Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/linux_webgpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Linux WebGPU CI

on:
push:
branches: [main, 'rel-*']
branches: [main, 'rel-*', 'plugin-ep-webgpu/rel-*']
pull_request:
branches: [main, 'rel-*']
branches: [main, 'rel-*', 'plugin-ep-webgpu/rel-*']
workflow_dispatch:

concurrency:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- main
- rel-*
- plugin-ep-webgpu/rel-*
pull_request:
branches:
- main
- rel-*
- plugin-ep-webgpu/rel-*
workflow_dispatch:

concurrency:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- main
- rel-*
- plugin-ep-webgpu/rel-*
pull_request:
branches:
- main
- rel-*
- plugin-ep-webgpu/rel-*
workflow_dispatch:

concurrency:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows_webgpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- main
- rel-*
- plugin-ep-webgpu/rel-*
pull_request:
branches:
- main
- rel-*
- plugin-ep-webgpu/rel-*
workflow_dispatch:

concurrency:
Expand Down
10 changes: 10 additions & 0 deletions js/common/lib/inference-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ export declare namespace InferenceSession {
*/
validationMode?: 'disabled' | 'wgpuOnly' | 'basic' | 'full';

/**
* Enable robust buffer access for an ORT-created Dawn device. This is a global, first-device-wins option. Later
* conflicting values and values supplied with an external device are ignored with a warning.
*
* This setting is available only in ONNX Runtime (Node.js binding).
*
* @default `true` in Debug builds; `false` in Release and RelWithDebInfo builds
*/
enableRobustness?: boolean;

/**
* Specify the cache mode for storage buffers.
* - 'disabled': Disable buffer cache. Buffers are destroyed when no longer in use.
Expand Down
4 changes: 4 additions & 0 deletions js/node/src/session_options_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void ParseExecutionProviders(const Napi::Array epList, Ort::SessionOptions& sess
ORT_NAPI_THROW_TYPEERROR_IF(!valueVar.IsString(), epList.Env(),
"Invalid argument: \"", name, "\" must be a string.");
value = valueVar.As<Napi::String>().Utf8Value();
} else if (name == "enableRobustness") {
ORT_NAPI_THROW_TYPEERROR_IF(!valueVar.IsBoolean(), epList.Env(),
"Invalid argument: \"enableRobustness\" must be a boolean.");
value = valueVar.As<Napi::Boolean>().Value() ? "1" : "0";
} else if (name == "forceCpuNodeNames") {
ORT_NAPI_THROW_TYPEERROR_IF(!valueVar.IsArray(), epList.Env(),
"Invalid argument: \"forceCpuNodeNames\" must be a string array.");
Expand Down
14 changes: 4 additions & 10 deletions onnxruntime/core/providers/webgpu/reduction/reduction_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ REGISTER_REDUCE_KERNEL(ReduceMin, 20);
// Factory functions allow conditional int64 support on the T type constraint.
// NOTE: int64 reduction in the WebGPU shader uses i32 (low 32 bits only); values outside
// the int32 range will produce incorrect results — same limitation as Range.
template <int StartVersion, int EndVersion>
KernelCreateInfo CreateReduceSumVersionedKernelInfo(bool enable_int64) {
KernelCreateInfo CreateReduceSumVersionedKernelInfo(int start_version, int end_version, bool enable_int64) {
const auto& type_constraints = GetOpTypeConstraints(enable_int64, false);
KernelCreatePtrFn kernel_create_fn = [](FuncManager&, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out) -> Status {
out = std::make_unique<ReduceSum>(info);
Expand All @@ -73,15 +72,14 @@ KernelCreateInfo CreateReduceSumVersionedKernelInfo(bool enable_int64) {
return {KernelDefBuilder()
.SetName("ReduceSum")
.SetDomain(kOnnxDomain)
.SinceVersion(StartVersion, EndVersion)
.SinceVersion(start_version, end_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T", type_constraints)
.Build(),
kernel_create_fn};
}

template <int SinceVersion>
KernelCreateInfo CreateReduceSumKernelInfo(bool enable_int64) {
KernelCreateInfo CreateReduceSumKernelInfo(int since_version, bool enable_int64) {
const auto& type_constraints = GetOpTypeConstraints(enable_int64, false);
KernelCreatePtrFn kernel_create_fn = [](FuncManager&, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out) -> Status {
out = std::make_unique<ReduceSum>(info);
Expand All @@ -90,18 +88,14 @@ KernelCreateInfo CreateReduceSumKernelInfo(bool enable_int64) {
return {KernelDefBuilder()
.SetName("ReduceSum")
.SetDomain(kOnnxDomain)
.SinceVersion(SinceVersion)
.SinceVersion(since_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T", type_constraints)
.InputMemoryType(OrtMemTypeCPUInput, 1)
.Build(),
kernel_create_fn};
}

template KernelCreateInfo CreateReduceSumVersionedKernelInfo<1, 10>(bool);
template KernelCreateInfo CreateReduceSumVersionedKernelInfo<11, 12>(bool);
template KernelCreateInfo CreateReduceSumKernelInfo<13>(bool);

REGISTER_REDUCE_VERSIONED_KERNEL(ReduceProd, 1, 10);
REGISTER_REDUCE_VERSIONED_KERNEL(ReduceProd, 11, 12);
REGISTER_REDUCE_VERSIONED_KERNEL(ReduceProd, 13, 17);
Expand Down
6 changes: 2 additions & 4 deletions onnxruntime/core/providers/webgpu/reduction/reduction_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,8 @@ class ArgMax final : public ReduceKernel<false> {
};

// Factory functions for ReduceSum with conditional int64 support (registered via RegisterKernels).
template <int StartVersion, int EndVersion>
KernelCreateInfo CreateReduceSumVersionedKernelInfo(bool enable_int64);
template <int SinceVersion>
KernelCreateInfo CreateReduceSumKernelInfo(bool enable_int64);
KernelCreateInfo CreateReduceSumVersionedKernelInfo(int start_version, int end_version, bool enable_int64);
KernelCreateInfo CreateReduceSumKernelInfo(int since_version, bool enable_int64);

} // namespace webgpu
} // namespace onnxruntime
89 changes: 44 additions & 45 deletions onnxruntime/core/providers/webgpu/tensor/cast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,58 +199,57 @@
return Status::OK();
}

template <int StartVersion, int EndVersion>
KernelCreateInfo CreateCastKernelInfo(bool enable_int64) {
// Casting to int64 is always supported. Casting *from* int64 (int64 in T1/input) stays guarded by enable_int64.
namespace {
// Casting to int64 is always supported. Casting *from* int64 (int64 in T1/input) stays guarded by enable_int64.
// T1 (input): plus uint8, so casts *from* a uint8 tensor (to int32/float/bool/etc.) run on the
// WebGPU EP instead of falling back. Reading uint8 input unpacks the packed Uint8x4 storage via
// GetByOffset.
std::vector<MLDataType> GetCastT1TypeConstraints(bool enable_int64) {
std::vector<MLDataType> t1_constraints = GetOpTypeConstraints(/*enable_int64=*/enable_int64, /*enable_bool=*/true);
// T1 (input): plus uint8, so casts *from* a uint8 tensor (to int32/float/bool/etc.) run on the
// WebGPU EP instead of falling back. Reading uint8 input unpacks the packed Uint8x4 storage via
// GetByOffset.
t1_constraints.push_back(DataTypeImpl::GetTensorType<uint8_t>());
// T2 (output): the int64+bool set, plus uint8 so the WebGPU EP can produce uint8 output directly
// (e.g. a terminal bool->uint8 cast at a graph output) instead of falling back. Casting *to* uint8
// packs via the Uint8x4 SetByOffset.
return t1_constraints;
}

// T2 (output): the int64+bool set, plus uint8 so the WebGPU EP can produce uint8 output directly
// (e.g. a terminal bool->uint8 cast at a graph output) instead of falling back. Casting *to* uint8
// packs via the Uint8x4 SetByOffset.
std::vector<MLDataType> GetCastT2TypeConstraints() {
std::vector<MLDataType> t2_constraints = GetOpTypeConstraints(/*enable_int64=*/true, /*enable_bool=*/true);
t2_constraints.push_back(DataTypeImpl::GetTensorType<uint8_t>());
return t2_constraints;
}

KernelCreatePtrFn kernel_create_fn = [](FuncManager&, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out) -> Status {
out = std::make_unique<Cast>(info);
return Status::OK();
};

if constexpr (StartVersion == EndVersion) {
return {
KernelDefBuilder()
.SetName("Cast")
.SetDomain(kOnnxDomain)
.SinceVersion(StartVersion)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T1", t1_constraints)
.TypeConstraint("T2", t2_constraints)
.Build(),
kernel_create_fn};
} else {
return {
KernelDefBuilder()
.SetName("Cast")
.SetDomain(kOnnxDomain)
.SinceVersion(StartVersion, EndVersion)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T1", t1_constraints)
.TypeConstraint("T2", t2_constraints)
.Build(),
kernel_create_fn};
}
Status CreateCastKernel(FuncManager&, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out) {
out = std::make_unique<Cast>(info);

Check warning on line 223 in onnxruntime/core/providers/webgpu/tensor/cast.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <memory> for make_unique<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/webgpu/tensor/cast.cc:223: Add #include <memory> for make_unique<> [build/include_what_you_use] [4]
return Status::OK();
}
} // namespace

KernelCreateInfo CreateCastVersionedKernelInfo(int start_version, int end_version, bool enable_int64) {
return {
KernelDefBuilder()
.SetName("Cast")
.SetDomain(kOnnxDomain)
.SinceVersion(start_version, end_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T1", GetCastT1TypeConstraints(enable_int64))
.TypeConstraint("T2", GetCastT2TypeConstraints())
.Build(),
CreateCastKernel};
}

// Explicit template instantiations
template KernelCreateInfo CreateCastKernelInfo<6, 8>(bool);
template KernelCreateInfo CreateCastKernelInfo<9, 12>(bool);
template KernelCreateInfo CreateCastKernelInfo<13, 18>(bool);
template KernelCreateInfo CreateCastKernelInfo<19, 20>(bool);
template KernelCreateInfo CreateCastKernelInfo<21, 22>(bool);
template KernelCreateInfo CreateCastKernelInfo<23, 23>(bool);
template KernelCreateInfo CreateCastKernelInfo<24>(bool);
KernelCreateInfo CreateCastKernelInfo(int since_version, bool enable_int64) {
return {
KernelDefBuilder()
.SetName("Cast")
.SetDomain(kOnnxDomain)
.SinceVersion(since_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T1", GetCastT1TypeConstraints(enable_int64))
.TypeConstraint("T2", GetCastT2TypeConstraints())
.Build(),
CreateCastKernel};
}

} // namespace webgpu
} // namespace onnxruntime
6 changes: 3 additions & 3 deletions onnxruntime/core/providers/webgpu/tensor/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class Cast final : public WebGpuKernel {
int32_t to_;
};

// Create Cast kernel info with appropriate type constraints based on int64 support
template <int StartVersion, int EndVersion = StartVersion>
KernelCreateInfo CreateCastKernelInfo(bool enable_int64);
// Create Cast kernel info with appropriate type constraints based on int64 support.
KernelCreateInfo CreateCastVersionedKernelInfo(int start_version, int end_version, bool enable_int64);
KernelCreateInfo CreateCastKernelInfo(int since_version, bool enable_int64);

} // namespace webgpu
} // namespace onnxruntime
16 changes: 4 additions & 12 deletions onnxruntime/core/providers/webgpu/tensor/concat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace webgpu {
// so enabling int64 is safe. int64 (stored as vec2<u32>) is copied losslessly via the raw
// storage-word path in AppendAssignOutputDataFunction, preserving the full 64-bit value instead of
// the truncating i32 value type used by arithmetic kernels.
template <int StartVersion, int EndVersion>
KernelCreateInfo CreateConcatVersionedKernelInfo(bool enable_int64) {
KernelCreateInfo CreateConcatVersionedKernelInfo(int start_version, int end_version, bool enable_int64) {
std::vector<MLDataType> type_constraints = GetOpTypeConstraints(enable_int64, /*enable_bool=*/false);

KernelCreatePtrFn kernel_create_fn = [](FuncManager&, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out) -> Status {
Expand All @@ -30,15 +29,14 @@ KernelCreateInfo CreateConcatVersionedKernelInfo(bool enable_int64) {
KernelDefBuilder()
.SetName("Concat")
.SetDomain(kOnnxDomain)
.SinceVersion(StartVersion, EndVersion)
.SinceVersion(start_version, end_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T", std::move(type_constraints))
.Build(),
kernel_create_fn};
}

template <int SinceVersion>
KernelCreateInfo CreateConcatKernelInfo(bool enable_int64) {
KernelCreateInfo CreateConcatKernelInfo(int since_version, bool enable_int64) {
std::vector<MLDataType> type_constraints = GetOpTypeConstraints(enable_int64, /*enable_bool=*/false);

KernelCreatePtrFn kernel_create_fn = [](FuncManager&, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out) -> Status {
Expand All @@ -50,19 +48,13 @@ KernelCreateInfo CreateConcatKernelInfo(bool enable_int64) {
KernelDefBuilder()
.SetName("Concat")
.SetDomain(kOnnxDomain)
.SinceVersion(SinceVersion)
.SinceVersion(since_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T", std::move(type_constraints))
.Build(),
kernel_create_fn};
}

// Explicit template instantiations
template KernelCreateInfo CreateConcatVersionedKernelInfo<1, 3>(bool);
template KernelCreateInfo CreateConcatVersionedKernelInfo<4, 10>(bool);
template KernelCreateInfo CreateConcatVersionedKernelInfo<11, 12>(bool);
template KernelCreateInfo CreateConcatKernelInfo<13>(bool);

void AppendCalculateInputIndexFunction(OStringStream& os, size_t input_count) {
os << "fn calculate_input_index(global_idx: u32) -> u32 {\n"
<< " for (var i = 1u; i < " << input_count << "; i = i + 1u) {\n"
Expand Down
6 changes: 2 additions & 4 deletions onnxruntime/core/providers/webgpu/tensor/concat.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class Concat final : public WebGpuKernel, public ConcatBase {
};

// Create Concat kernel info with appropriate type constraints based on int64 support
template <int StartVersion, int EndVersion>
KernelCreateInfo CreateConcatVersionedKernelInfo(bool enable_int64);
template <int SinceVersion>
KernelCreateInfo CreateConcatKernelInfo(bool enable_int64);
KernelCreateInfo CreateConcatVersionedKernelInfo(int start_version, int end_version, bool enable_int64);
KernelCreateInfo CreateConcatKernelInfo(int since_version, bool enable_int64);

} // namespace webgpu
} // namespace onnxruntime
14 changes: 4 additions & 10 deletions onnxruntime/core/providers/webgpu/tensor/expand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ Status Expand::ComputeInternal(ComputeContext& context) const {
return context.RunProgram(program);
}

template <int StartVersion, int EndVersion>
KernelCreateInfo CreateExpandVersionedKernelInfo(bool enable_int64) {
KernelCreateInfo CreateExpandVersionedKernelInfo(int start_version, int end_version, bool enable_int64) {
std::vector<MLDataType> type_constraints = GetOpTypeConstraints(enable_int64, true);
type_constraints.push_back(DataTypeImpl::GetTensorType<uint8_t>());

Expand All @@ -154,16 +153,15 @@ KernelCreateInfo CreateExpandVersionedKernelInfo(bool enable_int64) {
KernelDefBuilder()
.SetName("Expand")
.SetDomain(kOnnxDomain)
.SinceVersion(StartVersion, EndVersion)
.SinceVersion(start_version, end_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T", type_constraints)
.InputMemoryType(OrtMemTypeCPU, 1)
.Build(),
kernel_create_fn};
}

template <int SinceVersion>
KernelCreateInfo CreateExpandKernelInfo(bool enable_int64) {
KernelCreateInfo CreateExpandKernelInfo(int since_version, bool enable_int64) {
std::vector<MLDataType> type_constraints = GetOpTypeConstraints(enable_int64, true);
type_constraints.push_back(DataTypeImpl::GetTensorType<uint8_t>());

Expand All @@ -176,17 +174,13 @@ KernelCreateInfo CreateExpandKernelInfo(bool enable_int64) {
KernelDefBuilder()
.SetName("Expand")
.SetDomain(kOnnxDomain)
.SinceVersion(SinceVersion)
.SinceVersion(since_version)
.Provider(kWebGpuExecutionProvider)
.TypeConstraint("T", type_constraints)
.InputMemoryType(OrtMemTypeCPU, 1)
.Build(),
kernel_create_fn};
}

// Explicit template instantiations
template KernelCreateInfo CreateExpandVersionedKernelInfo<8, 12>(bool);
template KernelCreateInfo CreateExpandKernelInfo<13>(bool);

} // namespace webgpu
} // namespace onnxruntime
6 changes: 2 additions & 4 deletions onnxruntime/core/providers/webgpu/tensor/expand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class Expand final : public WebGpuKernel {
};

// Create Expand kernel info with appropriate type constraints based on int64 support
template <int StartVersion, int EndVersion>
KernelCreateInfo CreateExpandVersionedKernelInfo(bool enable_int64);
template <int SinceVersion>
KernelCreateInfo CreateExpandKernelInfo(bool enable_int64);
KernelCreateInfo CreateExpandVersionedKernelInfo(int start_version, int end_version, bool enable_int64);
KernelCreateInfo CreateExpandKernelInfo(int since_version, bool enable_int64);

} // namespace webgpu
} // namespace onnxruntime
Loading
Loading