-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[WebGPU plugin EP] NuGet packaging #28313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edgchen1
wants to merge
33
commits into
main
Choose a base branch
from
edgchen1/webgpu_packaging_nuget
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e351aea
Add NuGet packaging for WebGPU plugin EP
edgchen1 9187830
Add setup-build-tools and set-nightly-build-option templates to NuGet…
edgchen1 02f4eb9
Move NuGet test job to plugin-webgpu-test-pipeline
edgchen1 3a48445
add version_file parameter
edgchen1 7a2e483
Move NuGet test job into Windows test stage
edgchen1 e36bacf
Use internal NuGet feed for WebGPU plugin packaging and test pipelines
edgchen1 0924c97
Sign managed WebGPU plugin DLL before packing into NuGet
edgchen1 7fabfd1
add build_wheel.py comment about assumption that binaries are directl…
edgchen1 11d41ee
Derive WebGPU plugin EP NuGet onnxruntime dependency from MIN_ONNXRUN…
edgchen1 685c3d1
Fix ESRP signing pattern for WebGPU plugin managed DLL
edgchen1 a1b85cc
Update readme files
edgchen1 a0b2e20
Address WebGPU plugin EP NuGet packaging review feedback
edgchen1 8643376
Port pack_nuget.ps1 to Python
edgchen1 52a6f97
Update README to reflect pack_nuget.py staging-dir behavior
edgchen1 0e7f395
Drop pack_nuget.py parameter table from README
edgchen1 3ca87d5
Fold pack_nuget.py notes into parent section in README
edgchen1 095bd3f
Address review nits in WebGPU EP NuGet packaging
edgchen1 b9ccab7
update example versions
edgchen1 74c0603
use sentinel as csproj default version value
edgchen1 1561737
Address PR review feedback
edgchen1 ad74055
Use pwsh shorthand consistently in WebGPU test stage
edgchen1 68ac995
Polish improvements after PR review fixes
edgchen1 13f7e96
remove cmake_build_type parameter from plugin-webgpu-nuget-packaging-…
edgchen1 964f11c
address review comments
edgchen1 2f87181
update comment
edgchen1 f717236
add early exit in OrtEpDevice iteration in test program
edgchen1 6a02745
use model generated from script
edgchen1 52bc9e8
Merge remote-tracking branch 'origin/main' into edgchen1/webgpu_packa…
edgchen1 073b629
Make Validate_Parameters always-on with explicit dependsOn
edgchen1 600adb8
update comment
edgchen1 479f9b4
Rename dependsOn parameter to depends_on for casing consistency
edgchen1 67ad2f8
Tighten Validate_Parameters comment wording
edgchen1 ee7990a
disable RC value from top level pipeline
edgchen1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ebgpu/csharp/Microsoft.ML.OnnxRuntime.EP.WebGpu/Microsoft.ML.OnnxRuntime.EP.WebGpu.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <LangVersion>latest</LangVersion> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <!-- Package info --> | ||
| <PackageId>Microsoft.ML.OnnxRuntime.EP.WebGpu</PackageId> | ||
| <!-- Sentinel default; overridden via -p:Version=<x.y.z> when packing (see pack_nuget.py). --> | ||
| <Version>0.0.0-dev</Version> | ||
| <Authors>Microsoft</Authors> | ||
| <Company>Microsoft</Company> | ||
| <Description>WebGPU plugin Execution Provider for ONNX Runtime. Provides GPU acceleration via WebGPU (Dawn) with D3D12 and Vulkan backends.</Description> | ||
| <PackageReadmeFile>README.md</PackageReadmeFile> | ||
| <PackageTags>ONNX;ONNX Runtime;Machine Learning;AI;Deep Learning;WebGPU</PackageTags> | ||
|
|
||
| <!-- License/Repository --> | ||
| <PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
| <RepositoryUrl>https://github.com/microsoft/onnxruntime</RepositoryUrl> | ||
| <RepositoryType>git</RepositoryType> | ||
| <Copyright>© Microsoft Corporation. All rights reserved.</Copyright> | ||
|
|
||
| <!-- Include symbols/source for better debugging experience --> | ||
| <IncludeSymbols>true</IncludeSymbols> | ||
| <SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- | ||
| Minimum required Microsoft.ML.OnnxRuntime version is read from a file (single source | ||
| of truth, shared with the other plugin EP packages). The path is overridable via | ||
| -p:OnnxRuntimeMinVersionFile=<absolute path> so callers (e.g. pack_nuget.py, which | ||
| builds out of a staged copy) can point at the original file in the source tree. | ||
| --> | ||
| <PropertyGroup> | ||
| <OnnxRuntimeMinVersionFile Condition="'$(OnnxRuntimeMinVersionFile)' == ''">$(MSBuildThisFileDirectory)..\..\MIN_ONNXRUNTIME_VERSION</OnnxRuntimeMinVersionFile> | ||
| <OnnxRuntimeMinVersion Condition="Exists('$(OnnxRuntimeMinVersionFile)')">$([System.IO.File]::ReadAllText('$(OnnxRuntimeMinVersionFile)').Trim())</OnnxRuntimeMinVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="_ValidateOnnxRuntimeMinVersion" BeforeTargets="CollectPackageReferences"> | ||
| <Error Condition="!Exists('$(OnnxRuntimeMinVersionFile)')" | ||
| Text="OnnxRuntimeMinVersionFile not found: '$(OnnxRuntimeMinVersionFile)'. Set -p:OnnxRuntimeMinVersionFile=<absolute path> or restore the file at the default location." /> | ||
| <Error Condition="'$(OnnxRuntimeMinVersion)' == ''" | ||
| Text="OnnxRuntimeMinVersion resolved to an empty value from '$(OnnxRuntimeMinVersionFile)'." /> | ||
| </Target> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.ML.OnnxRuntime" Version="$(OnnxRuntimeMinVersion)" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Ensure README is included in the package --> | ||
| <None Include="README.md" Pack="true" PackagePath="" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Native binaries per platform. Each ItemGroup is conditioned on the runtimes/ directory | ||
| existing so the project can build cleanly from the source tree. At pack time, pack_nuget.py | ||
| populates the staging directory with whichever platforms are available. --> | ||
| <ItemGroup> | ||
| <None Include="runtimes\win-x64\native\**" | ||
| Pack="true" | ||
| PackagePath="runtimes/win-x64/native/" | ||
| CopyToOutputDirectory="PreserveNewest" | ||
| Condition="Exists('runtimes\win-x64\native')" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="runtimes\win-arm64\native\**" | ||
| Pack="true" | ||
| PackagePath="runtimes/win-arm64/native/" | ||
| CopyToOutputDirectory="PreserveNewest" | ||
| Condition="Exists('runtimes\win-arm64\native')" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="runtimes\linux-x64\native\**" | ||
| Pack="true" | ||
| PackagePath="runtimes/linux-x64/native/" | ||
| CopyToOutputDirectory="PreserveNewest" | ||
| Condition="Exists('runtimes\linux-x64\native')" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="runtimes\osx-arm64\native\**" | ||
| Pack="true" | ||
| PackagePath="runtimes/osx-arm64/native/" | ||
| CopyToOutputDirectory="PreserveNewest" | ||
| Condition="Exists('runtimes\osx-arm64\native')" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
43 changes: 43 additions & 0 deletions
43
plugin-ep-webgpu/csharp/Microsoft.ML.OnnxRuntime.EP.WebGpu/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ## Microsoft.ML.OnnxRuntime.EP.WebGpu | ||
|
|
||
| WebGPU plugin Execution Provider for [ONNX Runtime](https://github.com/microsoft/onnxruntime). | ||
| Provides GPU acceleration via WebGPU (Dawn) with D3D12 and Vulkan backends. | ||
|
|
||
| ### Usage | ||
|
|
||
| ```csharp | ||
| // Note: Error handling is omitted for brevity. | ||
|
|
||
| using Microsoft.ML.OnnxRuntime; | ||
| using Microsoft.ML.OnnxRuntime.EP.WebGpu; | ||
|
|
||
| // Register the WebGPU EP plugin library | ||
| var env = OrtEnv.Instance(); | ||
| env.RegisterExecutionProviderLibrary("webgpu_ep", WebGpuEp.GetLibraryPath()); | ||
|
|
||
| // Find the WebGPU EP device | ||
| OrtEpDevice? webGpuDevice = null; | ||
| foreach (var d in env.GetEpDevices()) | ||
| { | ||
| if (d.EpName == WebGpuEp.GetEpName()) | ||
| { | ||
| webGpuDevice = d; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Create a session with the WebGPU EP | ||
| using var sessionOptions = new SessionOptions(); | ||
| sessionOptions.AppendExecutionProvider(env, new[] { webGpuDevice }, new Dictionary<string, string>()); | ||
|
edgchen1 marked this conversation as resolved.
|
||
|
|
||
| using var session = new InferenceSession("model.onnx", sessionOptions); | ||
| ``` | ||
|
|
||
| ### Supported Platforms | ||
|
|
||
| | Runtime Identifier | Native Library | | ||
| |---|---| | ||
| | win-x64 | `onnxruntime_providers_webgpu.dll`, `dxil.dll`, `dxcompiler.dll` | | ||
| | win-arm64 | `onnxruntime_providers_webgpu.dll`, `dxil.dll`, `dxcompiler.dll` | | ||
| | linux-x64 | `libonnxruntime_providers_webgpu.so` | | ||
| | osx-arm64 | `libonnxruntime_providers_webgpu.dylib` | | ||
112 changes: 112 additions & 0 deletions
112
plugin-ep-webgpu/csharp/Microsoft.ML.OnnxRuntime.EP.WebGpu/WebGpuEp.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.ML.OnnxRuntime.EP.WebGpu | ||
| { | ||
| /// <summary> | ||
| /// Provides helper methods to locate the WebGPU plugin EP native library | ||
| /// and retrieve the EP name for registration with ONNX Runtime. | ||
| /// </summary> | ||
| public static class WebGpuEp | ||
| { | ||
| /// <summary> | ||
| /// Returns the path to the WebGPU plugin EP native library contained by this package. | ||
| /// Can be passed to <c>OrtEnv.RegisterExecutionProviderLibrary()</c>. | ||
| /// </summary> | ||
| /// <returns>Full path to the EP native library.</returns> | ||
| /// <exception cref="FileNotFoundException">If the native library file does not exist at the expected path.</exception> | ||
| public static string GetLibraryPath() | ||
| { | ||
| string rootDir = GetNativeDirectory(); | ||
| string rid = GetRuntimeIdentifier(); | ||
| string libraryName = GetLibraryName(); | ||
|
|
||
| // Probe the standard NuGet runtimes/<rid>/native/ layout first, then fall back | ||
| // to the base directory for single-file/published layouts where native assets | ||
| // can land directly next to the managed assembly. | ||
| string[] candidates = | ||
| { | ||
| Path.Combine(rootDir, "runtimes", rid, "native", libraryName), | ||
| Path.Combine(rootDir, libraryName), | ||
| }; | ||
|
|
||
| foreach (var candidate in candidates) | ||
| { | ||
| if (File.Exists(candidate)) | ||
| return Path.GetFullPath(candidate); | ||
| } | ||
|
|
||
| throw new FileNotFoundException( | ||
| $"Did not find WebGPU EP library file. Probed: {string.Join(", ", candidates)}"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the names of the EPs created by the WebGPU plugin EP library. | ||
| /// Can be used to select an <c>OrtEpDevice</c> from those returned by <c>OrtEnv.GetEpDevices()</c>. | ||
| /// </summary> | ||
| /// <returns>Array of EP names.</returns> | ||
| public static string[] GetEpNames() | ||
| { | ||
| return new[] { GetEpName() }; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the name of the one EP supported by this plugin EP library. | ||
| /// Convenience method for plugin EP packages that expose a single EP. | ||
| /// </summary> | ||
| /// <returns>The EP name string.</returns> | ||
| public static string GetEpName() | ||
| { | ||
| return "WebGpuExecutionProvider"; | ||
| } | ||
|
|
||
| private static string GetNativeDirectory() | ||
| { | ||
| var assemblyDir = Path.GetDirectoryName(typeof(WebGpuEp).Assembly.Location); | ||
|
|
||
| if (!string.IsNullOrEmpty(assemblyDir) && Directory.Exists(assemblyDir)) | ||
| return assemblyDir; | ||
|
|
||
| return AppContext.BaseDirectory; | ||
| } | ||
|
|
||
| private static string GetRuntimeIdentifier() | ||
| { | ||
| return GetOSTag() + "-" + GetArchTag(); | ||
| } | ||
|
|
||
| private static string GetLibraryName() | ||
| { | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| return "onnxruntime_providers_webgpu.dll"; | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| return "libonnxruntime_providers_webgpu.so"; | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| return "libonnxruntime_providers_webgpu.dylib"; | ||
|
|
||
| throw new PlatformNotSupportedException( | ||
| $"WebGPU plugin EP does not support OS platform: {RuntimeInformation.OSDescription}"); | ||
| } | ||
|
|
||
| private static string GetOSTag() | ||
| { | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return "win"; | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return "linux"; | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return "osx"; | ||
| throw new PlatformNotSupportedException( | ||
| $"WebGPU plugin EP does not support OS platform: {RuntimeInformation.OSDescription}"); | ||
| } | ||
|
|
||
| private static string GetArchTag() | ||
| { | ||
| return RuntimeInformation.ProcessArchitecture switch | ||
| { | ||
| Architecture.X64 => "x64", | ||
| Architecture.Arm64 => "arm64", | ||
| _ => throw new PlatformNotSupportedException( | ||
| $"WebGPU plugin EP does not support process architecture: {RuntimeInformation.ProcessArchitecture}"), | ||
| }; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.