Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/external/onnx
Submodule onnx updated 978 files
277 changes: 277 additions & 0 deletions cmake/onnxruntime_providers_openvino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,280 @@ set_target_properties(onnxruntime_providers_openvino PROPERTIES
MAP_IMPORTED_CONFIG_RELEASE RelWithDebInfo
MAP_IMPORTED_CONFIG_DEBUG RelWithDebInfo
)

# ---------------------------------------------------------------------------
# Windows SxS (Side-by-Side) loading support
#
# Embeds private-assembly manifests into OV/TBB DLLs and the provider DLL so
# that Windows loads them from the EP's own directory, avoiding DLL collisions
# when another application in the same process also uses OpenVINO.
#
# Build-time approach: OV/TBB DLLs are staged into <build>/sxs_staging/<config>/,
# Authenticode signatures are stripped, and SxS dep manifests are embedded.
# The provider DLL gets its dep manifest via a POST_BUILD step.
# ---------------------------------------------------------------------------
if(WIN32)
# --- Locate Windows SDK tools ---
# Locate a tool in the newest available Windows SDK x64 bin directory.
function(ort_find_winsdk_tool out_var exe_name)
if(${out_var})
return()
endif()
set(_hints "")
if(DEFINED ENV{WDKBinRoot})
list(APPEND _hints "$ENV{WDKBinRoot}/x64")
endif()
file(GLOB _glob_hints
"C:/Program Files (x86)/Windows Kits/10/bin/10.*/x64"
"C:/Program Files/Windows Kits/10/bin/10.*/x64")
list(SORT _glob_hints COMPARE NATURAL ORDER DESCENDING)
list(APPEND _hints ${_glob_hints})
find_program(${out_var} "${exe_name}" HINTS ${_hints} NO_DEFAULT_PATH)
if(NOT ${out_var})
message(FATAL_ERROR
"${exe_name}.exe not found in known Windows SDK paths.\n"
"Set -D${out_var}=<path/to/${exe_name}.exe> to override.")
endif()
message(STATUS "Found ${exe_name}.exe: ${${out_var}}")
endfunction()

ort_find_winsdk_tool(CMAKE_MT mt)
ort_find_winsdk_tool(ORT_SIGNTOOL_EXE signtool)

# --- Enumerate OV and TBB DLL filenames for the SxS assembly manifest ---
# Glob patterns selecting the OV binaries needed by the EP.
set(_ORT_OV_PATTERNS
"cache.json"
"*openvino.*"
"*openvinod.*"
"*openvino*plugin*"
"*openvino*compiler*"
"*openvino_ir_frontend*"
"*openvino_onnx_frontend*")

function(_ort_glob_ov _out_var _dir)
set(_result "")
foreach(_pat IN LISTS _ORT_OV_PATTERNS)
file(GLOB _tmp "${_dir}/${_pat}")
list(APPEND _result ${_tmp})
endforeach()
set(${_out_var} "${_result}" PARENT_SCOPE)
endfunction()

if(DEFINED ENV{INTEL_OPENVINO_DIR})
file(TO_CMAKE_PATH "$ENV{INTEL_OPENVINO_DIR}" _ORT_OV_ROOT)
set(_ov_bin "${_ORT_OV_ROOT}/runtime/bin/intel64")
set(_tbb_bin "${_ORT_OV_ROOT}/runtime/3rdparty/tbb/bin")

# TBB: split into non-debug (Release/RelWithDebInfo) and debug subsets
file(GLOB _all_tbb "${_tbb_bin}/tbb*.dll")
set(_tbb_release "")
set(_tbb_debug "")
foreach(_f IN LISTS _all_tbb)
get_filename_component(_lname "${_f}" NAME)
string(TOLOWER "${_lname}" _lname_lower)
if(_lname_lower MATCHES "debug")
list(APPEND _tbb_debug "${_f}")
else()
list(APPEND _tbb_release "${_f}")
endif()
endforeach()

if(EXISTS "${_ov_bin}/Release")
_ort_glob_ov(_ov_release "${_ov_bin}/Release")
set(ORT_OV_TBB_INSTALL_FILES_Release ${_ov_release} ${_tbb_release})
endif()
if(EXISTS "${_ov_bin}/Debug")
_ort_glob_ov(_ov_debug "${_ov_bin}/Debug")
set(ORT_OV_TBB_INSTALL_FILES_Debug ${_ov_debug} ${_tbb_debug})
endif()
if(EXISTS "${_ov_bin}/RelWithDebInfo")
_ort_glob_ov(_ov_rwdi "${_ov_bin}/RelWithDebInfo")
set(ORT_OV_TBB_INSTALL_FILES_RelWithDebInfo ${_ov_rwdi} ${_tbb_release})
elseif(DEFINED ORT_OV_TBB_INSTALL_FILES_Release)
set(ORT_OV_TBB_INSTALL_FILES_RelWithDebInfo ${ORT_OV_TBB_INSTALL_FILES_Release})
endif()
else()
# Python wheel layout — all binaries flat in <site-packages>/openvino/libs/
set(Python3_FIND_VIRTUALENV FIRST)
find_package(Python3 QUIET COMPONENTS Interpreter)
if(Python3_FOUND)
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c
"import openvino, pathlib; print(pathlib.Path(openvino.__file__).parent)"
OUTPUT_VARIABLE _ORT_OV_WHEEL_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _ORT_OV_WHEEL_RESULT)
endif()
if(Python3_FOUND AND _ORT_OV_WHEEL_RESULT EQUAL 0 AND _ORT_OV_WHEEL_DIR)
file(TO_CMAKE_PATH "${_ORT_OV_WHEEL_DIR}" _ORT_OV_ROOT)
set(_libs "${_ORT_OV_ROOT}/libs")
if(EXISTS "${_libs}")
_ort_glob_ov(_ov_wheel "${_libs}")
file(GLOB _tbb_wheel "${_libs}/tbb*.dll")
set(ORT_OV_TBB_INSTALL_FILES_wheel ${_ov_wheel} ${_tbb_wheel})
endif()
endif()
endif()

# Collect unique DLL filenames for SxS dep manifest embedding
set(_all_files
${ORT_OV_TBB_INSTALL_FILES_Release}
${ORT_OV_TBB_INSTALL_FILES_Debug}
${ORT_OV_TBB_INSTALL_FILES_RelWithDebInfo}
${ORT_OV_TBB_INSTALL_FILES_wheel})
set(ORT_OV_TBB_DLL_NAMES "")
foreach(_f IN LISTS _all_files)
get_filename_component(_ext "${_f}" EXT)
get_filename_component(_name "${_f}" NAME)
if(_ext STREQUAL ".dll")
list(APPEND ORT_OV_TBB_DLL_NAMES "${_name}")
endif()
endforeach()
list(REMOVE_DUPLICATES ORT_OV_TBB_DLL_NAMES)

if(ORT_OV_TBB_DLL_NAMES)
message(STATUS "OpenVINO SxS: DLLs for manifest: ${ORT_OV_TBB_DLL_NAMES}")

# --- Pre-generate SxS manifests at configure time ---
set(_sxs_manifest_dir "${CMAKE_BINARY_DIR}/sxs_manifests")
file(MAKE_DIRECTORY "${_sxs_manifest_dir}")
set(_ep_file_version "${ORT_VERSION}.0")

# Per-DLL dep manifests (dep.manifest.in uses ${DLL_BASE_NAME} and ${EP_FILE_VERSION})
foreach(_dll_name IN LISTS ORT_OV_TBB_DLL_NAMES)
get_filename_component(_dll_we "${_dll_name}" NAME_WE)
set(DLL_BASE_NAME "${_dll_we}")
set(EP_FILE_VERSION "${_ep_file_version}")
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/sxs/dep.manifest.in"
"${_sxs_manifest_dir}/${_dll_we}.dep.manifest"
)
endforeach()

# Per-config assembly manifests (only list DLLs that belong to each config)
set(ORT_SXS_VERSION "${ORT_VERSION}")
set(_asm_configs Release Debug RelWithDebInfo)
if(DEFINED ORT_OV_TBB_INSTALL_FILES_wheel)
set(_asm_configs wheel)
endif()

foreach(_cfg IN LISTS _asm_configs)
set(ORT_SXS_ASSEMBLY_FILE_ENTRIES "")
foreach(_f IN LISTS ORT_OV_TBB_INSTALL_FILES_${_cfg})
get_filename_component(_ext "${_f}" EXT)
get_filename_component(_name "${_f}" NAME)
if(_ext STREQUAL ".dll")
string(APPEND ORT_SXS_ASSEMBLY_FILE_ENTRIES " <file name=\"${_name}\" />\n")
endif()
endforeach()
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/sxs/assembly.manifest.in"
"${_sxs_manifest_dir}/openvino_runtime_${_cfg}.manifest"
@ONLY)
set(ORT_SXS_ASSEMBLY_MANIFEST_${_cfg} "${_sxs_manifest_dir}/openvino_runtime_${_cfg}.manifest")
endforeach()

# --- Build-time staging: copy, strip signatures, embed dep manifests ---
set(_sxs_staging_root "${CMAKE_BINARY_DIR}/sxs_staging")

function(_ort_sxs_stage_file _out_dst _cfg _src)
get_filename_component(_name "${_src}" NAME)
get_filename_component(_ext "${_src}" EXT)
set(_dst "${_sxs_staging_root}/${_cfg}/${_name}")

if(_ext STREQUAL ".dll")
get_filename_component(_name_we "${_src}" NAME_WE)
add_custom_command(
OUTPUT "${_dst}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${_sxs_staging_root}/${_cfg}"
COMMAND "${CMAKE_COMMAND}" -E copy "${_src}" "${_dst}"
COMMAND "${CMAKE_COMMAND}"
"-DSIGNTOOL=${ORT_SIGNTOOL_EXE}"
"-DDLL_PATH=${_dst}"
-P "${CMAKE_CURRENT_LIST_DIR}/sxs/remove_signature.cmake"
COMMAND "${CMAKE_COMMAND}"
"-DCMAKE_MT=${CMAKE_MT}"
"-DDLL_PATH=${_dst}"
"-DMANIFEST_PATH=${_sxs_manifest_dir}/${_name_we}.dep.manifest"
-P "${CMAKE_CURRENT_LIST_DIR}/sxs/embed_manifest.cmake"
DEPENDS "${_src}" "${_sxs_manifest_dir}/${_name_we}.dep.manifest"
COMMENT "SxS ${_cfg}/${_name}: remove signature + embed manifest"
VERBATIM
)
else()
add_custom_command(
OUTPUT "${_dst}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${_sxs_staging_root}/${_cfg}"
COMMAND "${CMAKE_COMMAND}" -E copy "${_src}" "${_dst}"
DEPENDS "${_src}"
COMMENT "SxS ${_cfg}/${_name}: copy"
VERBATIM
)
endif()
set(${_out_dst} "${_dst}" PARENT_SCOPE)
endfunction()

if(DEFINED ORT_OV_TBB_INSTALL_FILES_wheel)
set(_staged_wheel "")
foreach(_src IN LISTS ORT_OV_TBB_INSTALL_FILES_wheel)
_ort_sxs_stage_file(_dst "$<CONFIG>" "${_src}")
list(APPEND _staged_wheel "${_dst}")
endforeach()
Comment on lines +315 to +320
set(ORT_OV_TBB_STAGED_FILES_wheel "${_staged_wheel}")
add_custom_target(ort_embed_ov_tbb_manifests ALL DEPENDS ${ORT_OV_TBB_STAGED_FILES_wheel})
else()
set(_all_staged "")
foreach(_cfg IN ITEMS Release Debug RelWithDebInfo)
foreach(_src IN LISTS ORT_OV_TBB_INSTALL_FILES_${_cfg})
_ort_sxs_stage_file(_dst "${_cfg}" "${_src}")
list(APPEND _all_staged "${_dst}")
list(APPEND ORT_OV_TBB_STAGED_FILES_${_cfg} "${_dst}")
endforeach()
endforeach()
add_custom_target(ort_embed_ov_tbb_manifests ALL DEPENDS ${_all_staged})
endif()

# --- Post-build: embed dep manifest into onnxruntime_providers_openvino.dll ---
set(DLL_BASE_NAME "onnxruntime_providers_openvino")
set(EP_FILE_VERSION "${_ep_file_version}")
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/sxs/dep.manifest.in"
"${_sxs_manifest_dir}/onnxruntime_providers_openvino.dep.manifest"
)
add_custom_command(TARGET onnxruntime_providers_openvino POST_BUILD
COMMAND "${CMAKE_COMMAND}"
"-DCMAKE_MT=${CMAKE_MT}"
"-DDLL_PATH=$<TARGET_FILE:onnxruntime_providers_openvino>"
"-DMANIFEST_PATH=${_sxs_manifest_dir}/onnxruntime_providers_openvino.dep.manifest"
-P "${CMAKE_CURRENT_LIST_DIR}/sxs/embed_manifest.cmake"
COMMENT "SxS: embedding dep manifest into onnxruntime_providers_openvino.dll"
VERBATIM
)

# --- Install staged OV+TBB binaries and assembly manifest ---
if(DEFINED ORT_OV_TBB_STAGED_FILES_wheel)
install(FILES ${ORT_OV_TBB_STAGED_FILES_wheel} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES "${ORT_SXS_ASSEMBLY_MANIFEST_wheel}"
RENAME "openvino_runtime.manifest"
DESTINATION ${CMAKE_INSTALL_BINDIR})
else()
foreach(_config IN ITEMS Release Debug RelWithDebInfo)
if(ORT_OV_TBB_STAGED_FILES_${_config})
install(FILES ${ORT_OV_TBB_STAGED_FILES_${_config}}
DESTINATION ${CMAKE_INSTALL_BINDIR}
CONFIGURATIONS ${_config})
endif()
if(ORT_SXS_ASSEMBLY_MANIFEST_${_config})
install(FILES "${ORT_SXS_ASSEMBLY_MANIFEST_${_config}}"
RENAME "openvino_runtime.manifest"
DESTINATION ${CMAKE_INSTALL_BINDIR}
CONFIGURATIONS ${_config})
endif()
endforeach()
endif()
else()
message(WARNING "OpenVINO SxS: No OV/TBB DLLs found — SxS manifest embedding skipped.\n"
"Ensure INTEL_OPENVINO_DIR is set (setupvars.bat) or the openvino wheel is installed.")
endif()
endif()
3 changes: 3 additions & 0 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,9 @@ endif()
if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
target_link_libraries(onnxruntime_test_all PRIVATE Python::Python)
endif()
if (WIN32 AND onnxruntime_USE_OPENVINO)
target_link_libraries(onnxruntime_test_all PRIVATE psapi)
endif()
onnxruntime_apply_emscripten_test_link_settings(onnxruntime_test_all)

if (onnxruntime_ENABLE_ATEN)
Expand Down
12 changes: 12 additions & 0 deletions cmake/sxs/assembly.manifest.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
Windows SxS private assembly manifest for the OpenVINO runtime bundled with
onnxruntime_providers_openvino.dll (legacy EP).
Installed as bin/openvino_runtime.manifest alongside the provider DLL.
Version matches the ORT version (MAJOR.MINOR.PATCH.0).
Configured at build time by CMakeLists.txt — do not edit by hand.
-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="openvino_runtime"
version="@ORT_SXS_VERSION@.0" processorArchitecture="amd64" />
@ORT_SXS_ASSEMBLY_FILE_ENTRIES@</assembly>
18 changes: 18 additions & 0 deletions cmake/sxs/dep.manifest.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
SxS dependency manifest embedded into each OV/TBB DLL and
onnxruntime_providers_openvino.dll.
Declares a dependency on the openvino_runtime private assembly at the EP version,
matching the version in assembly.manifest.in.
Generated by cmake/sxs/embed_manifest.cmake — do not edit by hand.
-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="${DLL_BASE_NAME}"
version="${EP_FILE_VERSION}" processorArchitecture="amd64" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="openvino_runtime"
version="${EP_FILE_VERSION}" processorArchitecture="amd64" />
</dependentAssembly>
</dependency>
</assembly>
24 changes: 24 additions & 0 deletions cmake/sxs/embed_manifest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) Intel Corporation
# Licensed under the MIT License
#
# cmake -P script: embed a manifest file into a PE binary as RT_MANIFEST resource ID 2.
#
# Variables (passed via -D):
# CMAKE_MT — absolute path to mt.exe
# DLL_PATH — absolute path to the PE file to modify
# MANIFEST_PATH — absolute path to the .manifest file to embed
cmake_minimum_required(VERSION 3.28)

execute_process(
COMMAND "${CMAKE_MT}" -nologo
"-manifest" "${MANIFEST_PATH}"
"-outputresource:${DLL_PATH};2"
RESULT_VARIABLE _rc
OUTPUT_VARIABLE _out
ERROR_VARIABLE _err
)

if(NOT _rc EQUAL 0)
message(FATAL_ERROR
"embed_manifest: mt.exe failed for '${DLL_PATH}' (exit ${_rc}):\n${_out}${_err}")
endif()
35 changes: 35 additions & 0 deletions cmake/sxs/remove_signature.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) Intel Corporation
# Licensed under the MIT License
#
# cmake -P script: remove the Authenticode digital signature from a PE file.
#
# Variables (passed via -D):
# SIGNTOOL — absolute path to signtool.exe
# DLL_PATH — absolute path to the PE file
#
# Uses signtool verify to detect whether the file is signed before attempting
# removal, so unsigned files are skipped cleanly without parsing error messages.
cmake_minimum_required(VERSION 3.28)

execute_process(
COMMAND "${SIGNTOOL}" verify /pa "${DLL_PATH}"
RESULT_VARIABLE _signed
OUTPUT_QUIET ERROR_QUIET
)

if(NOT _signed EQUAL 0)
message(STATUS "remove_signature: '${DLL_PATH}' is not signed — skipped")
return()
endif()

execute_process(
COMMAND "${SIGNTOOL}" remove /s "${DLL_PATH}"
RESULT_VARIABLE _rc
OUTPUT_VARIABLE _out
ERROR_VARIABLE _err
)

if(NOT _rc EQUAL 0)
message(FATAL_ERROR
"remove_signature: signtool remove failed for '${DLL_PATH}' (exit ${_rc}):\n${_out}${_err}")
endif()
Loading
Loading