Skip to content

Commit 031471f

Browse files
Update setup.py script to make it buildable again
Finall update of setup.py file
1 parent 659e519 commit 031471f

File tree

5 files changed

+72
-15
lines changed

5 files changed

+72
-15
lines changed

modules/nvidia_plugin/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Afterwards plugin build procedure is as following:
4848

4949
1. Clone `openvino_contrib` repository:
5050
```bash
51-
git clone --recurse-submodules --single-branch --branch=2022.3.0 https://github.com/openvinotoolkit/openvino_contrib.git
51+
git clone --recurse-submodules --single-branch --branch=2024.1.0 https://github.com/openvinotoolkit/openvino_contrib.git
5252
```
5353
2. Go to plugin directory:
5454
```bash
@@ -60,7 +60,7 @@ mkdir build && cd build
6060
```
6161
4. Build plugin
6262

63-
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)
63+
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)
6464

6565
Then build CUDA Plugin with one of 2 options:
6666
- Using `build.sh`
@@ -97,7 +97,7 @@ If python available the CUDA Plugin could be compiled with setup.py script as fo
9797

9898
1. Clone `openvino_contrib` repository:
9999
```bash
100-
git clone --recurse-submodules --single-branch --branch=2022.3.0 https://github.com/openvinotoolkit/openvino_contrib.git
100+
git clone --recurse-submodules --single-branch --branch=2024.1.0 https://github.com/openvinotoolkit/openvino_contrib.git
101101
```
102102
2. Go to plugin directory:
103103
```bash

modules/nvidia_plugin/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fi
3939
cd "${OPENVINO_BUILD_PATH}"
4040
cmake "${OPENVINO_HOME}" \
4141
-DENABLE_NVIDIA=ON \
42+
-DENABLE_PLUGINS_XML=ON \
4243
-DENABLE_TESTS="${ENABLE_TESTS}" \
4344
-DBUILD_arm_plugin=OFF \
4445
-DBUILD_java_api=OFF \

modules/nvidia_plugin/wheel/openvino_nvidia/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ def _register_nvidia_plugin():
3636

3737
_register_nvidia_plugin()
3838

39-
__version__ = "2022.3.0"
39+
__version__ = "2023.1.0"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
openvino==2022.3.0
1+
openvino==2023.1.0

modules/nvidia_plugin/wheel/setup.py

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import errno
1414
import multiprocessing
1515
import typing
16+
import sysconfig
1617
import defusedxml.ElementTree as ET
1718
from defusedxml import defuse_stdlib
1819

@@ -39,7 +40,7 @@
3940

4041
PACKAGE_NAME = config('WHEEL_PACKAGE_NAME', 'openvino-nvidia')
4142
OPENVINO_REPO_URI = config('OPENVINO_REPO_DOWNLOAD_URL', 'https://github.com/openvinotoolkit/openvino.git')
42-
WHEEL_VERSION = config('WHEEL_VERSION', '2022.3.0')
43+
WHEEL_VERSION = config('WHEEL_VERSION', "2024.1.0")
4344
OPENVINO_REPO_TAG = config('OPENVINO_REPO_TAG', WHEEL_VERSION)
4445
NVIDIA_PLUGIN_CMAKE_TARGET_NAME = 'openvino_nvidia_gpu_plugin'
4546
LIBS_RPATH = '$ORIGIN' if sys.platform == 'linux' else '@loader_path'
@@ -147,6 +148,7 @@ def create_pip_command(*options):
147148

148149
def run_command(command, cwd: str = None, on_fail_msg: str = '', env=None):
149150
try:
151+
print(f"run_command: {' '.join(command)}")
150152
subprocess.check_call(command, cwd=cwd, env=env) # nosec - disable B603:subprocess_without_shell_equals_true check
151153
except subprocess.CalledProcessError as e:
152154
raise RuntimeError(on_fail_msg) from e
@@ -226,15 +228,23 @@ def run(self):
226228
if self.cmake_exec is None:
227229
raise FileNotFoundError("cmake path not located on path")
228230

229-
self.mkpath(self.deps_dir)
230231
self.clone_openvino_src()
232+
# TODO: Uncomment when issue with conan dependecies will be resolved.
233+
# When uncomment this line, got the following error during
234+
# cmake configuration step:
235+
# CMake Error at build/protobuf-Target-release.cmake:74 (set_property):
236+
# set_property can not be used on an ALIAS target.
237+
# ...
238+
# self.openvino_conan_install()
231239
self.configure_openvino_cmake()
232240
if self.force:
233241
self.build_openvino()
234242
self.build_nvidia_plugin()
235243
self.locate_built_lib()
236244

237245
def clone_openvino_src(self):
246+
self.mkpath(self.deps_dir)
247+
238248
if os.path.isdir(self.openvino_src_dir):
239249
return
240250
self.announce("Cloning the OpenVINO sources", level=3)
@@ -246,16 +256,41 @@ def clone_openvino_src(self):
246256
cwd=self.openvino_src_dir,
247257
on_fail_msg='Failed to update the OpenVINO git submodules')
248258

259+
def openvino_conan_install(self):
260+
if not os.path.isdir(self.openvino_build_dir):
261+
self.mkpath(self.openvino_build_dir)
262+
263+
run_command(["conan",
264+
"install",
265+
f'-of={self.openvino_build_dir}',
266+
'--build=missing',
267+
self.openvino_src_dir],
268+
cwd=self.openvino_build_dir,
269+
on_fail_msg='Failed to install conan dependecies for OpenVINO CMake Project')
270+
249271
def configure_openvino_cmake(self):
250272
if not os.path.isdir(self.openvino_build_dir):
251273
self.mkpath(self.openvino_build_dir)
252274

253-
configure_command = [self.cmake_exec, f'-S{self.openvino_src_dir}', f'-B{self.openvino_build_dir}',
254-
f'-DCMAKE_BUILD_TYPE={self.build_configuration_name}',
275+
python_include_dir = sysconfig.get_path("include")
276+
277+
configure_command = [self.cmake_exec,
278+
'-G', 'Unix Makefiles',
279+
f'-S{self.openvino_src_dir}',
280+
f'-B{self.openvino_build_dir}',
281+
'-DENABLE_PLUGINS_XML=ON',
282+
'-DCMAKE_VERBOSE_MAKEFILE=ON',
283+
'-DENABLE_NVIDIA=ON',
255284
'-DENABLE_PYTHON=ON',
285+
f'-DPython3_EXECUTABLE={sys.executable}',
286+
f'-DPython3_INCLUDE_DIR={python_include_dir}',
256287
f'-DPYTHON_EXECUTABLE={sys.executable}',
257-
f'-DWHEEL_VERSION={WHEEL_VERSION}',
258-
'-DENABLE_WHEEL=ON']
288+
f'-DPYTHON_INCLUDE_DIR={python_include_dir}',
289+
'-DNGRAPH_PYTHON_BUILD_ENABLE=ON',
290+
f'-DCMAKE_BUILD_TYPE={self.build_configuration_name}',
291+
f'-DOPENVINO_EXTRA_MODULES={self.openvino_contrib_src_dir}/modules/nvidia_plugin',
292+
'-DENABLE_WHEEL=ON',
293+
f'-DWHEEL_VERSION={WHEEL_VERSION}']
259294
self.announce("Configuring OpenVINO CMake Project", level=3)
260295
run_command(configure_command,
261296
cwd=self.openvino_build_dir,
@@ -333,11 +368,18 @@ def locate_built_lib(self):
333368
set_rpath(LIBS_RPATH, os.path.realpath(path))
334369

335370

336-
class InstallCMakeLib(install_lib):
371+
class InstallCMakeLib(install_lib, build_clib):
372+
def initialize_options(self):
373+
install_lib.initialize_options(self)
374+
build_clib.initialize_options(self)
375+
337376
def finalize_options(self):
338-
super().finalize_options()
377+
install_lib.finalize_options(self)
378+
build_clib.finalize_options(self)
379+
339380
self.git_exec = shutil.which("git")
340381
self.force = None
382+
self.deps_dir = os.path.abspath(os.path.join(self.build_temp, "deps"))
341383
self.set_undefined_options('install', ('force', 'force'))
342384

343385
def run(self):
@@ -373,6 +415,17 @@ def install_openvino_package_and_other_dependencies(self):
373415
run_command(requirements_py,
374416
on_fail_msg=f'Failed to install dependencies from {path_to_requirements_txt}')
375417

418+
def check_plugins_xml(self, dst_xml_file):
419+
if not os.path.exists(dst_xml_file):
420+
from glob import glob
421+
422+
plugins_xml_path = f"{self.deps_dir}/openvino/bin/**/*/plugins.xml"
423+
print(f"plugins_xml_path = {plugins_xml_path}")
424+
for src_xml_file in glob(f"{self.deps_dir}/openvino/bin/**/*/plugins.xml", recursive=True):
425+
print(f"src_xml_file = {src_xml_file}")
426+
shutil.copyfile(src_xml_file, dst_xml_file)
427+
break
428+
376429
def get_openvino_package_dir(self):
377430
import openvino
378431
openvino_package_dir = os.path.dirname(os.path.abspath(openvino.__file__))
@@ -386,6 +439,9 @@ def register_nvidia_plugin(self):
386439
f"libopenvino_nvidia_gpu_plugin.{platform_specifics.get_lib_file_extension()}")
387440

388441
xml_file = os.path.join(openvino_package_libs_dir, "plugins.xml")
442+
443+
self.check_plugins_xml(xml_file)
444+
389445
tree = ET.parse(xml_file).getroot()
390446
plugins = tree.find("plugins")
391447
if all(plugin.get('name') != 'NVIDIA' for plugin in plugins.iter('plugin')):
@@ -407,7 +463,7 @@ def unregister_nvidia_plugin(self):
407463
break
408464

409465
def test_nvidia_plugin(self):
410-
from openvino.runtime import Core
466+
import openvino as ov
411467
test_model_convert_fp32 = """
412468
<?xml version="1.0"?>
413469
<net name="Function_1208" version="10">
@@ -439,7 +495,7 @@ def test_nvidia_plugin(self):
439495
</edges>
440496
</net>
441497
""".encode('ascii')
442-
core = Core()
498+
core = ov.Core()
443499
model = core.read_model(model=test_model_convert_fp32)
444500
try:
445501
core.compile_model(model=model, device_name="NVIDIA")

0 commit comments

Comments
 (0)