Skip to content

Commit

Permalink
Update setup.py script to make it buildable again
Browse files Browse the repository at this point in the history
Finall update of setup.py file
  • Loading branch information
lohika-denis-kotov committed Jun 7, 2024
1 parent 659e519 commit 031471f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
6 changes: 3 additions & 3 deletions modules/nvidia_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/nvidia_plugin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion modules/nvidia_plugin/wheel/openvino_nvidia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ def _register_nvidia_plugin():

_register_nvidia_plugin()

__version__ = "2022.3.0"
__version__ = "2023.1.0"
2 changes: 1 addition & 1 deletion modules/nvidia_plugin/wheel/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
openvino==2022.3.0
openvino==2023.1.0
76 changes: 66 additions & 10 deletions modules/nvidia_plugin/wheel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import errno
import multiprocessing
import typing
import sysconfig
import defusedxml.ElementTree as ET
from defusedxml import defuse_stdlib

Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -226,15 +228,23 @@ 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()
self.build_nvidia_plugin()
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)
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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__))
Expand All @@ -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')):
Expand All @@ -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 = """
<?xml version="1.0"?>
<net name="Function_1208" version="10">
Expand Down Expand Up @@ -439,7 +495,7 @@ def test_nvidia_plugin(self):
</edges>
</net>
""".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")
Expand Down

0 comments on commit 031471f

Please sign in to comment.