onnxruntime/tools/python/util/add_openvino_win_libs.py
saurabh a6ce7b339f
Enable model subgraph execution in OVEP and setting the OpenVINO dll's to the path from the OpenVINO pypi packge in OVEP and fix OVEP windows io buffer sample (#16147)
### Description
This PR enables execution of subgraphs in OVEP and currently, when OVEP
developers install the onnxruntime-openvino package on windows from
pypi, they would have to additionally download OpenVINO windows binaries
and run the setupvars.bat script which sets the environment PATH to
locate the OV dll's. Also this PR fixes issues of OVEP windows io buffer
sample.



### Motivation and Context
Fix: We want to make the user experience easy for OVEP Python developers
on windows platform.
This fix, introduces a function add_openvino_libs_to_path at the
location tools/python/util/add_openvino_win_libs.py.
The above function, can be called by OVEP python users in the
application code and that takes care of setting
the OpenVINO dll's to the path from the OpenVINO pypi packge (openvino)
which was installed.
This change also makes sure that add_openvino_libs_to_path() function is
added to onnxruntime python package
only when it is build for OpenVINO Execution Provider for ONNXRuntime
and not for default ORT python package builds.

New user experience for Python OVEP developers on windows platform:
step 1: pip install onnxruntime-openvino
step 2: pip install openvino
step 3: <Add these 2 lines in the application code>
import onnxruntime.tools.add_openvino_win_libs as utils
utils.add_openvino_libs_to_path()

---------

Signed-off-by: MaajidKhan <n.maajid.khan@intel.com>
Co-authored-by: MaajidKhan <n.maajid.khan@intel.com>
Co-authored-by: Suryaprakash Shanmugam <suryaprakash.shanmugam@intel.com>
2023-06-16 19:47:09 -07:00

35 lines
1.6 KiB
Python

# Copyright (C) 2022-2023 Intel Corporation
# Licensed under the MIT License
import os
import site
import sys
def add_openvino_libs_to_path() -> None:
"""Adds OpenVINO libraries to the PATH environment variable on Windows."""
if sys.platform == "win32":
# Installer, pip installs openvino dlls to the different directories
# and those paths need to be visible to the openvino-ep modules
#
# If you're using a custom installation of openvino,
# add the location of openvino dlls to your system PATH.
openvino_libs = []
# looking for the libs in the pip installation path.
if os.path.isdir(os.path.join(site.getsitepackages()[1], "openvino", "libs")):
openvino_libs.append(os.path.join(site.getsitepackages()[1], "openvino", "libs"))
else:
# setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable.
openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS")
if openvino_libs_installer:
openvino_libs.extend(openvino_libs_installer.split(";"))
else:
sys.exit(
"Error: Please set the OPENVINO_LIB_PATHS environment variable. "
"If you use an install package, please, run setupvars.bat"
)
for lib in openvino_libs:
lib_path = os.path.join(os.path.dirname(__file__), lib)
if os.path.isdir(lib_path):
os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"]
os.add_dll_directory(os.path.abspath(lib_path))