sync 2e7068faf55e
Browse files- README.md +57 -0
- build/webgpu/bench.json +53 -0
- build/webgpu/manifest.json +80 -0
- build/webgpu/metadata.json +19 -0
- build/webgpu/test.json +209 -0
- build/webgpu/unary-scalar.wgsl.jinja +41 -0
- build/webgpu/unary-vec4.wgsl.jinja +34 -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.Asinh
|
| 10 |
+
|
| 11 |
+
`ai.onnx` · standard ONNX operator · ONNX opset ≥ 9
|
| 12 |
+
|
| 13 |
+
## Description
|
| 14 |
+
|
| 15 |
+
Computes the hyperbolic arcsine (`asinh`) of each element in the input tensor. The output has the same shape as the input.
|
| 16 |
+
|
| 17 |
+
See the [ONNX `Asinh` spec](https://onnx.ai/onnx/operators/onnx__Asinh.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 to map elementwise through inverse hyperbolic sine. | 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` | The hyperbolic arcsine of each input element, same shape as 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.Asinh", { version: 1 });
|
| 59 |
+
const { y } = await kernel({ x: { data: xData, shape: [3] } });
|
| 60 |
+
```
|
build/webgpu/bench.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Asinh",
|
| 3 |
+
"cases": [
|
| 4 |
+
{
|
| 5 |
+
"name": "1m_f32",
|
| 6 |
+
"inputs": { "x": { "dtype": "float32", "shape": [1048576] } },
|
| 7 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1048576] } }
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"name": "asinh-f32-1m-vec4",
|
| 11 |
+
"preset": "smoke",
|
| 12 |
+
"vars": { "dtype": "float32", "count": 1048576 },
|
| 13 |
+
"inputs": {
|
| 14 |
+
"x": { "shape": [1048576], "dtype": "float32", "dist": "uniform", "seed": 911, "scale": 20, "offset": -10 }
|
| 15 |
+
},
|
| 16 |
+
"outputs": { "y": { "shape": [1048576], "dtype": "float32" } },
|
| 17 |
+
"bench": {
|
| 18 |
+
"primary": true,
|
| 19 |
+
"metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }]
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"name": "asinh-f32-1m-minus-1-scalar-fallback",
|
| 24 |
+
"preset": "smoke",
|
| 25 |
+
"vars": { "dtype": "float32", "count": 1048575 },
|
| 26 |
+
"inputs": {
|
| 27 |
+
"x": { "shape": [1048575], "dtype": "float32", "dist": "uniform", "seed": 912, "scale": 20, "offset": -10 }
|
| 28 |
+
},
|
| 29 |
+
"outputs": { "y": { "shape": [1048575], "dtype": "float32" } },
|
| 30 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"name": "asinh-f16-1m-vec4",
|
| 34 |
+
"preset": "smoke",
|
| 35 |
+
"vars": { "dtype": "float16", "count": 1048576 },
|
| 36 |
+
"inputs": {
|
| 37 |
+
"x": { "shape": [1048576], "dtype": "float16", "dist": "uniform", "seed": 913, "scale": 20, "offset": -10 }
|
| 38 |
+
},
|
| 39 |
+
"outputs": { "y": { "shape": [1048576], "dtype": "float16" } },
|
| 40 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"name": "asinh-f16-1m-minus-1-scalar-fallback",
|
| 44 |
+
"preset": "smoke",
|
| 45 |
+
"vars": { "dtype": "float16", "count": 1048575 },
|
| 46 |
+
"inputs": {
|
| 47 |
+
"x": { "shape": [1048575], "dtype": "float16", "dist": "uniform", "seed": 914, "scale": 20, "offset": -10 }
|
| 48 |
+
},
|
| 49 |
+
"outputs": { "y": { "shape": [1048575], "dtype": "float16" } },
|
| 50 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 51 |
+
}
|
| 52 |
+
]
|
| 53 |
+
}
|
build/webgpu/manifest.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"domain": "ai.onnx",
|
| 3 |
+
"name": "Asinh",
|
| 4 |
+
"sinceVersion": 9,
|
| 5 |
+
"description": "Computes the hyperbolic arcsine (`asinh`) of each element in the input tensor. The output has the same shape as the input.",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{ "role": "input", "dtype": "T", "description": "Values to map elementwise through inverse hyperbolic sine." }
|
| 8 |
+
],
|
| 9 |
+
"outputs": [
|
| 10 |
+
{
|
| 11 |
+
"role": "output",
|
| 12 |
+
"dtype": "T",
|
| 13 |
+
"rank": "ranks.input",
|
| 14 |
+
"description": "The hyperbolic arcsine of each input element, same shape as 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": "Asinh.vec4",
|
| 37 |
+
"source": { "shader": "unary-vec4.wgsl.jinja", "inputs": { "op": "\"asinh\"" } },
|
| 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": "elementwise",
|
| 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": "Asinh",
|
| 64 |
+
"source": { "shader": "unary-scalar.wgsl.jinja", "inputs": { "op": "\"asinh\"", "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.Asinh",
|
| 3 |
+
"id": "_ai_onnx_asinh_webgpu_a503438",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"backend": { "type": "webgpu" },
|
| 7 |
+
"digest": {
|
| 8 |
+
"algorithm": "sha256",
|
| 9 |
+
"files": {
|
| 10 |
+
"bench.json": "UW3ydjAwtJ6/U0sBoKtbFqtbwYgZfSSu7LuQs6VApTE=",
|
| 11 |
+
"manifest.json": "/3bRWF5ZfvXDNsa8jL5H5Q47aMtB735wo54xo5avPxM=",
|
| 12 |
+
"test.json": "3PxMi6OpSAIMhT+AZG7i1kw5jmD1uKj7ru2+snR8mBE=",
|
| 13 |
+
"unary-scalar.wgsl.jinja": "Zr4SHvEJ1w76n2vKN8vj5IrnQyIISQpUSzlsNriOAnQ=",
|
| 14 |
+
"unary-vec4.wgsl.jinja": "WSYxLj9wsnlDWUSeLwPHDn1fc0XFtaSLZxQgiaIxg98="
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
|
| 18 |
+
"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.Asinh" }
|
| 19 |
+
}
|
build/webgpu/test.json
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Asinh",
|
| 3 |
+
"cases": [
|
| 4 |
+
{
|
| 5 |
+
"name": "f32_values",
|
| 6 |
+
"inputs": {
|
| 7 |
+
"x": {
|
| 8 |
+
"dtype": "float32",
|
| 9 |
+
"shape": [6],
|
| 10 |
+
"data": { "kind": "values", "values": [-4.0, -1.0, 0.0, 0.5, 1.0, 4.0] }
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
+
"outputs": { "y": { "dtype": "float32", "shape": [6], "tolerance": 0.000001 } }
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"name": "f32_subnormal_identity_tail_gpu_gap",
|
| 17 |
+
"skipGpu": {
|
| 18 |
+
"category": "permanent",
|
| 19 |
+
"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."
|
| 20 |
+
},
|
| 21 |
+
"provenance": {
|
| 22 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 23 |
+
"test": "MathOpTest.Asinh",
|
| 24 |
+
"notes": "For tiny finite inputs asinh(x) rounds back to x in float32; zero-flushing erases the signed tail."
|
| 25 |
+
},
|
| 26 |
+
"inputs": {
|
| 27 |
+
"x": {
|
| 28 |
+
"dtype": "float32",
|
| 29 |
+
"shape": [4],
|
| 30 |
+
"data": { "kind": "values", "values": [-1e-39, -1e-40, 1e-40, 1e-39] }
|
| 31 |
+
}
|
| 32 |
+
},
|
| 33 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 0 } }
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"name": "f32_subnormal_identity_tail_scalar_gpu_gap",
|
| 37 |
+
"skipGpu": {
|
| 38 |
+
"category": "permanent",
|
| 39 |
+
"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."
|
| 40 |
+
},
|
| 41 |
+
"provenance": {
|
| 42 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 43 |
+
"test": "MathOpTest.Asinh",
|
| 44 |
+
"notes": "Scalar-path companion: subnormal inputs are valid finite Asinh outputs."
|
| 45 |
+
},
|
| 46 |
+
"inputs": {
|
| 47 |
+
"x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-1e-40, 0.0, 1e-40] } }
|
| 48 |
+
},
|
| 49 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0 } }
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"name": "f16_values",
|
| 53 |
+
"inputs": {
|
| 54 |
+
"x": {
|
| 55 |
+
"dtype": "float16",
|
| 56 |
+
"shape": [2, 3],
|
| 57 |
+
"data": { "kind": "values", "values": [-4.0, -1.0, 0.0, 0.5, 1.0, 4.0] }
|
| 58 |
+
}
|
| 59 |
+
},
|
| 60 |
+
"outputs": { "y": { "dtype": "float16", "shape": [2, 3] } },
|
| 61 |
+
"tolerance": 0.002
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"name": "large_in_domain_args_no_overflow",
|
| 65 |
+
"inputs": {
|
| 66 |
+
"x": {
|
| 67 |
+
"dtype": "float32",
|
| 68 |
+
"shape": [6],
|
| 69 |
+
"data": {
|
| 70 |
+
"kind": "values",
|
| 71 |
+
"values": [10000000000.0, 100000000000000000000.0, -100000000000000000000.0, 1e+30, -1e+30, 3e+38]
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
},
|
| 75 |
+
"outputs": { "y": { "dtype": "float32", "shape": [6], "tolerance": 0.001 } }
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"name": "f32_large_magnitude_accuracy_gpu_gap",
|
| 79 |
+
"skipGpu": {
|
| 80 |
+
"category": "todo",
|
| 81 |
+
"reason": "The current f32 implementation differs from the CPU reference by about one ULP at large finite magnitudes. A higher-accuracy f32 algorithm or software-extended precision could close this implementable gap."
|
| 82 |
+
},
|
| 83 |
+
"provenance": {
|
| 84 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 85 |
+
"test": "MathOpTest.Asinh",
|
| 86 |
+
"notes": "Large finite magnitudes exercise Asinh's overflow-avoidance region; CPU and ORT agree within a tighter bound than the current WGSL builtin path."
|
| 87 |
+
},
|
| 88 |
+
"inputs": {
|
| 89 |
+
"x": {
|
| 90 |
+
"dtype": "float32",
|
| 91 |
+
"shape": [6],
|
| 92 |
+
"data": {
|
| 93 |
+
"kind": "values",
|
| 94 |
+
"values": [10000000000.0, 100000000000000000000.0, -100000000000000000000.0, 1e+30, -1e+30, 3e+38]
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
},
|
| 98 |
+
"outputs": { "y": { "dtype": "float32", "shape": [6], "tolerance": 0.000001, "relTolerance": 0 } }
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"name": "ort_float_small_range",
|
| 102 |
+
"provenance": {
|
| 103 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 104 |
+
"test": "MathOpTest.Asinh"
|
| 105 |
+
},
|
| 106 |
+
"inputs": {
|
| 107 |
+
"x": { "dtype": "float32", "shape": [5], "data": { "kind": "values", "values": [-1.0, -0.5, 0.0, 0.5, 1.0] } }
|
| 108 |
+
},
|
| 109 |
+
"outputs": { "y": { "dtype": "float32", "shape": [5], "tolerance": 0.00001 } }
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"name": "ort_nonfinite_values",
|
| 113 |
+
"provenance": {
|
| 114 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 115 |
+
"test": "MathOpTest.Asinh",
|
| 116 |
+
"notes": "Extends ORT's small-range case with signed infinities, signed zero, and NaN."
|
| 117 |
+
},
|
| 118 |
+
"inputs": {
|
| 119 |
+
"x": {
|
| 120 |
+
"dtype": "float32",
|
| 121 |
+
"shape": [7],
|
| 122 |
+
"data": { "kind": "values", "values": ["-Infinity", -1.0, 0.0, 0.0, 1.0, "Infinity", "NaN"] }
|
| 123 |
+
}
|
| 124 |
+
},
|
| 125 |
+
"outputs": { "y": { "dtype": "float32", "shape": [7], "tolerance": 0.00001, "allowNaN": true } }
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"name": "onnx_backend_example",
|
| 129 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_asinh_example" },
|
| 130 |
+
"inputs": { "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-1.0, 0.0, 1.0] } } },
|
| 131 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.000001 } }
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "onnx_backend_asinh",
|
| 135 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_asinh" },
|
| 136 |
+
"inputs": {
|
| 137 |
+
"x": {
|
| 138 |
+
"dtype": "float32",
|
| 139 |
+
"shape": [3, 4, 5],
|
| 140 |
+
"data": {
|
| 141 |
+
"kind": "values",
|
| 142 |
+
"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]
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
},
|
| 146 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0.00001 } }
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"name": "onnx_backend_asinh_example",
|
| 150 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_asinh_example" },
|
| 151 |
+
"inputs": { "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-1.0, 0.0, 1.0] } } },
|
| 152 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.00001 } }
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"name": "vec4_f16_lanes",
|
| 156 |
+
"inputs": {
|
| 157 |
+
"x": {
|
| 158 |
+
"dtype": "float16",
|
| 159 |
+
"shape": [16],
|
| 160 |
+
"data": {
|
| 161 |
+
"kind": "values",
|
| 162 |
+
"values": [-8.0, -4.0, -2.0, -1.0, -0.5, -0.25, 0.0, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 50.0, 100.0]
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
},
|
| 166 |
+
"outputs": { "y": { "dtype": "float16", "shape": [16], "tolerance": 0.001, "relTolerance": 0.002 } }
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
"name": "vec4_f32_large_magnitude_guard",
|
| 170 |
+
"inputs": {
|
| 171 |
+
"x": {
|
| 172 |
+
"dtype": "float32",
|
| 173 |
+
"shape": [4],
|
| 174 |
+
"data": {
|
| 175 |
+
"kind": "values",
|
| 176 |
+
"values": [1000000000000000000.0, -1000000000000000000.0, 100000000000000000000.0, -100000000000000000000.0]
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
},
|
| 180 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4] } }
|
| 181 |
+
},
|
| 182 |
+
{
|
| 183 |
+
"name": "empty_input_zero_dim",
|
| 184 |
+
"inputs": { "x": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } } },
|
| 185 |
+
"outputs": { "y": { "dtype": "float32", "shape": [0], "tolerance": 0 } }
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"name": "f16_unaligned_scalar_fallback_tail",
|
| 189 |
+
"inputs": {
|
| 190 |
+
"x": {
|
| 191 |
+
"dtype": "float16",
|
| 192 |
+
"shape": [7],
|
| 193 |
+
"data": { "kind": "values", "values": [-100.0, -8.0, -0.75, 0.0, 0.75, 8.0, 100.0] }
|
| 194 |
+
}
|
| 195 |
+
},
|
| 196 |
+
"outputs": { "y": { "dtype": "float16", "shape": [7], "tolerance": 0.005, "relTolerance": 0.005 } }
|
| 197 |
+
},
|
| 198 |
+
{
|
| 199 |
+
"name": "f32_scalar_tail_4095",
|
| 200 |
+
"provenance": {
|
| 201 |
+
"notes": "Compact sibling for the f32 Asinh scalar-fallback benchmark; count is intentionally not divisible by four."
|
| 202 |
+
},
|
| 203 |
+
"inputs": {
|
| 204 |
+
"x": { "dtype": "float32", "shape": [4095], "data": { "kind": "linspace", "start": -10.0, "end": 10.0 } }
|
| 205 |
+
},
|
| 206 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4095], "tolerance": 0.00001, "relTolerance": 0.00001 } }
|
| 207 |
+
}
|
| 208 |
+
]
|
| 209 |
+
}
|
build/webgpu/unary-scalar.wgsl.jinja
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{% macro emit_asinh_safe() %}
|
| 24 |
+
fn asinh_safe(x: f32) -> f32 {
|
| 25 |
+
// The log(x + sqrt(x*x + 1)) identity overflows in the x*x term for very
|
| 26 |
+
// large |x|, returning Inf instead of the true ~log(2|x|). Route large
|
| 27 |
+
// magnitudes through the algebraically-equivalent, overflow-free form
|
| 28 |
+
// (sqrt(x*x+1) == |x| to full f32 precision long before this point). The
|
| 29 |
+
// builtin path handles the normal range.
|
| 30 |
+
let a = abs(x);
|
| 31 |
+
if (a > 1.0e16) {
|
| 32 |
+
return sign(x) * (log(a) + 0.6931471805599453);
|
| 33 |
+
}
|
| 34 |
+
return asinh(x);
|
| 35 |
+
}{% endmacro %}
|
| 36 |
+
{{ emit_asinh_safe() }}
|
| 37 |
+
{{ flat_tail_open() }}
|
| 38 |
+
let v = f32(x[i]);
|
| 39 |
+
y[i] = {{ scalar }}(asinh_safe(v));
|
| 40 |
+
{{ flat_tail_close() -}}
|
| 41 |
+
}
|
build/webgpu/unary-vec4.wgsl.jinja
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{% macro emit_asinh_safe() %}
|
| 9 |
+
fn asinh_safe(x: f32) -> f32 {
|
| 10 |
+
// The log(x + sqrt(x*x + 1)) identity overflows in the x*x term for very
|
| 11 |
+
// large |x|, returning Inf instead of the true ~log(2|x|). Route large
|
| 12 |
+
// magnitudes through the algebraically-equivalent, overflow-free form
|
| 13 |
+
// (sqrt(x*x+1) == |x| to full f32 precision long before this point). The
|
| 14 |
+
// builtin path handles the normal range.
|
| 15 |
+
let a = abs(x);
|
| 16 |
+
if (a > 1.0e16) {
|
| 17 |
+
return sign(x) * (log(a) + 0.6931471805599453);
|
| 18 |
+
}
|
| 19 |
+
return asinh(x);
|
| 20 |
+
}{% endmacro %}
|
| 21 |
+
{{ emit_asinh_safe() }}
|
| 22 |
+
|
| 23 |
+
@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
|
| 24 |
+
fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {
|
| 25 |
+
// 2D-folded flat index: gid.y carries the high bits when the element count exceeds the
|
| 26 |
+
// maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills the rest into y).
|
| 27 |
+
let i = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
|
| 28 |
+
if (i >= params.count) {
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
let xv = x[i];
|
| 32 |
+
let fv = vec4<f32>(xv);
|
| 33 |
+
y[i] = {{ vectorScalar }}(vec4<f32>(asinh_safe(fv.x), asinh_safe(fv.y), asinh_safe(fv.z), asinh_safe(fv.w)));
|
| 34 |
+
}
|