sync 2e7068faf55e
Browse files- README.md +57 -0
- build/webgpu/bench.json +43 -0
- build/webgpu/manifest.json +84 -0
- build/webgpu/metadata.json +19 -0
- build/webgpu/test.json +247 -0
- build/webgpu/unary-scalar.wgsl.jinja +47 -0
- build/webgpu/unary-vec4.wgsl.jinja +41 -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.Atanh
|
| 10 |
+
|
| 11 |
+
`ai.onnx` · standard ONNX operator · ONNX opset ≥ 9
|
| 12 |
+
|
| 13 |
+
## Description
|
| 14 |
+
|
| 15 |
+
Computes the inverse hyperbolic tangent (`atanh`) of each element of the input tensor. Operates elementwise; input values must be in the open interval `(-1, 1)`.
|
| 16 |
+
|
| 17 |
+
See the [ONNX `Atanh` spec](https://onnx.ai/onnx/operators/onnx__Atanh.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 tangent; real-valued results require inputs in `(-1, 1)`. | 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 arctangent of each element of `input`; 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.Atanh", { version: 1 });
|
| 59 |
+
const { y } = await kernel({ x: { data: xData, shape: [] } });
|
| 60 |
+
```
|
build/webgpu/bench.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Atanh",
|
| 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": "1m_f16_vec4",
|
| 11 |
+
"preset": "smoke",
|
| 12 |
+
"vars": { "dtype": "float16", "count": 1048576 },
|
| 13 |
+
"inputs": {
|
| 14 |
+
"x": { "shape": [1048576], "dtype": "float16", "dist": "uniform", "seed": 911, "scale": 1.8, "offset": -0.9 }
|
| 15 |
+
},
|
| 16 |
+
"outputs": { "y": { "shape": [1048576], "dtype": "float16" } },
|
| 17 |
+
"bench": {
|
| 18 |
+
"primary": true,
|
| 19 |
+
"metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }]
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"name": "1m_f32_scalar_fallback_unaligned",
|
| 24 |
+
"preset": "smoke",
|
| 25 |
+
"vars": { "dtype": "float32", "count": 1048575 },
|
| 26 |
+
"inputs": {
|
| 27 |
+
"x": { "shape": [1048575], "dtype": "float32", "dist": "uniform", "seed": 912, "scale": 1.8, "offset": -0.9 }
|
| 28 |
+
},
|
| 29 |
+
"outputs": { "y": { "shape": [1048575], "dtype": "float32" } },
|
| 30 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"name": "1m_f16_scalar_fallback_unaligned",
|
| 34 |
+
"preset": "smoke",
|
| 35 |
+
"vars": { "dtype": "float16", "count": 1048575 },
|
| 36 |
+
"inputs": {
|
| 37 |
+
"x": { "shape": [1048575], "dtype": "float16", "dist": "uniform", "seed": 913, "scale": 1.8, "offset": -0.9 }
|
| 38 |
+
},
|
| 39 |
+
"outputs": { "y": { "shape": [1048575], "dtype": "float16" } },
|
| 40 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 41 |
+
}
|
| 42 |
+
]
|
| 43 |
+
}
|
build/webgpu/manifest.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"domain": "ai.onnx",
|
| 3 |
+
"name": "Atanh",
|
| 4 |
+
"sinceVersion": 9,
|
| 5 |
+
"description": "Computes the inverse hyperbolic tangent (`atanh`) of each element of the input tensor. Operates elementwise; input values must be in the open interval `(-1, 1)`.",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{
|
| 8 |
+
"role": "input",
|
| 9 |
+
"dtype": "T",
|
| 10 |
+
"description": "Values to map elementwise through inverse hyperbolic tangent; real-valued results require inputs in `(-1, 1)`."
|
| 11 |
+
}
|
| 12 |
+
],
|
| 13 |
+
"outputs": [
|
| 14 |
+
{
|
| 15 |
+
"role": "output",
|
| 16 |
+
"dtype": "T",
|
| 17 |
+
"rank": "ranks.input",
|
| 18 |
+
"description": "The hyperbolic arctangent of each element of `input`; same shape as the input.",
|
| 19 |
+
"shape": "shapes.input"
|
| 20 |
+
}
|
| 21 |
+
],
|
| 22 |
+
"typeConstraints": { "T": ["float32", "float16"] },
|
| 23 |
+
"args": {
|
| 24 |
+
"x": { "kind": "tensor", "semantic": "input", "role": "input" },
|
| 25 |
+
"y": { "kind": "tensor", "semantic": "output", "role": "output" }
|
| 26 |
+
},
|
| 27 |
+
"tunables": { "WORKGROUP_SIZE": 256 },
|
| 28 |
+
"variants": [
|
| 29 |
+
{
|
| 30 |
+
"id": "same_layout_vec4",
|
| 31 |
+
"when": ["numel(shapes.x) > 0", "numel(shapes.x) % 4 == 0", "numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)"],
|
| 32 |
+
"constants": {
|
| 33 |
+
"scalar": "dtypes.T",
|
| 34 |
+
"usesF16": "dtypes.T == \"f16\"",
|
| 35 |
+
"vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\""
|
| 36 |
+
},
|
| 37 |
+
"passes": [
|
| 38 |
+
{
|
| 39 |
+
"id": "main",
|
| 40 |
+
"name": "Atanh.vec4",
|
| 41 |
+
"source": { "shader": "unary-vec4.wgsl.jinja", "inputs": { "op": "\"atanh\"" } },
|
| 42 |
+
"bindings": [
|
| 43 |
+
{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" },
|
| 44 |
+
{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" },
|
| 45 |
+
{
|
| 46 |
+
"name": "params",
|
| 47 |
+
"semantic": "kernel.params",
|
| 48 |
+
"buffer": { "type": "uniform" },
|
| 49 |
+
"struct": {
|
| 50 |
+
"name": "Params",
|
| 51 |
+
"fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.y) / 4" }]
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
],
|
| 55 |
+
"dispatch": { "threads": "numel(shapes.y) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 56 |
+
}
|
| 57 |
+
],
|
| 58 |
+
"priority": 20
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"id": "elementwise",
|
| 62 |
+
"when": ["numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)"],
|
| 63 |
+
"constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" },
|
| 64 |
+
"passes": [
|
| 65 |
+
{
|
| 66 |
+
"id": "main",
|
| 67 |
+
"name": "Atanh",
|
| 68 |
+
"source": { "shader": "unary-scalar.wgsl.jinja", "inputs": { "op": "\"atanh\"", "itemsPerInvocation": 4 } },
|
| 69 |
+
"bindings": [
|
| 70 |
+
{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" },
|
| 71 |
+
{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$scalar" },
|
| 72 |
+
{
|
| 73 |
+
"name": "params",
|
| 74 |
+
"semantic": "kernel.params",
|
| 75 |
+
"buffer": { "type": "uniform" },
|
| 76 |
+
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.y)" }] }
|
| 77 |
+
}
|
| 78 |
+
],
|
| 79 |
+
"dispatch": { "threads": "ceilDiv(numel(shapes.y), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 80 |
+
}
|
| 81 |
+
]
|
| 82 |
+
}
|
| 83 |
+
]
|
| 84 |
+
}
|
build/webgpu/metadata.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ai.onnx.Atanh",
|
| 3 |
+
"id": "_ai_onnx_atanh_webgpu_8d63922",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"backend": { "type": "webgpu" },
|
| 7 |
+
"digest": {
|
| 8 |
+
"algorithm": "sha256",
|
| 9 |
+
"files": {
|
| 10 |
+
"bench.json": "NTOrbyRKHuw4fvc5vl66WZf+8Jg8TH/srsgfC+k/shk=",
|
| 11 |
+
"manifest.json": "IC/2LTfUU97KTzRCcfiMS1d9aAETVID1Ch3F5dz2VA0=",
|
| 12 |
+
"test.json": "jBj/kfXXcx95j74iwm1vc6GhOfkFxhLPu2srA7Obz0U=",
|
| 13 |
+
"unary-scalar.wgsl.jinja": "k2knkcmGVcIrmqCemV/mIiIRauDUgvJBgfJmZjdeTbQ=",
|
| 14 |
+
"unary-vec4.wgsl.jinja": "2XlqwcUfyxUz90FaEDonfVXO1Pdijz2R2RJ+Mciv4Ks="
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
|
| 18 |
+
"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.Atanh" }
|
| 19 |
+
}
|
build/webgpu/test.json
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Atanh",
|
| 3 |
+
"cases": [
|
| 4 |
+
{
|
| 5 |
+
"name": "f32_values",
|
| 6 |
+
"inputs": {
|
| 7 |
+
"x": {
|
| 8 |
+
"dtype": "float32",
|
| 9 |
+
"shape": [6],
|
| 10 |
+
"data": { "kind": "values", "values": [-0.9, -0.5, 0.0, 0.25, 0.5, 0.9] }
|
| 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.Atanh",
|
| 24 |
+
"notes": "For tiny finite inputs atanh(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_near_unit_boundary_accuracy_gpu_gap",
|
| 37 |
+
"skipGpu": {
|
| 38 |
+
"category": "todo",
|
| 39 |
+
"reason": "Near the high-slope domain boundary, the current f32 implementation differs from the CPU reference by about one ULP. A higher-accuracy f32 algorithm or software-extended precision could close this implementable gap."
|
| 40 |
+
},
|
| 41 |
+
"provenance": {
|
| 42 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 43 |
+
"test": "MathOpTest.Atanh",
|
| 44 |
+
"notes": "Values just inside the open Atanh domain are finite but numerically sensitive; this catches boundary accuracy loss before it becomes an Inf/NaN classification bug."
|
| 45 |
+
},
|
| 46 |
+
"inputs": {
|
| 47 |
+
"x": {
|
| 48 |
+
"dtype": "float32",
|
| 49 |
+
"shape": [4],
|
| 50 |
+
"data": {
|
| 51 |
+
"kind": "values",
|
| 52 |
+
"values": [-0.9999999403953552, -0.9999998807907104, 0.9999998807907104, 0.9999999403953552]
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 5e-7, "relTolerance": 0 } }
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"name": "f32_subnormal_identity_tail_scalar_gpu_gap",
|
| 60 |
+
"skipGpu": {
|
| 61 |
+
"category": "permanent",
|
| 62 |
+
"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."
|
| 63 |
+
},
|
| 64 |
+
"provenance": {
|
| 65 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 66 |
+
"test": "MathOpTest.Atanh",
|
| 67 |
+
"notes": "Scalar-path companion: subnormal inputs are valid finite Atanh outputs."
|
| 68 |
+
},
|
| 69 |
+
"inputs": {
|
| 70 |
+
"x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-1e-40, 0.0, 1e-40] } }
|
| 71 |
+
},
|
| 72 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0 } }
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "f32_near_unit_boundary_accuracy_scalar_gpu_gap",
|
| 76 |
+
"skipGpu": {
|
| 77 |
+
"category": "todo",
|
| 78 |
+
"reason": "Near the high-slope domain boundary, the current scalar f32 implementation differs from the CPU reference by about one ULP. A higher-accuracy f32 algorithm or software-extended precision could close this implementable gap."
|
| 79 |
+
},
|
| 80 |
+
"provenance": {
|
| 81 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 82 |
+
"test": "MathOpTest.Atanh",
|
| 83 |
+
"notes": "Scalar-path companion for finite near-boundary Atanh accuracy just inside the open domain."
|
| 84 |
+
},
|
| 85 |
+
"inputs": {
|
| 86 |
+
"x": {
|
| 87 |
+
"dtype": "float32",
|
| 88 |
+
"shape": [3],
|
| 89 |
+
"data": { "kind": "values", "values": [-0.9999999403953552, 0.9999998807907104, 0.9999999403953552] }
|
| 90 |
+
}
|
| 91 |
+
},
|
| 92 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 5e-7, "relTolerance": 0 } }
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"name": "f16_values",
|
| 96 |
+
"inputs": {
|
| 97 |
+
"x": {
|
| 98 |
+
"dtype": "float16",
|
| 99 |
+
"shape": [2, 3],
|
| 100 |
+
"data": { "kind": "values", "values": [-0.9, -0.5, 0.0, 0.25, 0.5, 0.9] }
|
| 101 |
+
}
|
| 102 |
+
},
|
| 103 |
+
"outputs": { "y": { "dtype": "float16", "shape": [2, 3] } },
|
| 104 |
+
"tolerance": 0.003
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"name": "out_of_domain_returns_nan",
|
| 108 |
+
"inputs": {
|
| 109 |
+
"x": {
|
| 110 |
+
"dtype": "float32",
|
| 111 |
+
"shape": [6],
|
| 112 |
+
"data": { "kind": "values", "values": [1.5, -1.5, 2.0, -2.0, 1.0, -1.0] }
|
| 113 |
+
}
|
| 114 |
+
},
|
| 115 |
+
"outputs": { "y": { "dtype": "float32", "shape": [6], "tolerance": 0.000001, "allowNaN": true } }
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"name": "f16_domain_and_nonfinite_values",
|
| 119 |
+
"inputs": {
|
| 120 |
+
"x": {
|
| 121 |
+
"dtype": "float16",
|
| 122 |
+
"shape": [10],
|
| 123 |
+
"data": { "kind": "values", "values": [-1.0, -0.999, 0.0, 0.0, 0.999, 1.0, 1.001, -1.001, "Infinity", "NaN"] }
|
| 124 |
+
}
|
| 125 |
+
},
|
| 126 |
+
"outputs": { "y": { "dtype": "float16", "shape": [10], "tolerance": 0.003, "allowNaN": true } }
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"name": "ort_float_boundary_interval",
|
| 130 |
+
"provenance": {
|
| 131 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 132 |
+
"test": "MathOpTest.Atanh"
|
| 133 |
+
},
|
| 134 |
+
"inputs": {
|
| 135 |
+
"x": { "dtype": "float32", "shape": [5], "data": { "kind": "values", "values": [-1.0, -0.5, 0.0, 0.5, 1.0] } }
|
| 136 |
+
},
|
| 137 |
+
"outputs": { "y": { "dtype": "float32", "shape": [5], "tolerance": 0.00001 } }
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"name": "ort_domain_and_nonfinite_values",
|
| 141 |
+
"provenance": {
|
| 142 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 143 |
+
"test": "MathOpTest.Atanh",
|
| 144 |
+
"notes": "Adds endpoints, out-of-domain values, signed infinities, signed zero, and NaN."
|
| 145 |
+
},
|
| 146 |
+
"inputs": {
|
| 147 |
+
"x": {
|
| 148 |
+
"dtype": "float32",
|
| 149 |
+
"shape": [11],
|
| 150 |
+
"data": {
|
| 151 |
+
"kind": "values",
|
| 152 |
+
"values": [-1.0, -0.9999999, 0.0, 0.0, 0.9999999, 1.0, 1.0000001, -1.0000001, "Infinity", "-Infinity", "NaN"]
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
},
|
| 156 |
+
"outputs": { "y": { "dtype": "float32", "shape": [11], "tolerance": 0.00001, "allowNaN": true } }
|
| 157 |
+
},
|
| 158 |
+
{
|
| 159 |
+
"name": "onnx_backend_example",
|
| 160 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_atanh_example" },
|
| 161 |
+
"inputs": { "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-0.5, 0.0, 0.5] } } },
|
| 162 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.000001 } }
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"name": "onnx_backend_atanh",
|
| 166 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_atanh" },
|
| 167 |
+
"inputs": {
|
| 168 |
+
"x": {
|
| 169 |
+
"dtype": "float32",
|
| 170 |
+
"shape": [3, 4, 5],
|
| 171 |
+
"data": {
|
| 172 |
+
"kind": "values",
|
| 173 |
+
"values": [0.54881352186203, 0.7151893377304077, 0.6027633547782898, 0.5448831915855408, 0.42365479469299316, 0.6458941102027893, 0.4375872015953064, 0.891772985458374, 0.9636627435684204, 0.3834415078163147, 0.7917250394821167, 0.5288949012756348, 0.5680445432662964, 0.9255966544151306, 0.07103605568408966, 0.08712930232286453, 0.020218396559357643, 0.832619845867157, 0.7781567573547363, 0.8700121641159058, 0.978618323802948, 0.7991585731506348, 0.4614793658256531, 0.7805292010307312, 0.11827442795038223, 0.6399210095405579, 0.14335328340530396, 0.9446688890457153, 0.5218483209609985, 0.4146619439125061, 0.26455560326576233, 0.7742336988449097, 0.4561503231525421, 0.568433940410614, 0.018789799883961678, 0.6176354885101318, 0.6120957136154175, 0.6169340014457703, 0.9437480568885803, 0.681820273399353, 0.35950788855552673, 0.43703195452690125, 0.6976311802864075, 0.0602254718542099, 0.6667667031288147, 0.670637845993042, 0.21038256585597992, 0.12892629206180573, 0.31542834639549255, 0.36371076107025146, 0.5701967477798462, 0.4386015236377716, 0.9883738160133362, 0.10204481333494186, 0.20887675881385803, 0.16130951046943665, 0.6531082987785339, 0.25329160690307617, 0.4663107693195343, 0.24442559480667114]
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
},
|
| 177 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0.00001, "allowNaN": true } }
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"name": "onnx_backend_atanh_example",
|
| 181 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_atanh_example" },
|
| 182 |
+
"inputs": { "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-0.5, 0.0, 0.5] } } },
|
| 183 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.00001 } }
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
"name": "vec4_f16_lanes",
|
| 187 |
+
"inputs": {
|
| 188 |
+
"x": {
|
| 189 |
+
"dtype": "float16",
|
| 190 |
+
"shape": [16],
|
| 191 |
+
"data": {
|
| 192 |
+
"kind": "values",
|
| 193 |
+
"values": [-0.95, -0.9, -0.75, -0.5, -0.25, -0.125, 0.0, 0.0625, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 0.95]
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
},
|
| 197 |
+
"outputs": { "y": { "dtype": "float16", "shape": [16], "tolerance": 0.001, "relTolerance": 0.005 } }
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"name": "empty_input_zero_dim",
|
| 201 |
+
"inputs": { "x": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } } },
|
| 202 |
+
"outputs": { "y": { "dtype": "float32", "shape": [0], "tolerance": 0 } }
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"name": "f32_near_unit_boundary_gpu_runnable",
|
| 206 |
+
"inputs": {
|
| 207 |
+
"x": {
|
| 208 |
+
"dtype": "float32",
|
| 209 |
+
"shape": [6],
|
| 210 |
+
"data": { "kind": "values", "values": [-0.9999, -0.999, -0.99, 0.99, 0.999, 0.9999] }
|
| 211 |
+
}
|
| 212 |
+
},
|
| 213 |
+
"outputs": { "y": { "dtype": "float32", "shape": [6], "tolerance": 0.001, "relTolerance": 0.0001 } }
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
"name": "rank0_scalar",
|
| 217 |
+
"inputs": { "x": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [0.5] } } },
|
| 218 |
+
"outputs": {
|
| 219 |
+
"y": {
|
| 220 |
+
"dtype": "float32",
|
| 221 |
+
"shape": [],
|
| 222 |
+
"data": { "kind": "values", "values": [0.5493061443340549] },
|
| 223 |
+
"tolerance": 0.000001
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
},
|
| 227 |
+
{
|
| 228 |
+
"name": "f32_boundary_exact_one_and_neg_one",
|
| 229 |
+
"inputs": {
|
| 230 |
+
"x": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [-1.0, -0.5, 0.5, 1.0] } }
|
| 231 |
+
},
|
| 232 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 0.000001, "allowNaN": true } }
|
| 233 |
+
},
|
| 234 |
+
{
|
| 235 |
+
"name": "f16_empty_zero_numel_shape",
|
| 236 |
+
"inputs": { "x": { "dtype": "float16", "shape": [0], "data": { "kind": "values", "values": [] } } },
|
| 237 |
+
"outputs": { "y": { "dtype": "float16", "shape": [0] } }
|
| 238 |
+
},
|
| 239 |
+
{
|
| 240 |
+
"name": "f32_vec4_sustained_1024",
|
| 241 |
+
"inputs": {
|
| 242 |
+
"x": { "dtype": "float32", "shape": [1024], "data": { "kind": "linspace", "start": -0.9, "end": 0.9 } }
|
| 243 |
+
},
|
| 244 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1024], "tolerance": 0.00001 } }
|
| 245 |
+
}
|
| 246 |
+
]
|
| 247 |
+
}
|
build/webgpu/unary-scalar.wgsl.jinja
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{% set unaryDomainGuard = device.adapterInfo.architecture == "" or device.adapterInfo.architecture == "apple" %}
|
| 24 |
+
{% macro emit_atanh_safe(guarded) %}
|
| 25 |
+
fn atanh_safe(x: f32) -> f32 {
|
| 26 |
+
{%- if guarded %}
|
| 27 |
+
// A no-NaN compilation path can return a finite value for out-of-domain
|
| 28 |
+
// operands. Classify the loaded bits instead: |x| == 1 is a signed
|
| 29 |
+
// infinity and |x| > 1 (including NaN) is a quiet NaN carrying the operand's
|
| 30 |
+
// sign.
|
| 31 |
+
let bits = bitcast<u32>(x);
|
| 32 |
+
let magnitude = bits & 0x7fffffffu;
|
| 33 |
+
if (magnitude == 0x3f800000u) {
|
| 34 |
+
return bitcast<f32>((bits & 0x80000000u) | 0x7f800000u);
|
| 35 |
+
}
|
| 36 |
+
if (magnitude > 0x3f800000u) {
|
| 37 |
+
return bitcast<f32>(bits | 0x7fc00000u);
|
| 38 |
+
}
|
| 39 |
+
{%- endif %}
|
| 40 |
+
return atanh(x);
|
| 41 |
+
}{% endmacro %}
|
| 42 |
+
{{ emit_atanh_safe(unaryDomainGuard) }}
|
| 43 |
+
{{ flat_tail_open() }}
|
| 44 |
+
let v = f32(x[i]);
|
| 45 |
+
y[i] = {{ scalar }}(atanh_safe(v));
|
| 46 |
+
{{ flat_tail_close() -}}
|
| 47 |
+
}
|
build/webgpu/unary-vec4.wgsl.jinja
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{% set unaryDomainGuard = device.adapterInfo.architecture == "" or device.adapterInfo.architecture == "apple" %}
|
| 9 |
+
{% macro emit_atanh_safe(guarded) %}
|
| 10 |
+
fn atanh_safe(x: f32) -> f32 {
|
| 11 |
+
{%- if guarded %}
|
| 12 |
+
// A no-NaN compilation path can return a finite value for out-of-domain
|
| 13 |
+
// operands. Classify the loaded bits instead: |x| == 1 is a signed
|
| 14 |
+
// infinity and |x| > 1 (including NaN) is a quiet NaN carrying the operand's
|
| 15 |
+
// sign.
|
| 16 |
+
let bits = bitcast<u32>(x);
|
| 17 |
+
let magnitude = bits & 0x7fffffffu;
|
| 18 |
+
if (magnitude == 0x3f800000u) {
|
| 19 |
+
return bitcast<f32>((bits & 0x80000000u) | 0x7f800000u);
|
| 20 |
+
}
|
| 21 |
+
if (magnitude > 0x3f800000u) {
|
| 22 |
+
return bitcast<f32>(bits | 0x7fc00000u);
|
| 23 |
+
}
|
| 24 |
+
{%- endif %}
|
| 25 |
+
return atanh(x);
|
| 26 |
+
}{% endmacro %}
|
| 27 |
+
{{ emit_atanh_safe(unaryDomainGuard) }}
|
| 28 |
+
|
| 29 |
+
@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
|
| 30 |
+
fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {
|
| 31 |
+
// 2D-folded flat index: gid.y carries the high bits when the element count exceeds the
|
| 32 |
+
// maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills the rest into y).
|
| 33 |
+
let i = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
|
| 34 |
+
if (i >= params.count) {
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
let xv = x[i];
|
| 38 |
+
let fv = vec4<f32>(xv);
|
| 39 |
+
y[i] = {{ vectorScalar }}(vec4<f32>(
|
| 40 |
+
atanh_safe(fv.x), atanh_safe(fv.y), atanh_safe(fv.z), atanh_safe(fv.w)));
|
| 41 |
+
}
|