Skip to content

Commit 3f4eeda

Browse files
[NVIDIA] Prepare setup.py for PyPi (#1001)
* Fix issues related to auditwheel and final .whl package * Refactored setup.py, to make consistent case where OPENVINO_SRC_DIR was provided and openvino downloaded from the internet * Updated openvino_nvidia/__init__.py to improve registration of NVIDIA plugin; update README.,d by adding the section related to how build python package for NVIDIA plugin --------- Co-authored-by: Denis Kotov <[email protected]>
1 parent a1e904f commit 3f4eeda

File tree

6 files changed

+320
-113
lines changed

6 files changed

+320
-113
lines changed

modules/nvidia_plugin/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist/
88

99
report_api.xml
1010
report_op.xml
11+
wheel/packages/openvino_nvidia/lib/

modules/nvidia_plugin/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,60 @@ During compilation of the openvino_nvidia_gpu_plugin, user could specify the fol
192192
nvidia-smi --query-gpu=compute_cap --format=csv
193193
```
194194

195+
## Python package
196+
197+
Python package could be built using `wheel/setup.py` file provided in nvidia_plugin folder.
198+
199+
### Prerequisites
200+
Run the following commands as prerequisites to `setup.py`:
201+
```bash
202+
export OPENVINO_HOME=<OPENVINO_HOME_DIR> # If not provided, setup.py will download openvino automatically
203+
python3 -m pip install wheel
204+
```
205+
206+
### Building the package
207+
To build it, use simply the following command:
208+
```bash
209+
python3 ./wheel/setup.py bdist_wheel
210+
```
211+
212+
### Installing the package
213+
To install:
214+
```bash
215+
python3 ./wheel/setup.py install
216+
```
217+
218+
### Usage
219+
Now you can use `openvino-nvidia` package, here is example:
220+
```python
221+
import openvino_nvidia
222+
import openvino as ov
223+
224+
core = ov.Core()
225+
model = core.read_model(model=...)
226+
core.compile_model(model=model, device_name="NVIDIA")
227+
```
228+
During the import of package `openvino_nvidia` it tries to register itself in `openvino` package.
229+
Registration happens in "lightweight" manner, it means if "NVIDIA" plugin already registered than it does nothing.
230+
If you want forcely overwrite a path to plugin library you can do it by importing from `openvino_nvidia` package attribute `force_install`:
231+
```python
232+
from openvino_nvidia import force_install # will overwrite a path to plugin library
233+
import openvino as ov
234+
235+
core = ov.Core()
236+
model = core.read_model(model=...)
237+
core.compile_model(model=model, device_name="NVIDIA")
238+
```
239+
For symmetry there is also `install` attribute:
240+
```python
241+
from openvino_nvidia import install # will register plugin if it does not yet
242+
import openvino as ov
243+
244+
core = ov.Core()
245+
model = core.read_model(model=...)
246+
core.compile_model(model=model, device_name="NVIDIA")
247+
```
248+
195249
## Supported Layers and Limitations
196250
The plugin supports IRv10 and higher. The list of supported layers and its limitations are defined in [cuda_opset.md](docs/cuda_opset.md).
197251

modules/nvidia_plugin/build.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ fi
99

1010
BUILD_JOBS=${BUILD_JOBS:-$(nproc)}
1111
BUILD_TYPE=${BUILD_TYPE:-Release}
12-
BUILD_TARGETS=${BUILD_TARGETS:-"ov_nvidia_func_tests ov_nvidia_unit_tests openvino_nvidia_gpu_plugin benchmark_app"}
13-
WHEEL_VERSION=${WHEEL_VERSION:-"2022.3.0"}
12+
13+
ENABLE_WHEEL=${ENABLE_WHEEL:-"OFF"}
14+
WHEEL_VERSION=${WHEEL_VERSION:-"2025.3.0"}
15+
WHEEL_TARGET=""
16+
if [ "$ENABLE_WHEEL" = "ON" ]; then
17+
WHEEL_TARGET="ie_wheel"
18+
fi
19+
20+
BUILD_TARGETS=${BUILD_TARGETS:-"${WHEEL_TARGET} ov_nvidia_func_tests ov_nvidia_unit_tests openvino_nvidia_gpu_plugin benchmark_app"}
1421
ENABLE_TESTS=${ENABLE_TESTS:-"ON"}
15-
ENABLE_FUNCTIONAL_TESTS=${ENABLE_FUNCTIONAL_TESTS:-"OFF"}
22+
ENABLE_FUNCTIONAL_TESTS=${ENABLE_FUNCTIONAL_TESTS:-"ON"}
1623

1724
[[ -n "${OPENVINO_HOME}" ]] || { echo "OPENVINO_HOME environment variable is expected"; exit 1; }
1825
[[ -n "${OPENVINO_CONTRIB}" ]] || { echo "OPENVINO_CONTRIB environment variable is expected"; exit 1; }
@@ -43,6 +50,7 @@ cmake "${OPENVINO_HOME}" \
4350
-DENABLE_PLUGINS_XML=ON \
4451
-DENABLE_TESTS="${ENABLE_TESTS}" \
4552
-DENABLE_FUNCTIONAL_TESTS="${ENABLE_FUNCTIONAL_TESTS}" \
53+
-DENABLE_WHEEL="${ENABLE_WHEEL}" \
4654
-DBUILD_arm_plugin=OFF \
4755
-DBUILD_java_api=OFF \
4856
-DBUILD_llama_cpp_plugin=OFF \

modules/nvidia_plugin/wheel/packages/openvino_nvidia/__init__.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,44 @@ def _get_lib_file_extension() -> str:
1818
return "dylib"
1919

2020

21-
def _register_nvidia_plugin():
21+
def _register_nvidia_plugin(force=False):
2222
import openvino
2323
openvino_package_dir = os.path.dirname(os.path.abspath(openvino.__file__))
2424
openvino_package_libs_dir = os.path.join(openvino_package_dir, "libs")
2525
openvino_nvidia_gpu_package_dir = os.path.dirname(os.path.abspath(__file__))
26-
openvino_nvidia_gpu_library = os.path.join(openvino_nvidia_gpu_package_dir, f"../libopenvino_nvidia_gpu_plugin.{_get_lib_file_extension()}")
26+
openvino_nvidia_gpu_library = os.path.join(openvino_nvidia_gpu_package_dir, f"./lib/libopenvino_nvidia_gpu_plugin.{_get_lib_file_extension()}")
2727

2828
xml_file = os.path.join(openvino_package_libs_dir, "plugins.xml")
29+
xml_file_updated = False
2930
tree = ET.parse(xml_file).getroot()
3031
plugins = tree.find("plugins")
31-
if all(plugin.get('name') != 'NVIDIA' for plugin in plugins.iter('plugin')):
32-
plugins.append(Element('plugin', {'name': 'NVIDIA', 'location': openvino_nvidia_gpu_library}))
32+
33+
if force:
34+
for plugin in plugins:
35+
if plugin.tag == "plugin" and plugin.get("name") == "NVIDIA":
36+
plugins.remove(plugin)
37+
plugins.append(Element('plugin', {'name': 'NVIDIA', 'location': openvino_nvidia_gpu_library}))
38+
xml_file_updated = True
39+
else:
40+
if all(plugin.get('name') != 'NVIDIA' for plugin in plugins.iter('plugin')):
41+
plugins.append(Element('plugin', {'name': 'NVIDIA', 'location': openvino_nvidia_gpu_library}))
42+
xml_file_updated = True
43+
44+
if xml_file_updated:
3345
with open(xml_file, "w") as f:
3446
f.write(ET.tostring(tree).decode('utf8'))
3547

3648

49+
def __getattr__(name):
50+
if name == "install":
51+
_register_nvidia_plugin()
52+
elif name == "force_install":
53+
_register_nvidia_plugin(True)
54+
else:
55+
raise AttributeError(f"module {__name__} has no attribute {name}")
56+
57+
3758
_register_nvidia_plugin()
3859

39-
__version__ = "2024.1.0"
60+
61+
__version__ = "2025.3.0"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
openvino==2024.1.0
1+
openvino==2025.3.0

0 commit comments

Comments
 (0)