sync 2e7068faf55e
Browse files- README.md +57 -0
- build/webgpu/bench.json +57 -0
- build/webgpu/manifest.json +80 -0
- build/webgpu/metadata.json +19 -0
- build/webgpu/test.json +148 -0
- build/webgpu/unary-scalar.wgsl.jinja +26 -0
- build/webgpu/unary-vec4.wgsl.jinja +19 -0
README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
library_name: kernels
|
| 3 |
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- kernel
|
| 6 |
+
- webgpu
|
| 7 |
+
- wgsl
|
| 8 |
---
|
| 9 |
+
# ai.onnx.Exp
|
| 10 |
+
|
| 11 |
+
`ai.onnx` · standard ONNX operator · ONNX opset ≥ 13
|
| 12 |
+
|
| 13 |
+
## Description
|
| 14 |
+
|
| 15 |
+
Computes `exp(x)` elementwise for every element of the input tensor. The output has the same shape and type as the input.
|
| 16 |
+
|
| 17 |
+
See the [ONNX `Exp` spec](https://onnx.ai/onnx/operators/onnx__Exp.html) for the reference semantics.
|
| 18 |
+
|
| 19 |
+
## Inputs
|
| 20 |
+
|
| 21 |
+
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|
| 22 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 23 |
+
| `input` | `x` | `T` | — | — | Values used as exponents of `e` in the elementwise exponential. | required |
|
| 24 |
+
|
| 25 |
+
## Outputs
|
| 26 |
+
|
| 27 |
+
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|
| 28 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 29 |
+
| `output` | `y` | `T` | same as `input` | same as `input` | Output tensor containing the elementwise exponential of the input. | required |
|
| 30 |
+
|
| 31 |
+
## Type constraints
|
| 32 |
+
|
| 33 |
+
| Variable | Allowed dtypes |
|
| 34 |
+
| --- | --- |
|
| 35 |
+
| `T` | `float32`, `float16` |
|
| 36 |
+
|
| 37 |
+
## Files
|
| 38 |
+
|
| 39 |
+
- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)
|
| 40 |
+
- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
|
| 41 |
+
- [`test.json`](build/webgpu/test.json) — correctness cases
|
| 42 |
+
- [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
|
| 43 |
+
- [`unary-scalar.wgsl.jinja`](build/webgpu/unary-scalar.wgsl.jinja)
|
| 44 |
+
- [`unary-vec4.wgsl.jinja`](build/webgpu/unary-vec4.wgsl.jinja)
|
| 45 |
+
|
| 46 |
+
## Use with `@huggingface/kernels`
|
| 47 |
+
|
| 48 |
+
The loader derives every required output's shape and logical dtype from the manifest contract and this call.
|
| 49 |
+
It then allocates the result tensors automatically.
|
| 50 |
+
|
| 51 |
+
The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
|
| 52 |
+
|
| 53 |
+
Replace each `*Data` placeholder with a typed array containing the corresponding input data.
|
| 54 |
+
|
| 55 |
+
```js
|
| 56 |
+
import { getKernel } from "@huggingface/kernels";
|
| 57 |
+
|
| 58 |
+
const kernel = await getKernel("webgpu-kernels/ai.onnx.Exp", { version: 1 });
|
| 59 |
+
const { y } = await kernel({ x: { data: xData, shape: [] } });
|
| 60 |
+
```
|
build/webgpu/bench.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Exp",
|
| 3 |
+
"tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] },
|
| 4 |
+
"cases": [
|
| 5 |
+
{
|
| 6 |
+
"name": "exp-f32-1m",
|
| 7 |
+
"preset": "smoke",
|
| 8 |
+
"vars": { "dtype": "float32", "count": 1048576 },
|
| 9 |
+
"inputs": { "x": { "shape": [1048576], "dtype": "float32", "dist": "normal", "seed": 620, "scale": 0.1 } },
|
| 10 |
+
"outputs": { "y": { "shape": [1048576], "dtype": "float32" } },
|
| 11 |
+
"bench": {
|
| 12 |
+
"primary": true,
|
| 13 |
+
"metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }]
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"name": "exp-f32-8m",
|
| 18 |
+
"preset": "smoke",
|
| 19 |
+
"vars": { "dtype": "float32", "count": 8388608 },
|
| 20 |
+
"inputs": { "x": { "shape": [8388608], "dtype": "float32", "seed": 7009, "dist": "normal", "scale": 0.1 } },
|
| 21 |
+
"outputs": { "y": { "shape": [8388608], "dtype": "float32" } },
|
| 22 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"name": "exp-f32-16m",
|
| 26 |
+
"preset": "smoke",
|
| 27 |
+
"vars": { "dtype": "float32", "count": 16777216 },
|
| 28 |
+
"inputs": { "x": { "shape": [16777216], "dtype": "float32", "seed": 7011, "dist": "normal", "scale": 0.1 } },
|
| 29 |
+
"outputs": { "y": { "shape": [16777216], "dtype": "float32" } },
|
| 30 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"name": "exp-f16-8m",
|
| 34 |
+
"preset": "smoke",
|
| 35 |
+
"vars": { "dtype": "float16", "count": 8388608 },
|
| 36 |
+
"inputs": { "x": { "shape": [8388608], "dtype": "float16", "seed": 7010, "dist": "normal", "scale": 0.1 } },
|
| 37 |
+
"outputs": { "y": { "shape": [8388608], "dtype": "float16" } },
|
| 38 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"name": "exp-f32-1m-plus-1-scalar",
|
| 42 |
+
"preset": "smoke",
|
| 43 |
+
"vars": { "dtype": "float32", "count": 1048577 },
|
| 44 |
+
"inputs": { "x": { "shape": [1048577], "dtype": "float32", "dist": "normal", "seed": 621, "scale": 0.1 } },
|
| 45 |
+
"outputs": { "y": { "shape": [1048577], "dtype": "float32" } },
|
| 46 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"name": "exp-f16-1m-plus-1-scalar",
|
| 50 |
+
"preset": "smoke",
|
| 51 |
+
"vars": { "dtype": "float16", "count": 1048577 },
|
| 52 |
+
"inputs": { "x": { "shape": [1048577], "dtype": "float16", "dist": "normal", "seed": 622, "scale": 0.1 } },
|
| 53 |
+
"outputs": { "y": { "shape": [1048577], "dtype": "float16" } },
|
| 54 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 55 |
+
}
|
| 56 |
+
]
|
| 57 |
+
}
|
build/webgpu/manifest.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"domain": "ai.onnx",
|
| 3 |
+
"name": "Exp",
|
| 4 |
+
"sinceVersion": 13,
|
| 5 |
+
"description": "Computes `exp(x)` elementwise for every element of the input tensor. The output has the same shape and type as the input.",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{ "role": "input", "dtype": "T", "description": "Values used as exponents of `e` in the elementwise exponential." }
|
| 8 |
+
],
|
| 9 |
+
"outputs": [
|
| 10 |
+
{
|
| 11 |
+
"role": "output",
|
| 12 |
+
"dtype": "T",
|
| 13 |
+
"rank": "ranks.input",
|
| 14 |
+
"description": "Output tensor containing the elementwise exponential of the input.",
|
| 15 |
+
"shape": "shapes.input"
|
| 16 |
+
}
|
| 17 |
+
],
|
| 18 |
+
"typeConstraints": { "T": ["float32", "float16"] },
|
| 19 |
+
"args": {
|
| 20 |
+
"x": { "kind": "tensor", "semantic": "input", "role": "input" },
|
| 21 |
+
"y": { "kind": "tensor", "semantic": "output", "role": "output" }
|
| 22 |
+
},
|
| 23 |
+
"tunables": { "WORKGROUP_SIZE": 256 },
|
| 24 |
+
"variants": [
|
| 25 |
+
{
|
| 26 |
+
"id": "same_layout_vec4",
|
| 27 |
+
"when": ["numel(shapes.x) > 0", "numel(shapes.x) % 4 == 0", "numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)"],
|
| 28 |
+
"constants": {
|
| 29 |
+
"scalar": "dtypes.T",
|
| 30 |
+
"usesF16": "dtypes.T == \"f16\"",
|
| 31 |
+
"vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\""
|
| 32 |
+
},
|
| 33 |
+
"passes": [
|
| 34 |
+
{
|
| 35 |
+
"id": "main",
|
| 36 |
+
"name": "Exp.vec4",
|
| 37 |
+
"source": { "shader": "unary-vec4.wgsl.jinja", "inputs": { "op": "\"exp\"" } },
|
| 38 |
+
"bindings": [
|
| 39 |
+
{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" },
|
| 40 |
+
{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" },
|
| 41 |
+
{
|
| 42 |
+
"name": "params",
|
| 43 |
+
"semantic": "kernel.params",
|
| 44 |
+
"buffer": { "type": "uniform" },
|
| 45 |
+
"struct": {
|
| 46 |
+
"name": "Params",
|
| 47 |
+
"fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.y) / 4" }]
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
],
|
| 51 |
+
"dispatch": { "threads": "numel(shapes.y) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 52 |
+
}
|
| 53 |
+
],
|
| 54 |
+
"priority": 20
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"id": "scalar",
|
| 58 |
+
"when": ["numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)"],
|
| 59 |
+
"constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" },
|
| 60 |
+
"passes": [
|
| 61 |
+
{
|
| 62 |
+
"id": "main",
|
| 63 |
+
"name": "Exp",
|
| 64 |
+
"source": { "shader": "unary-scalar.wgsl.jinja", "inputs": { "op": "\"exp\"", "itemsPerInvocation": 4 } },
|
| 65 |
+
"bindings": [
|
| 66 |
+
{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" },
|
| 67 |
+
{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$scalar" },
|
| 68 |
+
{
|
| 69 |
+
"name": "params",
|
| 70 |
+
"semantic": "kernel.params",
|
| 71 |
+
"buffer": { "type": "uniform" },
|
| 72 |
+
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.y)" }] }
|
| 73 |
+
}
|
| 74 |
+
],
|
| 75 |
+
"dispatch": { "threads": "ceilDiv(numel(shapes.y), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 76 |
+
}
|
| 77 |
+
]
|
| 78 |
+
}
|
| 79 |
+
]
|
| 80 |
+
}
|
build/webgpu/metadata.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ai.onnx.Exp",
|
| 3 |
+
"id": "_ai_onnx_exp_webgpu_0a43009",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"backend": { "type": "webgpu" },
|
| 7 |
+
"digest": {
|
| 8 |
+
"algorithm": "sha256",
|
| 9 |
+
"files": {
|
| 10 |
+
"bench.json": "bDB6nvxDbLKgaCODtOOts1Z5Su/8+vP35e5KDn56fiU=",
|
| 11 |
+
"manifest.json": "+4WWeMreaihmDLYJv9k+qzTgio5ykz3P4qtbSn2avhc=",
|
| 12 |
+
"test.json": "AqFvYeLz6IF603TGdetqW4JAhc09e4kCQ+uK0R8Rhgs=",
|
| 13 |
+
"unary-scalar.wgsl.jinja": "xFU7bx8sOm0IUqpXX3/rL2fkyv/b1e0ej/74VFwlLCw=",
|
| 14 |
+
"unary-vec4.wgsl.jinja": "XSKLHhqloVC3wytaLx7c1GObxRF4CEG7GmVdu4UnAWM="
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
|
| 18 |
+
"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.Exp" }
|
| 19 |
+
}
|
build/webgpu/test.json
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Exp",
|
| 3 |
+
"cases": [
|
| 4 |
+
{
|
| 5 |
+
"name": "vector",
|
| 6 |
+
"inputs": {
|
| 7 |
+
"x": {
|
| 8 |
+
"dtype": "float32",
|
| 9 |
+
"shape": [32],
|
| 10 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.1, "cosStep": 0.2, "scale": 0.1 }
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
+
"outputs": { "y": { "dtype": "float32", "shape": [32], "tolerance": 0.000001 } }
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"name": "rank0_scalar",
|
| 17 |
+
"inputs": { "x": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [1.25] } } },
|
| 18 |
+
"outputs": { "y": { "dtype": "float32", "shape": [], "tolerance": 0.000001 } }
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"name": "overflow_and_special_values",
|
| 22 |
+
"inputs": {
|
| 23 |
+
"x": {
|
| 24 |
+
"dtype": "float32",
|
| 25 |
+
"shape": [6],
|
| 26 |
+
"data": { "kind": "values", "values": [100.0, -100.0, "Infinity", "-Infinity", "NaN", 0.0] }
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
"outputs": { "y": { "dtype": "float32", "shape": [6], "tolerance": 0.000001, "allowNaN": true } }
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "f32_subnormal_underflow_tail_gpu_gap",
|
| 33 |
+
"skipGpu": {
|
| 34 |
+
"category": "permanent",
|
| 35 |
+
"reason": "Portable WGSL floating-point semantics do not guarantee preservation of the subnormal values required by this fixture. Backend evidence: WebGPU/Metal flushes subnormals to zero (f32 and f16); the kernel cannot preserve denormal inputs/outputs bit-exactly."
|
| 36 |
+
},
|
| 37 |
+
"provenance": {
|
| 38 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 39 |
+
"test": "MathOpTest.Exp_float",
|
| 40 |
+
"notes": "exp(-90..-100) is subnormal but nonzero in float32; flushing the tail to zero loses valid probability mass."
|
| 41 |
+
},
|
| 42 |
+
"inputs": {
|
| 43 |
+
"x": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [-88.0, -90.0, -95.0, -100.0] } }
|
| 44 |
+
},
|
| 45 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 1e-45 } }
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "f32_subnormal_underflow_tail_scalar_gpu_gap",
|
| 49 |
+
"skipGpu": {
|
| 50 |
+
"category": "permanent",
|
| 51 |
+
"reason": "Portable WGSL floating-point semantics do not guarantee preservation of the subnormal values required by this fixture. Backend evidence: WebGPU/Metal flushes subnormals to zero (f32 and f16); the kernel cannot preserve denormal inputs/outputs bit-exactly."
|
| 52 |
+
},
|
| 53 |
+
"provenance": {
|
| 54 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 55 |
+
"test": "MathOpTest.Exp_float",
|
| 56 |
+
"notes": "Scalar-path companion: exp of large negative finite inputs can produce valid nonzero subnormal outputs."
|
| 57 |
+
},
|
| 58 |
+
"inputs": {
|
| 59 |
+
"x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-90.0, -95.0, -100.0] } }
|
| 60 |
+
},
|
| 61 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 1e-45 } }
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"name": "f16_values",
|
| 65 |
+
"inputs": {
|
| 66 |
+
"x": { "dtype": "float16", "shape": [5], "data": { "kind": "values", "values": [-5.0, -1.0, 0.0, 1.0, 5.0] } }
|
| 67 |
+
},
|
| 68 |
+
"outputs": { "y": { "dtype": "float16", "shape": [5], "tolerance": 0.05 } }
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"name": "f32_near_overflow_boundary",
|
| 72 |
+
"inputs": {
|
| 73 |
+
"x": {
|
| 74 |
+
"dtype": "float32",
|
| 75 |
+
"shape": [5],
|
| 76 |
+
"data": { "kind": "values", "values": [80.0, 87.0, 88.0, 88.5, 89.0] }
|
| 77 |
+
}
|
| 78 |
+
},
|
| 79 |
+
"outputs": { "y": { "dtype": "float32", "shape": [5] } }
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"name": "ort_float_2x2",
|
| 83 |
+
"provenance": {
|
| 84 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 85 |
+
"test": "MathOpTest.Exp_float"
|
| 86 |
+
},
|
| 87 |
+
"inputs": {
|
| 88 |
+
"x": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [0.0, 1.0, 2.0, 10.0] } }
|
| 89 |
+
},
|
| 90 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 2], "tolerance": 0.003 } }
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"name": "ort_float16_2x2_projection",
|
| 94 |
+
"provenance": {
|
| 95 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 96 |
+
"test": "MathOpTest.Exp_float",
|
| 97 |
+
"notes": "Float16 projection of ORT's float Exp node values."
|
| 98 |
+
},
|
| 99 |
+
"inputs": {
|
| 100 |
+
"x": { "dtype": "float16", "shape": [2, 2], "data": { "kind": "values", "values": [0.0, 1.0, 2.0, 10.0] } }
|
| 101 |
+
},
|
| 102 |
+
"outputs": { "y": { "dtype": "float16", "shape": [2, 2], "relTolerance": 0.002 } }
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"name": "onnx_backend_example",
|
| 106 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_exp_example" },
|
| 107 |
+
"inputs": { "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-1.0, 0.0, 1.0] } } },
|
| 108 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.000001 } }
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"name": "onnx_backend_exp",
|
| 112 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_exp" },
|
| 113 |
+
"inputs": {
|
| 114 |
+
"x": {
|
| 115 |
+
"dtype": "float32",
|
| 116 |
+
"shape": [3, 4, 5],
|
| 117 |
+
"data": {
|
| 118 |
+
"kind": "values",
|
| 119 |
+
"values": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, -0.9772778749465942, 0.9500884413719177, -0.15135720372200012, -0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, -0.2051582634449005, 0.3130677044391632, -0.8540957570075989, -2.5529897212982178, 0.653618574142456, 0.8644362092018127, -0.7421650290489197, 2.269754648208618, -1.4543657302856445, 0.04575851559638977, -0.18718385696411133, 1.5327792167663574, 1.4693588018417358, 0.154947429895401, 0.37816253304481506, -0.8877857327461243, -1.980796456336975, -0.34791216254234314, 0.15634897351264954, 1.2302906513214111, 1.202379822731018, -0.38732680678367615, -0.302302747964859, -1.0485529899597168, -1.420017957687378, -1.7062702178955078, 1.950775384902954, -0.5096521973609924, -0.4380742907524109, -1.2527953386306763, 0.7774903774261475, -1.6138978004455566, -0.21274028718471527, -0.8954665660858154, 0.38690251111984253, -0.5108051300048828, -1.18063223361969, -0.02818222902715206, 0.4283318817615509, 0.06651721894741058, 0.30247190594673157, -0.6343221068382263, -0.3627411723136902]
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
},
|
| 123 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0.00001 } }
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"name": "onnx_backend_exp_example",
|
| 127 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_exp_example" },
|
| 128 |
+
"inputs": { "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-1.0, 0.0, 1.0] } } },
|
| 129 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.00001 } }
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"name": "empty_input_zero_dim",
|
| 133 |
+
"inputs": { "x": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } } },
|
| 134 |
+
"outputs": { "y": { "dtype": "float32", "shape": [0], "tolerance": 0 } }
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"name": "f16_overflow_to_infinity",
|
| 138 |
+
"inputs": {
|
| 139 |
+
"x": {
|
| 140 |
+
"dtype": "float16",
|
| 141 |
+
"shape": [8],
|
| 142 |
+
"data": { "kind": "values", "values": [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0] }
|
| 143 |
+
}
|
| 144 |
+
},
|
| 145 |
+
"outputs": { "y": { "dtype": "float16", "shape": [8], "relTolerance": 0.002 } }
|
| 146 |
+
}
|
| 147 |
+
]
|
| 148 |
+
}
|
build/webgpu/unary-scalar.wgsl.jinja
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% macro flat_tail_open() %}
|
| 2 |
+
@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
|
| 3 |
+
fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {
|
| 4 |
+
// 2D-folded flat index: gid.y carries the high bits when the element count exceeds the
|
| 5 |
+
// maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills the rest into y).
|
| 6 |
+
let invocation = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
|
| 7 |
+
// Tail-safe scalar x4 keeps vector-like dispatch density without requiring
|
| 8 |
+
// the logical tensor length (or its storage binding) to be vec4 aligned.
|
| 9 |
+
let begin = invocation * {{ source.itemsPerInvocation }}u;
|
| 10 |
+
let end = min(begin + {{ source.itemsPerInvocation }}u, params.count);
|
| 11 |
+
for (var i = begin; i < end; i = i + 1u) {
|
| 12 |
+
{%- endmacro %}
|
| 13 |
+
{% macro flat_tail_close() %}
|
| 14 |
+
}
|
| 15 |
+
{% endmacro %}
|
| 16 |
+
|
| 17 |
+
// Scalar unary fallback. Each branch retains the operation's numeric hardening,
|
| 18 |
+
// including Payne-Hanek trigonometric range reduction and NaN/overflow guards.
|
| 19 |
+
{% if usesF16 %}
|
| 20 |
+
enable f16;
|
| 21 |
+
{% endif %}
|
| 22 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 23 |
+
{{ flat_tail_open() }}
|
| 24 |
+
y[i] = {{ scalar }}(exp(f32(x[i])));
|
| 25 |
+
{{ flat_tail_close() -}}
|
| 26 |
+
}
|
build/webgpu/unary-vec4.wgsl.jinja
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Loads and stores vec4<T> (128 bits) while retaining scalar per-component
|
| 2 |
+
// arithmetic, including per-component helper calls for guard-heavy operations.
|
| 3 |
+
{% if usesF16 %}
|
| 4 |
+
enable f16;
|
| 5 |
+
{% endif %}
|
| 6 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
|
| 10 |
+
fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {
|
| 11 |
+
// 2D-folded flat index: gid.y carries the high bits when the element count exceeds the
|
| 12 |
+
// maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills the rest into y).
|
| 13 |
+
let i = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
|
| 14 |
+
if (i >= params.count) {
|
| 15 |
+
return;
|
| 16 |
+
}
|
| 17 |
+
let xv = x[i];
|
| 18 |
+
y[i] = {{ vectorScalar }}(exp(vec4<f32>(xv)));
|
| 19 |
+
}
|