Skip to content

Commit 2992fda

Browse files
prathikrPrathik RaoCopilotbmehta001Copilot
authored
Load WinML runtime DLL for SDK EP discovery (#733)
## Summary - Load `Microsoft.Windows.AI.MachineLearning.dll` from the Core native directory for the Python SDK when present. - Preload the same WinML runtime DLL for Rust `winml` builds from the native runtime directory. - Preload the WinML runtime DLL for C# WinML builds alongside ORT and ORT GenAI. - No JS SDK code change needed; its existing loader already handles the native runtime directory. ## Validation - Rust WinML EP smoke without a caller PATH override discovered CUDA, OpenVINO, and NvTensorRTRTX, then registered OpenVINO. - C# WinML source smoke without a caller PATH override discovered CUDA, OpenVINO, and NvTensorRTRTX, then registered OpenVINO. - JS EP smoke without a caller PATH override discovered CUDA, OpenVINO, and NvTensorRTRTX, then registered OpenVINO. --------- Co-authored-by: Prathik Rao <prathikrao@microsoft.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Bhagirath Mehta <bhamehta@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 33a1a2f commit 2992fda

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

sdk/python/src/detail/core_interop.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class CoreInterop:
132132
_flcore_library = None
133133
_genai_library = None
134134
_ort_library = None
135+
_winml_library = None
135136

136137
instance = None
137138

@@ -182,6 +183,17 @@ def _initialize_native_libraries() -> 'NativeBinaryPaths':
182183
if sys.platform.startswith("win"):
183184
CoreInterop._ort_library = ctypes.CDLL(str(paths.ort))
184185
CoreInterop._genai_library = ctypes.CDLL(str(paths.genai))
186+
winml_path = paths.core_dir / "Microsoft.Windows.AI.MachineLearning.dll"
187+
if winml_path.exists():
188+
# only exists in the WinML variant, load if present so that Core can use WinML EPs
189+
try:
190+
CoreInterop._winml_library = ctypes.CDLL(str(winml_path))
191+
except OSError as e:
192+
logger.warning(
193+
"Failed to load optional WinML library '%s'; continuing without WinML EPs: %s",
194+
winml_path,
195+
e,
196+
)
185197
else:
186198
CoreInterop._ort_library = ctypes.CDLL(str(paths.ort), mode=os.RTLD_GLOBAL)
187199
CoreInterop._genai_library = ctypes.CDLL(str(paths.genai), mode=os.RTLD_GLOBAL)

sdk/rust/src/detail/core_interop.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,25 @@ impl CoreInterop {
787787
}
788788
}
789789

790+
#[cfg(feature = "winml")]
791+
{
792+
let winml_dep = "Microsoft.Windows.AI.MachineLearning.dll";
793+
let winml_path = dir.join(winml_dep);
794+
if winml_path.exists() {
795+
// The WinML feature uses the WinML Core package and copies this
796+
// DLL into the native directory; load it from there so callers
797+
// don't need to add that directory to PATH.
798+
// SAFETY: Pre-loading a known dependency DLL from the same trusted
799+
// directory as the core library.
800+
let lib = unsafe {
801+
Library::new(&winml_path).map_err(|e| FoundryLocalError::LibraryLoad {
802+
reason: format!("Failed to load dependency {winml_dep}: {e}"),
803+
})?
804+
};
805+
libs.push(lib);
806+
}
807+
}
808+
790809
Ok(libs)
791810
}
792811
}

0 commit comments

Comments
 (0)