Repository navigation
Add ONNX Runtime sample with the Windows ML CG Execution Provider - #39
Conversation
Add physical GPU selection, persistent EPContext caching, and shared artifact/build integration. Reuse shared image preprocessing and WIL resource management while preserving release package defaults. Validated x64 Release on NVIDIA and AMD with cold/warm runs, concurrent launches, and cache failure/recovery checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cd8050c-b45d-45aa-bb86-50586dc5411f
There was a problem hiding this comment.
🟡 Changes recommended
The session-local mutex leaves shared cache files unprotected across Windows logon sessions, allowing concurrent compilation to delete another process’s temporary output.
3 open issues
What changed in this PR
Adds a C++ sample that uses ONNX Runtime directly with the Windows ML CG Execution Provider to compile and run SqueezeNet on a physical GPU, alongside the existing native Runtime samples.
Changes:
- Adds adapter selection, image classification, and an application-owned compilation cache with publication and recovery logic.
- Integrates the sample with shared build tooling, artifact checks, the launcher, and the Runtime solution.
- Documents setup, GPU requirements, and cache behavior without changing release package versions.
| File | Description |
|---|---|
Samples/shared/SampleArtifacts.psd1 |
Registers the sample’s existing SqueezeNet artifacts. |
Samples/Runtime/windows-ml-runtime.slnx |
Adds the project and launcher to the solution. |
Samples/Runtime/run_onnx_runtime_winmlcgep.ps1 |
Adds artifact checks and launch options. |
Samples/Runtime/README.md |
Lists the sample and clarifies caching and GPU requirements. |
Samples/Runtime/interop/onnx-runtime-winmlcgep/README.md |
Documents setup, usage, caching, and API boundaries. |
Samples/Runtime/interop/onnx-runtime-winmlcgep/onnx-runtime-winmlcgep.vcxproj |
Defines the native project and package-version metadata output. |
Samples/Runtime/interop/onnx-runtime-winmlcgep/main.cpp |
Implements GPU selection, compilation caching, and classification. |
Samples/Runtime/check_artifacts.ps1 |
Includes the sample in artifact validation. |
Samples/Runtime/build.ps1 |
Adds targeted and all-sample build registration. |
docs/Runtime/artifacts.md |
Lists the sample’s artifact group. |
Review effort: Balanced
Use an exclusive cache lock file across Windows sessions, reject empty adapter indices, and forward the verified model root to native inference without fallback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cd8050c-b45d-45aa-bb86-50586dc5411f
Nick Eubanks (nieubank)
left a comment
There was a problem hiding this comment.
Looks good to ship. I built it merged onto the current release/2.9-experimental, with the 2.9.36-experimental pin, for ARM64 and x64 with no warnings. On ARM64 with an NVIDIA RTX Spark GPU, the cold run compiled the cache in 5.2 seconds and the warm run reused it, and both classified the sample image as Samoyed at 97.88%. An empty --adapter-index, an unmatched --adapter-name and an out-of-range index are all rejected.
This touches the same three files as #30, so whichever lands second needs a rebase. If this one lands first, I'll rebase #30.
81efbbe
into
release/2.9-experimental


Summary
Add a C++ sample using the ONNX Runtime API directly with the Windows ML CG Execution Provider to compile and run SqueezeNet on a physical GPU.
Related issue
None.
Affected samples
Samples/Runtime/interop/onnx-runtime-winmlcgepSamples/shared/SampleArtifacts.psd1Checklist
Samples/WindowsML-Samples.slnlocally with Visual Studio 2022 or Visual Studio 2026.clang-format(ranSamples/format-code.ps1if available)README.mdTesting notes
Validation performed on x64 on November 16, 2026:
& .\Samples\Runtime\build.ps1 -Sample onnx-runtime-winmlcgep -Platform x64 -Configuration Release -PackageOnly -Rebuild& .\Samples\Runtime\check_artifacts.ps1 -Sample onnx-runtime-winmlcgep -ModelsDir .\Samples\Runtime\out\x64\Release\onnx-runtime-winmlcgep\models& $exe --adapter-name NvIdIa --recompileand& $exe --adapter-name NvIdIa& $exe --adapter-name aMd --recompileand& $exe --adapter-name aMdclang-format --dry-run --Werror --style=fileonmain.cppgit diff --check$exeabove isSamples\Runtime\out\x64\Release\onnx-runtime-winmlcgep\onnx-runtime-winmlcgep.exe. Native output was redirected during validation to avoid the interactive keypress pause.Additional targeted checks passed: simultaneous first launches produced exactly one compile and one warm reuse; a locked destination forced publication failure with exit 1 and temporary-file cleanup, followed by successful incomplete-cache recovery; invalid/missing/conflicting adapter arguments were rejected. Model assets were unchanged.
Not validated: the legacy
Samples/WindowsML-Samples.slnbuild (used the targeted Runtime project instead), ARM64, and exact preprocessing parity with the pinned quantized model's original training/reference pipeline. Successful classification and confidence scores are functional checks, not model-accuracy validation. The convenience run wrapper was not used for successful inference because isolated validation assets reside beside the executable rather than underSamples/Runtime/models.