From 031471fac9f3d74b34dd5bbdc6075831b5717934 Mon Sep 17 00:00:00 2001 From: Denis Kotov Date: Tue, 24 Oct 2023 12:48:10 +0300 Subject: [PATCH] Update setup.py script to make it buildable again Finall update of setup.py file --- modules/nvidia_plugin/README.md | 6 +- modules/nvidia_plugin/build.sh | 1 + .../wheel/openvino_nvidia/__init__.py | 2 +- modules/nvidia_plugin/wheel/requirements.txt | 2 +- modules/nvidia_plugin/wheel/setup.py | 76 ++++++++++++++++--- 5 files changed, 72 insertions(+), 15 deletions(-) diff --git a/modules/nvidia_plugin/README.md b/modules/nvidia_plugin/README.md index 3cdbd8dbb..ede223ac4 100644 --- a/modules/nvidia_plugin/README.md +++ b/modules/nvidia_plugin/README.md @@ -48,7 +48,7 @@ Afterwards plugin build procedure is as following: 1. Clone `openvino_contrib` repository: ```bash -git clone --recurse-submodules --single-branch --branch=2022.3.0 https://github.com/openvinotoolkit/openvino_contrib.git +git clone --recurse-submodules --single-branch --branch=2024.1.0 https://github.com/openvinotoolkit/openvino_contrib.git ``` 2. Go to plugin directory: ```bash @@ -60,7 +60,7 @@ mkdir build && cd build ``` 4. Build plugin - First of all, switch OpenVINO™ to tag _2022.3.0_ and then build it according the instruction [How to build](https://github.com/openvinotoolkit/openvino/wiki#how-to-build) + First of all, switch OpenVINO™ to tag _2024.1.0_ and then build it according the instruction [How to build](https://github.com/openvinotoolkit/openvino/wiki#how-to-build) Then build CUDA Plugin with one of 2 options: - Using `build.sh` @@ -97,7 +97,7 @@ If python available the CUDA Plugin could be compiled with setup.py script as fo 1. Clone `openvino_contrib` repository: ```bash -git clone --recurse-submodules --single-branch --branch=2022.3.0 https://github.com/openvinotoolkit/openvino_contrib.git +git clone --recurse-submodules --single-branch --branch=2024.1.0 https://github.com/openvinotoolkit/openvino_contrib.git ``` 2. Go to plugin directory: ```bash diff --git a/modules/nvidia_plugin/build.sh b/modules/nvidia_plugin/build.sh index d6df2bf62..bb7ed5695 100755 --- a/modules/nvidia_plugin/build.sh +++ b/modules/nvidia_plugin/build.sh @@ -39,6 +39,7 @@ fi cd "${OPENVINO_BUILD_PATH}" cmake "${OPENVINO_HOME}" \ -DENABLE_NVIDIA=ON \ + -DENABLE_PLUGINS_XML=ON \ -DENABLE_TESTS="${ENABLE_TESTS}" \ -DBUILD_arm_plugin=OFF \ -DBUILD_java_api=OFF \ diff --git a/modules/nvidia_plugin/wheel/openvino_nvidia/__init__.py b/modules/nvidia_plugin/wheel/openvino_nvidia/__init__.py index d93b08752..27c9ec4c6 100644 --- a/modules/nvidia_plugin/wheel/openvino_nvidia/__init__.py +++ b/modules/nvidia_plugin/wheel/openvino_nvidia/__init__.py @@ -36,4 +36,4 @@ def _register_nvidia_plugin(): _register_nvidia_plugin() -__version__ = "2022.3.0" +__version__ = "2023.1.0" diff --git a/modules/nvidia_plugin/wheel/requirements.txt b/modules/nvidia_plugin/wheel/requirements.txt index a6fcf5fa4..68d9f24b9 100644 --- a/modules/nvidia_plugin/wheel/requirements.txt +++ b/modules/nvidia_plugin/wheel/requirements.txt @@ -1 +1 @@ -openvino==2022.3.0 +openvino==2023.1.0 diff --git a/modules/nvidia_plugin/wheel/setup.py b/modules/nvidia_plugin/wheel/setup.py index 2b6b97934..5f59d01ed 100644 --- a/modules/nvidia_plugin/wheel/setup.py +++ b/modules/nvidia_plugin/wheel/setup.py @@ -13,6 +13,7 @@ import errno import multiprocessing import typing +import sysconfig import defusedxml.ElementTree as ET from defusedxml import defuse_stdlib @@ -39,7 +40,7 @@ PACKAGE_NAME = config('WHEEL_PACKAGE_NAME', 'openvino-nvidia') OPENVINO_REPO_URI = config('OPENVINO_REPO_DOWNLOAD_URL', 'https://github.com/openvinotoolkit/openvino.git') -WHEEL_VERSION = config('WHEEL_VERSION', '2022.3.0') +WHEEL_VERSION = config('WHEEL_VERSION', "2024.1.0") OPENVINO_REPO_TAG = config('OPENVINO_REPO_TAG', WHEEL_VERSION) NVIDIA_PLUGIN_CMAKE_TARGET_NAME = 'openvino_nvidia_gpu_plugin' LIBS_RPATH = '$ORIGIN' if sys.platform == 'linux' else '@loader_path' @@ -147,6 +148,7 @@ def create_pip_command(*options): def run_command(command, cwd: str = None, on_fail_msg: str = '', env=None): try: + print(f"run_command: {' '.join(command)}") subprocess.check_call(command, cwd=cwd, env=env) # nosec - disable B603:subprocess_without_shell_equals_true check except subprocess.CalledProcessError as e: raise RuntimeError(on_fail_msg) from e @@ -226,8 +228,14 @@ def run(self): if self.cmake_exec is None: raise FileNotFoundError("cmake path not located on path") - self.mkpath(self.deps_dir) self.clone_openvino_src() + # TODO: Uncomment when issue with conan dependecies will be resolved. + # When uncomment this line, got the following error during + # cmake configuration step: + # CMake Error at build/protobuf-Target-release.cmake:74 (set_property): + # set_property can not be used on an ALIAS target. + # ... + # self.openvino_conan_install() self.configure_openvino_cmake() if self.force: self.build_openvino() @@ -235,6 +243,8 @@ def run(self): self.locate_built_lib() def clone_openvino_src(self): + self.mkpath(self.deps_dir) + if os.path.isdir(self.openvino_src_dir): return self.announce("Cloning the OpenVINO sources", level=3) @@ -246,16 +256,41 @@ def clone_openvino_src(self): cwd=self.openvino_src_dir, on_fail_msg='Failed to update the OpenVINO git submodules') + def openvino_conan_install(self): + if not os.path.isdir(self.openvino_build_dir): + self.mkpath(self.openvino_build_dir) + + run_command(["conan", + "install", + f'-of={self.openvino_build_dir}', + '--build=missing', + self.openvino_src_dir], + cwd=self.openvino_build_dir, + on_fail_msg='Failed to install conan dependecies for OpenVINO CMake Project') + def configure_openvino_cmake(self): if not os.path.isdir(self.openvino_build_dir): self.mkpath(self.openvino_build_dir) - configure_command = [self.cmake_exec, f'-S{self.openvino_src_dir}', f'-B{self.openvino_build_dir}', - f'-DCMAKE_BUILD_TYPE={self.build_configuration_name}', + python_include_dir = sysconfig.get_path("include") + + configure_command = [self.cmake_exec, + '-G', 'Unix Makefiles', + f'-S{self.openvino_src_dir}', + f'-B{self.openvino_build_dir}', + '-DENABLE_PLUGINS_XML=ON', + '-DCMAKE_VERBOSE_MAKEFILE=ON', + '-DENABLE_NVIDIA=ON', '-DENABLE_PYTHON=ON', + f'-DPython3_EXECUTABLE={sys.executable}', + f'-DPython3_INCLUDE_DIR={python_include_dir}', f'-DPYTHON_EXECUTABLE={sys.executable}', - f'-DWHEEL_VERSION={WHEEL_VERSION}', - '-DENABLE_WHEEL=ON'] + f'-DPYTHON_INCLUDE_DIR={python_include_dir}', + '-DNGRAPH_PYTHON_BUILD_ENABLE=ON', + f'-DCMAKE_BUILD_TYPE={self.build_configuration_name}', + f'-DOPENVINO_EXTRA_MODULES={self.openvino_contrib_src_dir}/modules/nvidia_plugin', + '-DENABLE_WHEEL=ON', + f'-DWHEEL_VERSION={WHEEL_VERSION}'] self.announce("Configuring OpenVINO CMake Project", level=3) run_command(configure_command, cwd=self.openvino_build_dir, @@ -333,11 +368,18 @@ def locate_built_lib(self): set_rpath(LIBS_RPATH, os.path.realpath(path)) -class InstallCMakeLib(install_lib): +class InstallCMakeLib(install_lib, build_clib): + def initialize_options(self): + install_lib.initialize_options(self) + build_clib.initialize_options(self) + def finalize_options(self): - super().finalize_options() + install_lib.finalize_options(self) + build_clib.finalize_options(self) + self.git_exec = shutil.which("git") self.force = None + self.deps_dir = os.path.abspath(os.path.join(self.build_temp, "deps")) self.set_undefined_options('install', ('force', 'force')) def run(self): @@ -373,6 +415,17 @@ def install_openvino_package_and_other_dependencies(self): run_command(requirements_py, on_fail_msg=f'Failed to install dependencies from {path_to_requirements_txt}') + def check_plugins_xml(self, dst_xml_file): + if not os.path.exists(dst_xml_file): + from glob import glob + + plugins_xml_path = f"{self.deps_dir}/openvino/bin/**/*/plugins.xml" + print(f"plugins_xml_path = {plugins_xml_path}") + for src_xml_file in glob(f"{self.deps_dir}/openvino/bin/**/*/plugins.xml", recursive=True): + print(f"src_xml_file = {src_xml_file}") + shutil.copyfile(src_xml_file, dst_xml_file) + break + def get_openvino_package_dir(self): import openvino openvino_package_dir = os.path.dirname(os.path.abspath(openvino.__file__)) @@ -386,6 +439,9 @@ def register_nvidia_plugin(self): f"libopenvino_nvidia_gpu_plugin.{platform_specifics.get_lib_file_extension()}") xml_file = os.path.join(openvino_package_libs_dir, "plugins.xml") + + self.check_plugins_xml(xml_file) + tree = ET.parse(xml_file).getroot() plugins = tree.find("plugins") if all(plugin.get('name') != 'NVIDIA' for plugin in plugins.iter('plugin')): @@ -407,7 +463,7 @@ def unregister_nvidia_plugin(self): break def test_nvidia_plugin(self): - from openvino.runtime import Core + import openvino as ov test_model_convert_fp32 = """ @@ -439,7 +495,7 @@ def test_nvidia_plugin(self): """.encode('ascii') - core = Core() + core = ov.Core() model = core.read_model(model=test_model_convert_fp32) try: core.compile_model(model=model, device_name="NVIDIA")