Skip to content

Add ONNX Runtime sample with the Windows ML CG Execution Provider - #39

Merged
Zarana Kiran Desai (zadesai) merged 2 commits into
release/2.9-experimentalfrom
user/zadesai/cgep-sample-2.9
Nov 17, 2026
Merged

Zarana Kiran Desai (zadesai) merged 2 commits into
release/2.9-experimentalfrom
user/zadesai/cgep-sample-2.9

Conversation

@zadesai

Copy link
Copy Markdown

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.

  • Support physical adapter selection and application-owned EPContext caching with model/package/device identity, serialized publication, and incomplete-publication recovery.
  • Reuse shared image decoding, ImageNet normalization, artifact checks, build tooling, and launcher, plus centrally pinned WIL resource management.
  • Register the sample in the Runtime solution, artifact catalog, and documentation without changing release package versions.
  • Do not include model binaries or generated build/cache outputs.

Related issue

None.

Affected samples

  • Samples/Runtime/interop/onnx-runtime-winmlcgep
  • Runtime build/run registration and documentation
  • Samples/shared/SampleArtifacts.psd1

Checklist

  • I built Samples/WindowsML-Samples.sln locally with Visual Studio 2022 or Visual Studio 2026
  • I ran the affected sample(s) end-to-end on Windows 11 (x64 and/or ARM64)
  • C++ changes follow the repo .clang-format (ran Samples/format-code.ps1 if available)
  • I updated the relevant per-sample README.md
  • I did not check in large model artifacts, build outputs, or secrets

Testing notes

Validation performed on x64 on November 16, 2026:

Command / check Result
& .\Samples\Runtime\build.ps1 -Sample onnx-runtime-winmlcgep -Platform x64 -Configuration Release -PackageOnly -Rebuild Passed. NU1900: NuGet vulnerability metadata was unreachable.
& .\Samples\Runtime\check_artifacts.ps1 -Sample onnx-runtime-winmlcgep -ModelsDir .\Samples\Runtime\out\x64\Release\onnx-runtime-winmlcgep\models Passed: model, image, and labels match pinned sizes and SHA-256.
& $exe --adapter-name NvIdIa --recompile and & $exe --adapter-name NvIdIa Both passed, exit 0: NVIDIA GeForce RTX 5060 Ti; cold compile then warm reuse; WinMLCGEP assignment; Samoyed 97.88%.
& $exe --adapter-name aMd --recompile and & $exe --adapter-name aMd Both passed, exit 0: AMD Radeon Graphics; cold compile then warm reuse; WinMLCGEP assignment; Samoyed 94.47%.
Installed clang-format --dry-run --Werror --style=file on main.cpp Passed.
git diff --check Passed.

$exe above is Samples\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.sln build (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 under Samples/Runtime/models.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@nieubank Nick Eubanks (nieubank) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zadesai
Zarana Kiran Desai (zadesai) merged commit 81efbbe into release/2.9-experimental Nov 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants