13
13
import errno
14
14
import multiprocessing
15
15
import typing
16
+ import sysconfig
16
17
import defusedxml .ElementTree as ET
17
18
from defusedxml import defuse_stdlib
18
19
20
+ from textwrap import dedent
19
21
from pathlib import Path
20
22
from setuptools import setup
21
23
from setuptools .command .build_clib import build_clib
39
41
40
42
PACKAGE_NAME = config ('WHEEL_PACKAGE_NAME' , 'openvino-nvidia' )
41
43
OPENVINO_REPO_URI = config ('OPENVINO_REPO_DOWNLOAD_URL' , 'https://github.com/openvinotoolkit/openvino.git' )
42
- WHEEL_VERSION = config ('WHEEL_VERSION' , '2022.3.0' )
44
+ WHEEL_VERSION = config ('WHEEL_VERSION' , "2024.1.0" )
43
45
OPENVINO_REPO_TAG = config ('OPENVINO_REPO_TAG' , WHEEL_VERSION )
44
46
NVIDIA_PLUGIN_CMAKE_TARGET_NAME = 'openvino_nvidia_gpu_plugin'
45
47
LIBS_RPATH = '$ORIGIN' if sys .platform == 'linux' else '@loader_path'
@@ -226,15 +228,23 @@ def run(self):
226
228
if self .cmake_exec is None :
227
229
raise FileNotFoundError ("cmake path not located on path" )
228
230
229
- self .mkpath (self .deps_dir )
230
231
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()
231
239
self .configure_openvino_cmake ()
232
240
if self .force :
233
241
self .build_openvino ()
234
242
self .build_nvidia_plugin ()
235
243
self .locate_built_lib ()
236
244
237
245
def clone_openvino_src (self ):
246
+ self .mkpath (self .deps_dir )
247
+
238
248
if os .path .isdir (self .openvino_src_dir ):
239
249
return
240
250
self .announce ("Cloning the OpenVINO sources" , level = 3 )
@@ -246,16 +256,40 @@ def clone_openvino_src(self):
246
256
cwd = self .openvino_src_dir ,
247
257
on_fail_msg = 'Failed to update the OpenVINO git submodules' )
248
258
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
+
249
271
def configure_openvino_cmake (self ):
250
272
if not os .path .isdir (self .openvino_build_dir ):
251
273
self .mkpath (self .openvino_build_dir )
252
274
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
+ configure_command = [self .cmake_exec ,
277
+ '-G' , 'Unix Makefiles' ,
278
+ f'-S{ self .openvino_src_dir } ' ,
279
+ f'-B{ self .openvino_build_dir } ' ,
280
+ '-DENABLE_PLUGINS_XML=ON' ,
281
+ '-DCMAKE_VERBOSE_MAKEFILE=ON' ,
282
+ '-DENABLE_NVIDIA=ON' ,
255
283
'-DENABLE_PYTHON=ON' ,
284
+ f'-DPython3_EXECUTABLE={ sys .executable } ' ,
285
+ f'-DPython3_INCLUDE_DIR={ python_include_dir } ' ,
256
286
f'-DPYTHON_EXECUTABLE={ sys .executable } ' ,
257
- f'-DWHEEL_VERSION={ WHEEL_VERSION } ' ,
258
- '-DENABLE_WHEEL=ON' ]
287
+ f'-DPYTHON_INCLUDE_DIR={ python_include_dir } ' ,
288
+ '-DNGRAPH_PYTHON_BUILD_ENABLE=ON' ,
289
+ f'-DCMAKE_BUILD_TYPE={ self .build_configuration_name } ' ,
290
+ f'-DOPENVINO_EXTRA_MODULES={ self .openvino_contrib_src_dir } /modules/nvidia_plugin' ,
291
+ '-DENABLE_WHEEL=ON' ,
292
+ f'-DWHEEL_VERSION={ WHEEL_VERSION } ' ]
259
293
self .announce ("Configuring OpenVINO CMake Project" , level = 3 )
260
294
run_command (configure_command ,
261
295
cwd = self .openvino_build_dir ,
@@ -333,11 +367,18 @@ def locate_built_lib(self):
333
367
set_rpath (LIBS_RPATH , os .path .realpath (path ))
334
368
335
369
336
- class InstallCMakeLib (install_lib ):
370
+ class InstallCMakeLib (install_lib , build_clib ):
371
+ def initialize_options (self ):
372
+ install_lib .initialize_options (self )
373
+ build_clib .initialize_options (self )
374
+
337
375
def finalize_options (self ):
338
- super ().finalize_options ()
376
+ install_lib .finalize_options (self )
377
+ build_clib .finalize_options (self )
378
+
339
379
self .git_exec = shutil .which ("git" )
340
380
self .force = None
381
+ self .deps_dir = os .path .abspath (os .path .join (self .build_temp , "deps" ))
341
382
self .set_undefined_options ('install' , ('force' , 'force' ))
342
383
343
384
def run (self ):
@@ -373,6 +414,24 @@ def install_openvino_package_and_other_dependencies(self):
373
414
run_command (requirements_py ,
374
415
on_fail_msg = f'Failed to install dependencies from { path_to_requirements_txt } ' )
375
416
417
+ def update_plugins_xml (self , xml_file , openvino_nvidia_gpu_library ):
418
+ if not os .path .exists (xml_file ):
419
+ plugins_xml_src = dedent ('''\
420
+ <ie>
421
+ <plugins>
422
+ </plugins>
423
+ </ie>
424
+ ''' )
425
+ tree = ET .fromstring (plugins_xml_src )
426
+ else :
427
+ tree = ET .parse (xml_file ).getroot ()
428
+
429
+ plugins = tree .find ("plugins" )
430
+ if all (plugin .get ('name' ) != 'NVIDIA' for plugin in plugins .iter ('plugin' )):
431
+ plugins .append (Element ('plugin' , {'name' : 'NVIDIA' , 'location' : openvino_nvidia_gpu_library }))
432
+ with open (xml_file , "w" ) as f :
433
+ f .write (ET .tostring (tree ).decode ('utf8' ))
434
+
376
435
def get_openvino_package_dir (self ):
377
436
import openvino
378
437
openvino_package_dir = os .path .dirname (os .path .abspath (openvino .__file__ ))
@@ -386,12 +445,8 @@ def register_nvidia_plugin(self):
386
445
f"libopenvino_nvidia_gpu_plugin.{ platform_specifics .get_lib_file_extension ()} " )
387
446
388
447
xml_file = os .path .join (openvino_package_libs_dir , "plugins.xml" )
389
- tree = ET .parse (xml_file ).getroot ()
390
- plugins = tree .find ("plugins" )
391
- if all (plugin .get ('name' ) != 'NVIDIA' for plugin in plugins .iter ('plugin' )):
392
- plugins .append (Element ('plugin' , {'name' : 'NVIDIA' , 'location' : openvino_nvidia_gpu_library }))
393
- with open (xml_file , "w" ) as f :
394
- f .write (ET .tostring (tree ).decode ('utf8' ))
448
+
449
+ self .update_plugins_xml (xml_file , openvino_nvidia_gpu_library )
395
450
396
451
def unregister_nvidia_plugin (self ):
397
452
openvino_package_libs_dir = self .get_openvino_package_dir ()
@@ -407,7 +462,7 @@ def unregister_nvidia_plugin(self):
407
462
break
408
463
409
464
def test_nvidia_plugin (self ):
410
- from openvino . runtime import Core
465
+ import openvino as ov
411
466
test_model_convert_fp32 = """
412
467
<?xml version="1.0"?>
413
468
<net name="Function_1208" version="10">
@@ -439,7 +494,7 @@ def test_nvidia_plugin(self):
439
494
</edges>
440
495
</net>
441
496
""" .encode ('ascii' )
442
- core = Core ()
497
+ core = ov . Core ()
443
498
model = core .read_model (model = test_model_convert_fp32 )
444
499
try :
445
500
core .compile_model (model = model , device_name = "NVIDIA" )
0 commit comments