Add WinML EP Catalog CMake sample with NuGet package integration#593
Add WinML EP Catalog CMake sample with NuGet package integration#593
Conversation
|
|
||
| function Write-ErrorMessage { | ||
| param([string]$Message) | ||
| Write-Host "[ERROR] $Message" -ForegroundColor Red |
There was a problem hiding this comment.
| Write-Host "[ERROR] $Message" -ForegroundColor Red | |
| Write-Error $Message |
Send this to the error stream? Maybe get rid of this function and call Write-Error directly.
| # Local NuGet package configuration | ||
| set(WINML_NUGET_PACKAGE "${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.WindowsAppSDK.ML.2.0.246-experimental.nupkg" | ||
| CACHE FILEPATH "Path to Microsoft.WindowsAppSDK.ML nupkg") | ||
| set(WINML_LOCAL_PACKAGES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/local_packages" |
There was a problem hiding this comment.
Consider extracting somewhere under the CMAKE_CURRENT_BINARY_DIR or CMAKE_BINARY_DIR so that the source tree isn't touched.
| if(NOT DEFINED microsoft.windows.ai.machinelearning_DIR) | ||
| if(EXISTS "${WINML_NUGET_PACKAGE}") | ||
| get_filename_component(_winml_nupkg_filename "${WINML_NUGET_PACKAGE}" NAME) | ||
| string(REGEX REPLACE "\\.nupkg$" "" _winml_nupkg_name "${_winml_nupkg_filename}") |
There was a problem hiding this comment.
cmake_path(GET WINML_NUGET_PACKAGE STEM _winml_nupkg_filename) looks like it will handle getting just the filename without the extension. get_filename_component was superseded by the cmake_path() in 3.20 too.
| if(EXISTS "${WINML_NUGET_PACKAGE}") | ||
| get_filename_component(_winml_nupkg_filename "${WINML_NUGET_PACKAGE}" NAME) | ||
| string(REGEX REPLACE "\\.nupkg$" "" _winml_nupkg_name "${_winml_nupkg_filename}") | ||
| set(_winml_extract_dir "${WINML_LOCAL_PACKAGES_DIR}/${_winml_nupkg_name}") |
There was a problem hiding this comment.
These two could use cmake_Path(APPEND ...) to construct instead of string concatenation.
| if (FAILED(hr)) | ||
| { | ||
| std::cout << " Failed to get library path\n\n"; | ||
| return TRUE; | ||
| } | ||
| libraryPathUtf8.resize(used > 0 ? used - 1 : 0); |
There was a problem hiding this comment.
| if (FAILED(hr)) | |
| { | |
| std::cout << " Failed to get library path\n\n"; | |
| return TRUE; | |
| } | |
| libraryPathUtf8.resize(used > 0 ? used - 1 : 0); | |
| if (FAILED(hr) || used == 0) | |
| { | |
| std::cout << " Failed to get library path\n\n"; | |
| return TRUE; | |
| } | |
| libraryPathUtf8.resize(used - 1); |
Minor: symmetry with the error check above and simplifies the resize call
| } | ||
| } | ||
|
|
||
| WinMLEpCatalogRelease(catalog); |
There was a problem hiding this comment.
Can the catalog be released after the enumeration is done?
|
|
||
| std::cout << std::format("\nRegistered {} certified provider(s).\n", ctx.registeredProviders.size()); | ||
|
|
||
| // Unregister providers before env goes out of scope |
There was a problem hiding this comment.
A bit more explanation about why this is needed would be helpful.
env is a C++ object, so I would expect it to automatically clean itself up.
Adds a standalone CMake sample that demonstrates the WinMLEpCatalog C API for discovering and registering certified execution providers with ONNX Runtime. The build automatically restores the Microsoft.WindowsAppSDK.ML NuGet package during CMake configure via nuget install. A local .nupkg in the sample directory is used preferentially (for pre-release testing). All required runtime DLLs (onnxruntime.dll, onnxruntime_providers_shared.dll, DirectML.dll, Microsoft.Windows.AI.MachineLearning.dll) are copied to the output directory. The package version is controlled by a single WINML_NUGET_VERSION cache variable (default: 1.8.2141).
ab023f5 to
94d7a15
Compare
Adds a CMake-based C++ sample demonstrating the WinML Execution Provider Catalog C API (WinMLEpCatalog*) for discovering and registering hardware-accelerated ML execution providers with ONNX Runtime.
What the sample shows:
Build setup: