Skip to content
Open
Show file tree
Hide file tree
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 Apr 15, 2026
9187830
Add setup-build-tools and set-nightly-build-option templates to NuGet…
edgchen1 Apr 16, 2026
02f4eb9
Move NuGet test job to plugin-webgpu-test-pipeline
edgchen1 Apr 27, 2026
3a48445
add version_file parameter
edgchen1 Apr 28, 2026
7a2e483
Move NuGet test job into Windows test stage
edgchen1 Apr 28, 2026
e36bacf
Use internal NuGet feed for WebGPU plugin packaging and test pipelines
edgchen1 Apr 29, 2026
0924c97
Sign managed WebGPU plugin DLL before packing into NuGet
edgchen1 Apr 30, 2026
7fabfd1
add build_wheel.py comment about assumption that binaries are directl…
edgchen1 Apr 30, 2026
11d41ee
Derive WebGPU plugin EP NuGet onnxruntime dependency from MIN_ONNXRUN…
edgchen1 Apr 30, 2026
685c3d1
Fix ESRP signing pattern for WebGPU plugin managed DLL
edgchen1 Apr 30, 2026
a1b85cc
Update readme files
edgchen1 Apr 30, 2026
a0b2e20
Address WebGPU plugin EP NuGet packaging review feedback
edgchen1 May 1, 2026
8643376
Port pack_nuget.ps1 to Python
edgchen1 May 1, 2026
52a6f97
Update README to reflect pack_nuget.py staging-dir behavior
edgchen1 May 1, 2026
0e7f395
Drop pack_nuget.py parameter table from README
edgchen1 May 1, 2026
3ca87d5
Fold pack_nuget.py notes into parent section in README
edgchen1 May 1, 2026
095bd3f
Address review nits in WebGPU EP NuGet packaging
edgchen1 May 1, 2026
b9ccab7
update example versions
edgchen1 May 1, 2026
74c0603
use sentinel as csproj default version value
edgchen1 May 1, 2026
1561737
Address PR review feedback
edgchen1 May 4, 2026
ad74055
Use pwsh shorthand consistently in WebGPU test stage
edgchen1 May 4, 2026
68ac995
Polish improvements after PR review fixes
edgchen1 May 4, 2026
13f7e96
remove cmake_build_type parameter from plugin-webgpu-nuget-packaging-…
edgchen1 May 4, 2026
964f11c
address review comments
edgchen1 May 4, 2026
2f87181
update comment
edgchen1 May 4, 2026
f717236
add early exit in OrtEpDevice iteration in test program
edgchen1 May 4, 2026
6a02745
use model generated from script
edgchen1 May 4, 2026
52bc9e8
Merge remote-tracking branch 'origin/main' into edgchen1/webgpu_packa…
edgchen1 May 5, 2026
073b629
Make Validate_Parameters always-on with explicit dependsOn
edgchen1 May 5, 2026
600adb8
update comment
edgchen1 May 5, 2026
479f9b4
Rename dependsOn parameter to depends_on for casing consistency
edgchen1 May 5, 2026
67ad2f8
Tighten Validate_Parameters comment wording
edgchen1 May 5, 2026
ee7990a
disable RC value from top level pipeline
edgchen1 May 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions plugin-ep-webgpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ For more information about plugin EPs, see the documentation [here](https://onnx
- [`VERSION_NUMBER`](VERSION_NUMBER) — Base plugin EP version consumed by the CI pipeline. The pipeline derives the
final package version (release, dev) from this via
[`tools/ci_build/github/azure-pipelines/templates/set-plugin-build-variables-step.yml`](../tools/ci_build/github/azure-pipelines/templates/set-plugin-build-variables-step.yml).
- [`MIN_ONNXRUNTIME_VERSION`](MIN_ONNXRUNTIME_VERSION) — Minimum compatible core `onnxruntime` version. Single source
of truth shared by all packages built from this directory.
- [`python/`](python/) — Sources and build script for the `onnxruntime-ep-webgpu` Python wheel. See
[`python/README.md`](python/README.md) for build and test instructions.
- [`csharp/`](csharp/) — Sources and packaging script for the `Microsoft.ML.OnnxRuntime.EP.WebGpu` NuGet package. See
[`csharp/README.md`](csharp/README.md) for build and test instructions.

## How it fits together

The plugin EP is built as a shared library (`onnxruntime_providers_webgpu.{dll,so,dylib}`) by the main ONNX Runtime
build (`--use_webgpu shared_lib`). The resulting binaries are then packaged into:

- A Python wheel (`onnxruntime-ep-webgpu`), built from [`python/`](python/).
- A NuGet package (`Microsoft.ML.OnnxRuntime.EP.WebGpu`), built from [`csharp/`](csharp/).
- A universal package published to the internal ORT-Nightly feed for Windows (x64 / arm64), Linux x64, and macOS
arm64.

Expand All @@ -29,7 +34,7 @@ and post-build smoke tests run in the companion `WebGPU Plugin EP Test Pipeline`

## Usage

Once installed, the plugin EP is registered at runtime:
Once installed, the plugin EP is registered at runtime. Example in Python:

```python
import onnxruntime as ort
Expand All @@ -43,5 +48,7 @@ sess_options.add_provider_for_devices(devices, {})
session = ort.InferenceSession("model.onnx", sess_options=sess_options)
```

See [`python/onnxruntime_ep_webgpu/README.md`](python/onnxruntime_ep_webgpu/README.md) for the user-facing package
documentation (this README is bundled into the wheel).
See the user-facing package READMEs (bundled into the published packages) for full per-language usage:

- Python: [`python/onnxruntime_ep_webgpu/README.md`](python/onnxruntime_ep_webgpu/README.md)
- C# / .NET: [`csharp/Microsoft.ML.OnnxRuntime.EP.WebGpu/README.md`](csharp/Microsoft.ML.OnnxRuntime.EP.WebGpu/README.md)
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=&lt;absolute path&gt; 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>
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>());
Comment thread
edgchen1 marked this conversation as resolved.
Comment thread
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 plugin-ep-webgpu/csharp/Microsoft.ML.OnnxRuntime.EP.WebGpu/WebGpuEp.cs
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}"),
};
}
}
}
Loading
Loading