48
48
OPENVINO_INSTALL_BUILD_DEPS_SCRIPT = "install_build_dependencies.sh"
49
49
50
50
openvino_src_dir : Optional [str ] = None
51
+ build_configuration_name : Optional [str ] = None
52
+ package_data : typing .Dict [str , list ] = {}
51
53
52
54
53
55
def is_tool (name ):
@@ -206,9 +208,11 @@ def finalize_options(self):
206
208
super ().finalize_options ()
207
209
208
210
global openvino_src_dir
211
+ global build_configuration_name
212
+
209
213
self .git_exec = shutil .which ("git" )
210
214
self .cmake_exec = shutil .which ("cmake" )
211
- self . build_configuration_name = 'Debug' if self .debug else 'Release'
215
+ build_configuration_name = 'Debug' if self .debug else 'Release'
212
216
self .nvidia_plugin_src_dir = os .path .abspath (os .path .dirname (__file__ ))
213
217
self .build_lib_dir = os .path .join (self .nvidia_plugin_src_dir , "../build/lib" )
214
218
self .openvino_contrib_src_dir = os .path .normpath (os .path .join (self .nvidia_plugin_src_dir , "../../.." ))
@@ -286,7 +290,7 @@ def configure_openvino_cmake(self):
286
290
f'-DPYTHON_EXECUTABLE={ sys .executable } ' ,
287
291
f'-DPYTHON_INCLUDE_DIR={ python_include_dir } ' ,
288
292
'-DNGRAPH_PYTHON_BUILD_ENABLE=ON' ,
289
- f'-DCMAKE_BUILD_TYPE={ self . build_configuration_name } ' ,
293
+ f'-DCMAKE_BUILD_TYPE={ build_configuration_name } ' ,
290
294
f'-DOPENVINO_EXTRA_MODULES={ self .openvino_contrib_src_dir } /modules/nvidia_plugin' ,
291
295
'-DENABLE_WHEEL=ON' ,
292
296
f'-DWHEEL_VERSION={ WHEEL_VERSION } ' ]
@@ -306,7 +310,7 @@ def build_openvino(self):
306
310
307
311
def get_build_env (self ):
308
312
build_env = os .environ .copy ()
309
- build_env ['BUILD_TYPE' ] = self . build_configuration_name
313
+ build_env ['BUILD_TYPE' ] = build_configuration_name
310
314
build_env ['BUILD_TARGETS' ] = NVIDIA_PLUGIN_CMAKE_TARGET_NAME
311
315
build_env ['OPENVINO_HOME' ] = self .openvino_src_dir
312
316
build_env ['OPENVINO_CONTRIB' ] = self .openvino_contrib_src_dir
@@ -367,53 +371,67 @@ def locate_built_lib(self):
367
371
set_rpath (LIBS_RPATH , os .path .realpath (path ))
368
372
369
373
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
-
374
+ class InstallLib (install_lib ):
375
375
def finalize_options (self ):
376
376
install_lib .finalize_options (self )
377
- build_clib .finalize_options (self )
378
377
379
378
self .git_exec = shutil .which ("git" )
380
379
self .force = None
381
- self .deps_dir = os .path .abspath (os .path .join (self .build_temp , "deps" ))
382
380
self .set_undefined_options ('install' , ('force' , 'force' ))
381
+ print (f"self.force = { self .force } " )
383
382
384
383
def run (self ):
384
+ openvino_nvidia_gpu_library = f'{ openvino_src_dir } /bin/intel64/{ build_configuration_name } /lib/libopenvino_nvidia_gpu_plugin.{ platform_specifics .get_lib_file_extension ()} '
385
+ package_data .update ({
386
+ '' : [openvino_nvidia_gpu_library ]
387
+ })
388
+
389
+ self .build ()
390
+ self .install ()
391
+
385
392
try :
386
- self .build ()
387
- self .install ()
388
- self .install_openvino_package_and_other_dependencies ()
393
+ if self .force :
394
+ self .install_openvino_package ()
395
+ self .install_python_dependencies ()
389
396
self .register_nvidia_plugin ()
390
397
self .test_nvidia_plugin ()
391
- openvino_nvidia_gpu_library = f'{ openvino_src_dir } /bin/intel64/Release/lib/libopenvino_nvidia_gpu_plugin.{ platform_specifics .get_lib_file_extension ()} '
392
- package_data .update ({
393
- '' : [openvino_nvidia_gpu_library ]
394
- })
395
- finally :
398
+ except Exception as ex :
396
399
self .unregister_nvidia_plugin ()
397
400
398
- def install_openvino_package_and_other_dependencies (self ):
399
- if self .force :
400
- py_tag = tags .interpreter_name () + tags .interpreter_version ()
401
- abi_tag = wheel .bdist_wheel .get_abi_tag ()
402
- platform_tag = next (tags .platform_tags ())
403
- git_commits = get_command_output ([self .git_exec , 'rev-list' , '--count' , '--first-parent' , 'HEAD' ],
404
- cwd = openvino_src_dir , on_fail_msg = 'Failed to count OpenVINO commits' ).strip ()
405
- openvino_wheel_name = "-" .join (["openvino" , WHEEL_VERSION , git_commits , py_tag , abi_tag , platform_tag ]) + ".whl"
406
- wheels_path = os .path .abspath (os .path .join (openvino_src_dir , "build/wheels" , openvino_wheel_name ))
407
- self .announce (f"Installing OpenVINO package with { wheels_path } " , level = 3 )
408
- openvino_install_py = create_pip_command (wheels_path )
409
- run_command (openvino_install_py ,
410
- on_fail_msg = f'Failed to install OpenVINO wheel package with { wheels_path } ' )
411
-
401
+ def install_openvino_package (self ):
402
+ py_tag = tags .interpreter_name () + tags .interpreter_version ()
403
+ abi_tag = wheel .bdist_wheel .get_abi_tag ()
404
+ platform_tag = next (tags .platform_tags ())
405
+ git_commits = get_command_output ([self .git_exec , 'rev-list' , '--count' , '--first-parent' , 'HEAD' ],
406
+ cwd = openvino_src_dir ,
407
+ on_fail_msg = 'Failed to count OpenVINO commits' ).strip ()
408
+ openvino_wheel_name = "-" .join (["openvino" , WHEEL_VERSION , git_commits , py_tag , abi_tag , platform_tag ]) + ".whl"
409
+ wheels_path = os .path .abspath (os .path .join (openvino_src_dir , "build/wheels" , openvino_wheel_name ))
410
+ self .announce (f"Installing OpenVINO package with { wheels_path } " , level = 3 )
411
+ openvino_install_py = create_pip_command (wheels_path )
412
+ run_command (openvino_install_py ,
413
+ on_fail_msg = f'Failed to install OpenVINO wheel package with { wheels_path } ' )
414
+
415
+ def install_python_dependencies (self ):
412
416
path_to_requirements_txt = os .path .join (os .path .abspath (os .path .dirname (__file__ )), "requirements.txt" )
413
417
requirements_py = create_pip_command ('-r' , path_to_requirements_txt )
414
418
run_command (requirements_py ,
415
419
on_fail_msg = f'Failed to install dependencies from { path_to_requirements_txt } ' )
416
420
421
+ def check_plugins_xml_if_exists (self ):
422
+ openvino_package_libs_dir = self .get_openvino_package_dir ()
423
+ xml_file = os .path .join (openvino_package_libs_dir , "plugins.xml" )
424
+ if not os .path .exists (xml_file ):
425
+ plugins_xml_src = dedent ('''\
426
+ <ie>
427
+ <plugins>
428
+ </plugins>
429
+ </ie>
430
+ ''' )
431
+ tree = ET .fromstring (plugins_xml_src )
432
+ with open (xml_file , "w" ) as f :
433
+ f .write (ET .tostring (tree ).decode ('utf8' ))
434
+
417
435
def update_plugins_xml (self , xml_file , openvino_nvidia_gpu_library ):
418
436
if not os .path .exists (xml_file ):
419
437
plugins_xml_src = dedent ('''\
@@ -438,14 +456,17 @@ def get_openvino_package_dir(self):
438
456
openvino_package_libs_dir = os .path .join (openvino_package_dir , "libs" )
439
457
return openvino_package_libs_dir
440
458
459
+ def get_openvino_nvidia_lib_path (self ):
460
+ import openvino_nvidia
461
+ openvino_nvidia_package_dir = os .path .dirname (os .path .abspath (openvino_nvidia .__file__ ))
462
+ openvino_nvidia_gpu_library = f'{ openvino_nvidia_package_dir } /libopenvino_nvidia_gpu_plugin.{ platform_specifics .get_lib_file_extension ()} '
463
+ return openvino_nvidia_gpu_library
464
+
441
465
def register_nvidia_plugin (self ):
466
+ self .check_plugins_xml_if_exists ()
442
467
openvino_package_libs_dir = self .get_openvino_package_dir ()
443
- self .copy_tree (self .build_dir , openvino_package_libs_dir )
444
- openvino_nvidia_gpu_library = os .path .join (openvino_package_libs_dir ,
445
- f"libopenvino_nvidia_gpu_plugin.{ platform_specifics .get_lib_file_extension ()} " )
446
-
468
+ openvino_nvidia_gpu_library = self .get_openvino_nvidia_lib_path ()
447
469
xml_file = os .path .join (openvino_package_libs_dir , "plugins.xml" )
448
-
449
470
self .update_plugins_xml (xml_file , openvino_nvidia_gpu_library )
450
471
451
472
def unregister_nvidia_plugin (self ):
@@ -508,8 +529,6 @@ def test_nvidia_plugin(self):
508
529
f'Possible ABI version mismatch. { recommendations_msg } ' ) from e
509
530
510
531
511
- package_data : typing .Dict [str , list ] = {}
512
-
513
532
setup (
514
533
version = config ('WHEEL_VERSION' , WHEEL_VERSION ),
515
534
author_email = config (
'WHEEL_AUTHOR_EMAIL' ,
'[email protected] ' ),
@@ -525,12 +544,12 @@ def test_nvidia_plugin(self):
525
544
libraries = [(PACKAGE_NAME , {'sources' : []})],
526
545
packages = ["openvino_nvidia" ],
527
546
package_dir = {
528
- "openvino_nvidia" : f"{ os .path .abspath (os .path .dirname (__file__ ))} /openvino_nvidia" ,
547
+ "openvino_nvidia" : f"{ os .path .abspath (os .path .dirname (__file__ ))} /packages/ openvino_nvidia" ,
529
548
},
530
549
package_data = package_data ,
531
550
cmdclass = {
532
551
'build_clib' : BuildCMakeLib ,
533
- 'install_lib' : InstallCMakeLib ,
552
+ 'install_lib' : InstallLib ,
534
553
},
535
554
zip_safe = False ,
536
555
)
0 commit comments