Skip to content

Commit 5ce07b8

Browse files
committed
feat: Enable OVEP build with Static OV Libraries
1 parent 8c26898 commit 5ce07b8

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

cmake/CMakeLists.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ option(onnxruntime_USE_CUDA_NHWC_OPS "Build CUDA with NHWC op support" OFF)
8787
option(onnxruntime_CUDA_MINIMAL "Build CUDA without any operations apart from memcpy ops. Usefuel for a very minial TRT build" OFF)
8888
option(onnxruntime_ENABLE_CUDA_LINE_NUMBER_INFO "When building with CUDA support, generate device code line number information." OFF)
8989
option(onnxruntime_USE_OPENVINO "Build with OpenVINO support" OFF)
90+
option(onnxruntime_USE_OPENVINO_STATIC_LIBS "Build with OpenVINO support as Static Library" OFF)
9091
option(onnxruntime_USE_COREML "Build with CoreML support" OFF)
9192
option(onnxruntime_USE_NNAPI_BUILTIN "Build with builtin NNAPI lib for Android NNAPI support" OFF)
9293
option(onnxruntime_USE_QNN "Build with QNN support" OFF)
@@ -140,7 +141,7 @@ option(onnxruntime_ARMNN_RELU_USE_CPU "Use the CPU implementation for the Relu o
140141
option(onnxruntime_ARMNN_BN_USE_CPU "Use the CPU implementation for the Batch Normalization operator for the ArmNN EP" ON)
141142
option(onnxruntime_ENABLE_INSTRUMENT "Enable Instrument with Event Tracing for Windows (ETW)" OFF)
142143
option(onnxruntime_USE_TELEMETRY "Build with Telemetry" OFF)
143-
cmake_dependent_option(onnxruntime_USE_MIMALLOC "Override new/delete and arena allocator with mimalloc" OFF "WIN32;NOT onnxruntime_USE_CUDA;NOT onnxruntime_USE_OPENVINO" OFF)
144+
cmake_dependent_option(onnxruntime_USE_MIMALLOC "Override new/delete and arena allocator with mimalloc" OFF "WIN32;NOT onnxruntime_USE_CUDA;NOT onnxruntime_USE_OPENVINO; NOT onnxruntime_USE_OPENVINO_STATIC_LIBS" OFF)
144145
option(onnxruntime_USE_CANN "Build with CANN support" OFF)
145146
option(onnxruntime_USE_ROCM "Build with AMD GPU support" OFF)
146147
option(onnxruntime_USE_TVM "Build with TVM support" OFF)
@@ -606,7 +607,7 @@ if (WIN32)
606607
# structure was padded due to __declspec(align())
607608
list(APPEND ORT_WARNING_FLAGS "/wd4324")
608609
# warning C4800: Implicit conversion from 'X' to bool. Possible information loss
609-
if (onnxruntime_USE_OPENVINO)
610+
if (onnxruntime_USE_OPENVINO OR onnxruntime_USE_OPENVINO_STATIC_LIBS)
610611
list(APPEND ORT_WARNING_FLAGS "/wd4800")
611612
endif()
612613
# operator 'operator-name': deprecated between enumerations of different types
@@ -782,7 +783,7 @@ if (onnxruntime_USE_DNNL)
782783
list(APPEND ONNXRUNTIME_PROVIDER_NAMES dnnl)
783784
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_DNNL=1)
784785
endif()
785-
if (onnxruntime_USE_OPENVINO)
786+
if (onnxruntime_USE_OPENVINO OR onnxruntime_USE_OPENVINO_STATIC_LIBS)
786787
list(APPEND ORT_PROVIDER_FLAGS -DUSE_OPENVINO=1)
787788
list(APPEND ONNXRUNTIME_PROVIDER_NAMES openvino)
788789
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_OPENVINO=1)
@@ -1343,7 +1344,7 @@ if (onnxruntime_ENABLE_TRAINING_APIS)
13431344
)
13441345
endif()
13451346

1346-
if (onnxruntime_USE_OPENVINO)
1347+
if (onnxruntime_USE_OPENVINO OR onnxruntime_USE_OPENVINO_STATIC_LIBS)
13471348

13481349
add_definitions(-DUSE_OPENVINO=1)
13491350

cmake/onnxruntime_providers_openvino.cmake

+43-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,50 @@
1818
# Header paths
1919
find_package(OpenVINO REQUIRED COMPONENTS Runtime ONNX)
2020
if(OpenVINO_VERSION VERSION_LESS 2023.0)
21-
message(FATAL_ERROR "OpenVINO 2023.0 and newer are supported. Please, latest OpenVINO release")
21+
message(FATAL_ERROR "OpenVINO 2023.0 and newer are supported. Please, latest OpenVINO release")
2222
endif()
2323

2424
if (WIN32)
25-
unset(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO)
25+
unset(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO)
26+
endif()
27+
28+
if(onnxruntime_USE_OPENVINO_STATIC_LIBS)
29+
# Get the INTEL_OPENVINO_DIR environment variable
30+
file(TO_CMAKE_PATH "$ENV{INTEL_OPENVINO_DIR}" OpenVINO_BASE_DIR)
31+
32+
# Define the suffix path
33+
set(OPENVINO_SUFFIX_PATH "runtime/lib/intel64/Release")
34+
35+
# Combine the base directory with the suffix path
36+
file(TO_CMAKE_PATH "${OpenVINO_BASE_DIR}/${OPENVINO_SUFFIX_PATH}" OPENVINO_STATIC_LIB_DIR)
37+
38+
# Check if the combined directory exists, If the directory exists, proceed with setting up the static libraries
39+
if(IS_DIRECTORY "${OPENVINO_STATIC_LIB_DIR}")
40+
# Initialize an empty list to hold the found static libraries
41+
set(OPENVINO_FOUND_STATIC_LIBS)
42+
43+
# Use the appropriate file extension for static libraries based on the host operating system
44+
if(CMAKE_HOST_WIN32)
45+
set(OPENVINO_STATIC_LIB_EXT "*.lib")
46+
elseif(CMAKE_HOST_UNIX)
47+
set(OPENVINO_STATIC_LIB_EXT "*.a")
48+
endif()
49+
50+
# Use GLOB_RECURSE to find all static library files in the specified directory based on the OS
51+
file(GLOB_RECURSE OPENVINO_POSSIBLE_LIBS "${OPENVINO_STATIC_LIB_DIR}/${OPENVINO_STATIC_LIB_EXT}")
52+
53+
# Iterate over each possible library and check if it exists before appending
54+
foreach(lib ${OPENVINO_POSSIBLE_LIBS})
55+
if(EXISTS "${lib}")
56+
list(APPEND OPENVINO_FOUND_STATIC_LIBS "${lib}")
57+
endif()
58+
endforeach()
59+
60+
# Append the found static library files to the OPENVINO_LIB_LIST
61+
list(APPEND OPENVINO_LIB_LIST ${OPENVINO_FOUND_STATIC_LIBS})
62+
else()
63+
message(FATAL_ERROR "The specified OpenVINO static library directory does not exist: ${OPENVINO_STATIC_LIB_DIR}")
64+
endif()
2665
endif()
2766

2867
list(APPEND OPENVINO_LIB_LIST openvino::frontend::onnx openvino::runtime ${PYTHON_LIBRARIES})
@@ -38,6 +77,8 @@
3877
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/)
3978
set_target_properties(onnxruntime_providers_openvino PROPERTIES LINKER_LANGUAGE CXX)
4079
set_target_properties(onnxruntime_providers_openvino PROPERTIES FOLDER "ONNXRuntime")
80+
set_target_properties(onnxruntime_providers_openvino PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ON INTERPROCEDURAL_OPTIMIZATION_DEBUG ON INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
81+
4182
if(NOT MSVC)
4283
target_compile_options(onnxruntime_providers_openvino PRIVATE "-Wno-parentheses")
4384
endif()

tools/ci_build/build.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ def convert_arg_line_to_args(self, arg_line):
547547
type=_openvino_verify_device_type,
548548
help="Build with OpenVINO for specific hardware.",
549549
)
550+
parser.add_argument("--use_openvino_static_libs", action="store_true",
551+
help="Build with OpenVINO built as Static Library.")
550552
parser.add_argument(
551553
"--dnnl_aarch64_runtime", action="store", default="", type=str.lower, help="e.g. --dnnl_aarch64_runtime acl"
552554
)
@@ -1227,9 +1229,10 @@ def generate_build_tree(
12271229

12281230
if args.winml_root_namespace_override:
12291231
cmake_args += ["-Donnxruntime_WINML_NAMESPACE_OVERRIDE=" + args.winml_root_namespace_override]
1230-
if args.use_openvino:
1232+
if args.use_openvino or args.use_openvino_static_libs:
12311233
cmake_args += [
12321234
"-Donnxruntime_USE_OPENVINO=ON",
1235+
"-Donnxruntime_USE_OPENVINO_STATIC_LIBS=" + ("ON" if args.use_openvino_static_libs else "OFF"),
12331236
"-Donnxruntime_NPU_NO_FALLBACK=" + ("ON" if args.use_openvino == "NPU_NO_CPU_FALLBACK" else "OFF"),
12341237
"-Donnxruntime_USE_OPENVINO_GPU=" + ("ON" if args.use_openvino == "GPU" else "OFF"),
12351238
"-Donnxruntime_USE_OPENVINO_CPU=" + ("ON" if args.use_openvino == "CPU" else "OFF"),
@@ -1244,7 +1247,7 @@ def generate_build_tree(
12441247
]
12451248

12461249
# VitisAI and OpenVINO providers currently only support full_protobuf option.
1247-
if args.use_full_protobuf or args.use_openvino or args.use_vitisai or args.gen_doc:
1250+
if args.use_full_protobuf or args.use_openvino or args.use_openvino_static_libs or args.use_vitisai or args.gen_doc:
12481251
cmake_args += ["-Donnxruntime_USE_FULL_PROTOBUF=ON", "-DProtobuf_USE_STATIC_LIBS=ON"]
12491252

12501253
if args.use_tvm and args.llvm_path is not None:

0 commit comments

Comments
 (0)