Skip to content

Commit

Permalink
Cross-platform openvino building
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.shchepetov committed May 20, 2021
1 parent 1dc84ae commit eacc032
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
14 changes: 2 additions & 12 deletions tests/conditional_compilation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@

# pylint: disable=line-too-long

""" Pytest configuration for compilation tests.
Sample usage:
python3 -m pytest test_cc.py \
--sea_runtool=./thirdparty/itt_collector/runtool/sea_runtool.py \
--collector_dir=./bin/intel64/Release \
--artifacts=<path to directory where tests write output or read input> \
--openvino_ref=<path to root directory with installed OpenVINO> \
--openvino_root_dir=<path to OpenVINO repo root directory>
"""
"""Pytest configuration for compilation tests."""

import logging
import sys
Expand All @@ -28,7 +19,6 @@
import pytest

from path_utils import expand_env_vars # pylint: disable=import-error
from proc_utils import cmd_exec # pylint: disable=import-error
from test_utils import make_build, write_session_info, SESSION_INFO_FILE # pylint: disable=import-error


Expand Down Expand Up @@ -117,7 +107,7 @@ def openvino_ref(request, openvino_root_dir, artifacts):
"""Fixture function for command-line option.
Return path to root directory with installed OpenVINO.
If --openvino_ref command-line option is not specified firstly build and install
instrumented binaries with OpenVINO repository specified in --openvino_root_dir option.
instrumented package with OpenVINO repository specified in --openvino_root_dir option.
"""
openvino_ref_path = request.config.getoption("openvino_ref")
if openvino_ref_path:
Expand Down
22 changes: 11 additions & 11 deletions tests/conditional_compilation/test_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def test_cc_collect(test_id, model, openvino_ref, test_info,


@pytest.mark.dependency(depends=["cc_collect"])
def test_minimized_build(test_id, model, openvino_root_dir, artifacts): # pylint: disable=unused-argument
"""Install OpenVINO with collected conditional compilation statistics."""
def test_minimized_pkg(test_id, model, openvino_root_dir, artifacts): # pylint: disable=unused-argument
"""Build and install OpenVINO package with collected conditional compilation statistics."""
install_prefix = artifacts / test_id / "install_pkg"
build_dir = openvino_root_dir / "build_minimized"

Expand All @@ -78,25 +78,25 @@ def test_minimized_build(test_id, model, openvino_root_dir, artifacts): # pylin
assert return_code == 0, f"Command exited with non-zero status {return_code}:\n {output}"


@pytest.mark.dependency(depends=["cc_collect", "minimized_build"])
@pytest.mark.dependency(depends=["cc_collect", "minimized_pkg"])
def test_infer(test_id, model, artifacts):
"""Test inference with conditional compiled binaries."""
out = artifacts / test_id
minimized_build = out / "install_pkg"
return_code, output = run_infer(model, f"{out}_cc.npz", minimized_build)
minimized_pkg = out / "install_pkg"
return_code, output = run_infer(model, f"{out}_cc.npz", minimized_pkg)
assert return_code == 0, f"Command exited with non-zero status {return_code}:\n {output}"


@pytest.mark.dependency(depends=["cc_collect", "minimized_build"])
@pytest.mark.dependency(depends=["cc_collect", "minimized_pkg"])
def test_verify(test_id, model, openvino_ref, artifacts, tolerance=1e-6): # pylint: disable=too-many-arguments
"""Test verifying that inference results are equal."""
out = artifacts / test_id
minimized_build = out / "install_pkg"
minimized_pkg = out / "install_pkg"
out_file = f"{out}.npz"
out_file_cc = f"{out}_cc.npz"
return_code, output = run_infer(model, out_file, openvino_ref)
assert return_code == 0, f"Command exited with non-zero status {return_code}:\n {output}"
return_code, output = run_infer(model, out_file_cc, minimized_build)
return_code, output = run_infer(model, out_file_cc, minimized_pkg)
assert return_code == 0, f"Command exited with non-zero status {return_code}:\n {output}"
reference_results = dict(np.load(out_file))
inference_results = dict(np.load(out_file_cc))
Expand All @@ -109,13 +109,13 @@ def test_verify(test_id, model, openvino_ref, artifacts, tolerance=1e-6): # pyl
), "Reference and inference results differ"


@pytest.mark.dependency(depends=["cc_collect", "minimized_build"])
@pytest.mark.dependency(depends=["cc_collect", "minimized_pkg"])
def test_libs_size(test_id, model, openvino_ref, artifacts): # pylint: disable=unused-argument
"""Test if libraries haven't increased in size after conditional compilation."""
libraries = ["inference_engine_transformations", "MKLDNNPlugin", "ngraph"]
minimized_build = artifacts / test_id / "install_pkg"
minimized_pkg = artifacts / test_id / "install_pkg"
ref_libs_size = get_lib_sizes(openvino_ref, libraries)
lib_sizes = get_lib_sizes(minimized_build, libraries)
lib_sizes = get_lib_sizes(minimized_pkg, libraries)

for lib in libraries:
lib_size_diff = ref_libs_size[lib] - lib_sizes[lib]
Expand Down
17 changes: 8 additions & 9 deletions tests/conditional_compilation/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""
import os
import json
import multiprocessing
import shutil
import sys
from inspect import getsourcefile
from pathlib import Path
Expand Down Expand Up @@ -63,18 +65,15 @@ def run_infer(model, out_file, install_dir):


def make_build(openvino_root_dir, build_dir, install_dir, cmake_additional_args=None, log=None):
"""Build and install OpenVINO with parameters."""
if sys.platform == "win32":
python_executable=""
params = " ".join(cmake_additional_args) + " " if cmake_additional_args else ""
"""Parametrized build and install OpenVINO package."""
python_executable = shutil.which("python3")
additional_args_line = " ".join(cmake_additional_args) + " " if cmake_additional_args else ""
nproc = multiprocessing.cpu_count()
cmd = (
f"mkdir -p {build_dir} && "
f"cmake -DENABLE_PROFILING_ITT=ON -DCMAKE_BUILD_TYPE=Release "
f"-DPYTHON_EXECUTABLE=`which python3` {params}"
f"-DPYTHON_EXECUTABLE={python_executable} {additional_args_line}"
f"-S {openvino_root_dir} -B {build_dir} &&"
f"make -C {build_dir} --jobs=$(nproc --all) && "
f"mkdir -p {install_dir} && "
f"cmake --build {build_dir} -j{nproc} && "
f"cmake --install {build_dir} --prefix {install_dir}"
)
return cmd_exec([cmd], shell=True, log=log)

0 comments on commit eacc032

Please sign in to comment.