onnxruntime
ee9440b6 - [WebGPU] Add int32 support to Relu opset 14 (#33789)

Commit
5 days ago
[WebGPU] Add int32 support to Relu opset 14 (#33789) ### Description <!-- Describe your changes. --> Adds int32 support to the WebGPU EP `Relu` kernel for opset 14+. - `onnxruntime/core/providers/webgpu/math/unary_elementwise_ops.cc`: the `Relu` opset 14 kernel now uses the existing `SignedNumberTypes()` helper (float, float16, int32) instead of `WebGpuSupportedFloatTypes()`. Opsets 6-12 and 13 stay float-only because ONNX added the integer types in Relu-14. The shader is unchanged: `select(x_value_t(0), a, a > x_value_t(0))` is valid WGSL for `vec4<i32>`. - `onnxruntime/test/providers/webgpu/activation/activation_op_test.cc`: new `WebGpuActivationTest.Relu_Int32_Opset14_WebGpu`. It runs on the WebGPU EP only with `kOrtSessionOptionsDisableCPUEPFallback=1`, so a missing kernel fails the test instead of silently running on CPU (the CPU EP does register int32 Relu-14). It covers `INT32_MIN`, `-1`, `0`, `1` and `INT32_MAX` with shape `{7}` (partial trailing vec4) and `{1, 2, 2, 2}` (full vec4s). It skips before constructing `OpTester` when the WebGPU EP is unavailable. Out of scope: int8 and int64 Relu, which WGSL does not support natively. #### Validation Built with the WebGPU EP from a local, unpushed merge of this commit and a separate WebGPU Gather commit into `main` (121e34d92b). - `onnxruntime_provider_test --gtest_filter="WebGpuActivationTest.*:ActivationOpTest.Relu*:GatherOpTest.*:CastOpTest.*:GatherElementsOpTest.*:GatherNDOpTest.*"`: **passed**, 268/268 with 0 skipped. This includes `WebGpuActivationTest.Relu_Int32_Opset14_WebGpu`. - Negative check: with the Relu-14 registration reverted to `WebGpuSupportedFloatTypes()`, `WebGpuActivationTest.Relu_Int32_Opset14_WebGpu` **fails** at session init with "fallback to CPU EP has been explicitly disabled". This confirms the test catches a missing WebGPU kernel. - `lintrunner -a` and clang-format 20.1.8 on the changed files: no issues. - WPT `webnn/conformance_tests/relu.https.any.js?gpu`: **16/18 passed**, up from 15/18 before. "relu int32 4D tensor" now passes. The 2 remaining failures are the optional int8 and int64 subtests, which are out of scope. Tested with the WebGPU plugin EP built from `main` 121e34d92b plus this PR and the Gather int8 PR (local merge `5c68bbb9f9`), Edge Canary 159.0.4372.0, NVIDIA RTX Spark N1X on D3D12, and ORT runtime 1.28.3. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> The W3C WebNN WPT subtest `webnn/conformance_tests/relu.https.any.js` "relu int32 4D tensor" failed on the WebGPU EP with "Failed to build graph". WebNN disables CPU fallback, and WebGPU `Relu` had no int32 kernel, so the node was assigned to CPU and session creation failed. Co-authored-by: Aditya Rastogi <adityar@ntdev.microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Author
Parents
Loading