sync 2e7068faf55e
Browse files- README.md +69 -0
- build/webgpu/bench.json +106 -0
- build/webgpu/manifest.json +273 -0
- build/webgpu/mean-variance-normalization-serial-rows.wgsl.jinja +62 -0
- build/webgpu/mean-variance-normalization-subgroup.wgsl.jinja +136 -0
- build/webgpu/metadata.json +23 -0
- build/webgpu/noop.wgsl.jinja +4 -0
- build/webgpu/norm-flat-apply.wgsl.jinja +14 -0
- build/webgpu/norm-flat-splitk-combine.wgsl.jinja +20 -0
- build/webgpu/norm-flat-splitk-partials.wgsl.jinja +42 -0
- build/webgpu/test.json +582 -0
README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
| 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.MeanVarianceNormalization
|
| 10 |
+
|
| 11 |
+
`ai.onnx` · standard ONNX operator · ONNX opset ≥ 13
|
| 12 |
+
|
| 13 |
+
## Description
|
| 14 |
+
|
| 15 |
+
Normalizes each group as `(X - mean) / sqrt(variance)`, reducing over `axes` (default `[0, 2, 3]`).
|
| 16 |
+
|
| 17 |
+
See the [ONNX `MeanVarianceNormalization` spec](https://onnx.ai/onnx/operators/onnx__MeanVarianceNormalization.html) for the reference semantics.
|
| 18 |
+
|
| 19 |
+
## Inputs
|
| 20 |
+
|
| 21 |
+
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|
| 22 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 23 |
+
| `X` | `x` | `T` | — | — | Input tensor to normalize. | required |
|
| 24 |
+
|
| 25 |
+
## Outputs
|
| 26 |
+
|
| 27 |
+
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|
| 28 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 29 |
+
| `Y` | `y` | `T` | same as `X` | same as `X` | Normalized tensor with the same shape as `X`. | required |
|
| 30 |
+
|
| 31 |
+
## Attributes
|
| 32 |
+
|
| 33 |
+
Default values (overridable per request):
|
| 34 |
+
|
| 35 |
+
| Attribute | Default | Description |
|
| 36 |
+
| --- | --- | --- |
|
| 37 |
+
| `axes` | `[0,2,3]` | Axes that share a mean and variance; negative values count from the back. |
|
| 38 |
+
|
| 39 |
+
## Type constraints
|
| 40 |
+
|
| 41 |
+
| Variable | Allowed dtypes |
|
| 42 |
+
| --- | --- |
|
| 43 |
+
| `T` | `float32`, `float16` |
|
| 44 |
+
|
| 45 |
+
## Files
|
| 46 |
+
|
| 47 |
+
- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)
|
| 48 |
+
- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
|
| 49 |
+
- [`test.json`](build/webgpu/test.json) — correctness cases
|
| 50 |
+
- [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
|
| 51 |
+
- [`mean-variance-normalization-serial-rows.wgsl.jinja`](build/webgpu/mean-variance-normalization-serial-rows.wgsl.jinja)
|
| 52 |
+
- [`mean-variance-normalization-subgroup.wgsl.jinja`](build/webgpu/mean-variance-normalization-subgroup.wgsl.jinja)
|
| 53 |
+
- [`noop.wgsl.jinja`](build/webgpu/noop.wgsl.jinja)
|
| 54 |
+
- [`norm-flat-apply.wgsl.jinja`](build/webgpu/norm-flat-apply.wgsl.jinja)
|
| 55 |
+
- [`norm-flat-splitk-combine.wgsl.jinja`](build/webgpu/norm-flat-splitk-combine.wgsl.jinja)
|
| 56 |
+
- [`norm-flat-splitk-partials.wgsl.jinja`](build/webgpu/norm-flat-splitk-partials.wgsl.jinja)
|
| 57 |
+
|
| 58 |
+
## Use with `@huggingface/kernels`
|
| 59 |
+
|
| 60 |
+
The loader derives every required output's shape and logical dtype from the manifest contract and this call.
|
| 61 |
+
It then allocates the result tensors automatically.
|
| 62 |
+
|
| 63 |
+
The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
|
| 64 |
+
|
| 65 |
+
Replace each `*Data` placeholder with a typed array containing the corresponding input data.
|
| 66 |
+
|
| 67 |
+
```js
|
| 68 |
+
import { getKernel } from "@huggingface/kernels";
|
| 69 |
+
|
| 70 |
+
const kernel = await getKernel("webgpu-kernels/ai.onnx.MeanVarianceNormalization", { version: 1 });
|
| 71 |
+
const { y } = await kernel({ x: { data: xData, shape: [2, 2, 1, 2] } });
|
| 72 |
+
```
|
build/webgpu/bench.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.MeanVarianceNormalization",
|
| 3 |
+
"cases": [
|
| 4 |
+
{
|
| 5 |
+
"name": "1x32x32x32_default_axes",
|
| 6 |
+
"preset": "smoke",
|
| 7 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 8 |
+
"inputs": { "x": { "dtype": "float32", "shape": [1, 32, 32, 32] } },
|
| 9 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 32, 32, 32] } },
|
| 10 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"name": "8x64x128x128_default_axes",
|
| 14 |
+
"preset": "smoke",
|
| 15 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 16 |
+
"inputs": { "x": { "dtype": "float32", "shape": [8, 64, 128, 128] } },
|
| 17 |
+
"outputs": { "y": { "dtype": "float32", "shape": [8, 64, 128, 128] } },
|
| 18 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"name": "16x64x64x64_spatial_axes",
|
| 22 |
+
"preset": "smoke",
|
| 23 |
+
"attrs": { "axes": [2, 3] },
|
| 24 |
+
"inputs": { "x": { "dtype": "float32", "shape": [16, 64, 64, 64] } },
|
| 25 |
+
"outputs": { "y": { "dtype": "float32", "shape": [16, 64, 64, 64] } },
|
| 26 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "f16_vec4_8x64x128x128_default_axes",
|
| 30 |
+
"preset": "smoke",
|
| 31 |
+
"vars": { "dtype": "float16" },
|
| 32 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 33 |
+
"inputs": { "x": { "dtype": "float16", "shape": [8, 64, 128, 128], "dist": "normal", "seed": 900, "scale": 0.5 } },
|
| 34 |
+
"outputs": { "y": { "dtype": "float16", "shape": [8, 64, 128, 128] } },
|
| 35 |
+
"bench": {
|
| 36 |
+
"primary": true,
|
| 37 |
+
"metrics": [{ "type": "bandwidth", "value": "3 * dtypeBytes(args.dtype) * numel(shapes.x)" }]
|
| 38 |
+
}
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"name": "f16_all_axes_flat_split_1x1x256x256",
|
| 42 |
+
"preset": "smoke",
|
| 43 |
+
"attrs": { "axes": [0, 1, 2, 3] },
|
| 44 |
+
"inputs": { "x": { "dtype": "float16", "shape": [1, 1, 256, 256], "dist": "normal", "seed": 906, "scale": 0.5 } },
|
| 45 |
+
"outputs": { "y": { "dtype": "float16", "shape": [1, 1, 256, 256] } },
|
| 46 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 2 * numel(shapes.x)" }] }
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"name": "vec4_align_cliff_8x64x128x130_unaligned_W",
|
| 50 |
+
"preset": "smoke",
|
| 51 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 52 |
+
"inputs": { "x": { "dtype": "float32", "shape": [8, 64, 128, 130], "dist": "normal", "seed": 901, "scale": 0.5 } },
|
| 53 |
+
"outputs": { "y": { "dtype": "float32", "shape": [8, 64, 128, 130] } },
|
| 54 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"name": "channel_axis_scalar_strided_8x64x128x128",
|
| 58 |
+
"preset": "smoke",
|
| 59 |
+
"attrs": { "axes": [1] },
|
| 60 |
+
"inputs": { "x": { "dtype": "float32", "shape": [8, 64, 128, 128], "dist": "normal", "seed": 902, "scale": 0.5 } },
|
| 61 |
+
"outputs": { "y": { "dtype": "float32", "shape": [8, 64, 128, 128] } },
|
| 62 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"name": "channel_axis_wg_pow2_cliff_8x65x128x128",
|
| 66 |
+
"preset": "stress",
|
| 67 |
+
"attrs": { "axes": [1] },
|
| 68 |
+
"inputs": { "x": { "dtype": "float32", "shape": [8, 65, 128, 128], "dist": "normal", "seed": 905, "scale": 0.5 } },
|
| 69 |
+
"outputs": { "y": { "dtype": "float32", "shape": [8, 65, 128, 128] } },
|
| 70 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"name": "rank3_scalar_8x4096x1024_reduce_hidden",
|
| 74 |
+
"preset": "stress",
|
| 75 |
+
"provenance": { "notes": "Stress-only capacity case: input plus output occupy exactly 256 MiB of GPU storage." },
|
| 76 |
+
"attrs": { "axes": [2] },
|
| 77 |
+
"inputs": { "x": { "dtype": "float32", "shape": [8, 4096, 1024], "dist": "normal", "seed": 903, "scale": 0.5 } },
|
| 78 |
+
"outputs": { "y": { "dtype": "float32", "shape": [8, 4096, 1024] } },
|
| 79 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"name": "rank3_rows1_decode_hidden768",
|
| 83 |
+
"preset": "smoke",
|
| 84 |
+
"attrs": { "axes": [2] },
|
| 85 |
+
"inputs": { "x": { "dtype": "float32", "shape": [1, 1, 768], "dist": "normal", "seed": 904, "scale": 0.5 } },
|
| 86 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 1, 768] } },
|
| 87 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"name": "stress_all_axes_single_workgroup_rank4_3p9m",
|
| 91 |
+
"preset": "stress",
|
| 92 |
+
"attrs": { "axes": [0, 1, 2, 3] },
|
| 93 |
+
"inputs": { "x": { "dtype": "float32", "shape": [64, 64, 64, 15], "dist": "normal", "seed": 950, "scale": 0.5 } },
|
| 94 |
+
"outputs": { "y": { "dtype": "float32", "shape": [64, 64, 64, 15] } },
|
| 95 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"name": "stress_tiny_reduce_launchbound_wg2_4m_rows",
|
| 99 |
+
"preset": "stress",
|
| 100 |
+
"attrs": { "axes": [2] },
|
| 101 |
+
"inputs": { "x": { "dtype": "float32", "shape": [4194304, 1, 2], "dist": "normal", "seed": 951, "scale": 0.5 } },
|
| 102 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4194304, 1, 2] } },
|
| 103 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "3 * 4 * numel(shapes.x)" }] }
|
| 104 |
+
}
|
| 105 |
+
]
|
| 106 |
+
}
|
build/webgpu/manifest.json
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"domain": "ai.onnx",
|
| 3 |
+
"name": "MeanVarianceNormalization",
|
| 4 |
+
"sinceVersion": 13,
|
| 5 |
+
"description": "Normalizes each group as `(X - mean) / sqrt(variance)`, reducing over `axes` (default `[0, 2, 3]`).",
|
| 6 |
+
"inputs": [{ "role": "X", "dtype": "T", "description": "Input tensor to normalize." }],
|
| 7 |
+
"outputs": [
|
| 8 |
+
{
|
| 9 |
+
"role": "Y",
|
| 10 |
+
"dtype": "T",
|
| 11 |
+
"rank": "ranks.X",
|
| 12 |
+
"description": "Normalized tensor with the same shape as `X`.",
|
| 13 |
+
"shape": "shapes.X"
|
| 14 |
+
}
|
| 15 |
+
],
|
| 16 |
+
"attributes": { "axes": [0, 2, 3] },
|
| 17 |
+
"attributeDescriptions": { "axes": "Axes that share a mean and variance; negative values count from the back." },
|
| 18 |
+
"typeConstraints": { "T": ["float32", "float16"] },
|
| 19 |
+
"args": {
|
| 20 |
+
"x": { "kind": "tensor", "semantic": "X", "role": "input" },
|
| 21 |
+
"y": { "kind": "tensor", "semantic": "Y", "role": "output" }
|
| 22 |
+
},
|
| 23 |
+
"tunables": {
|
| 24 |
+
"WORKGROUP_SIZE": 256,
|
| 25 |
+
"SERIAL_WORKGROUP_SIZE": 256,
|
| 26 |
+
"SERIAL_TINY_WORKGROUP_SIZE": 64,
|
| 27 |
+
"SERIAL_MAX_REDUCTION": 128,
|
| 28 |
+
"SERIAL_MIN_ROWS": 256,
|
| 29 |
+
"TREE_MEDIUM_WORKGROUP_SIZE": 64,
|
| 30 |
+
"VEC4_MIN_REDUCTION": 8,
|
| 31 |
+
"FLAT_SPLIT_MIN_ELEMENTS": 65536,
|
| 32 |
+
"FLAT_SPLIT_TARGET_ELEMENTS": 4096,
|
| 33 |
+
"MAX_FLAT_SPLITS": 256
|
| 34 |
+
},
|
| 35 |
+
"derive": {
|
| 36 |
+
"deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)",
|
| 37 |
+
"foldedDispatchCapacity": "device.limits.maxComputeWorkgroupsPerDimension * device.limits.maxComputeWorkgroupsPerDimension",
|
| 38 |
+
"shapeContract": "ranks.X >= 3 and ranks.Y == ranks.X and sameShape(shapes.Y, shapes.X) and f16Ok(dtypes.T)",
|
| 39 |
+
"reduceCount": "(dim(shapes.X, 0) if hasAxis(attrs.axes, 0, ranks.X) else 1) * (dim(shapes.X, 1) if hasAxis(attrs.axes, 1, ranks.X) else 1) * (dim(shapes.X, 2) if hasAxis(attrs.axes, 2, ranks.X) else 1) * (dim(shapes.X, 3) if ranks.X >= 4 and hasAxis(attrs.axes, 3, ranks.X) else 1) * (dim(shapes.X, 4) if ranks.X >= 5 and hasAxis(attrs.axes, 4, ranks.X) else 1) * (dim(shapes.X, 5) if ranks.X >= 6 and hasAxis(attrs.axes, 5, ranks.X) else 1)",
|
| 40 |
+
"rowCount": "numel(shapes.X) / max(1, reduceCount)",
|
| 41 |
+
"allAxesReduced": "hasAxis(attrs.axes, 0, ranks.X) and hasAxis(attrs.axes, 1, ranks.X) and hasAxis(attrs.axes, 2, ranks.X) and (ranks.X < 4 or hasAxis(attrs.axes, 3, ranks.X)) and (ranks.X < 5 or hasAxis(attrs.axes, 4, ranks.X)) and (ranks.X < 6 or hasAxis(attrs.axes, 5, ranks.X))",
|
| 42 |
+
"vec4Eligible": "((ranks.X == 3 and hasAxis(attrs.axes, 2, 3) and (dim(shapes.X, 2) % 4 == 0 or (hasAxis(attrs.axes, 1, 3) and dim(shapes.X, 1) * dim(shapes.X, 2) % 4 == 0) or (hasAxis(attrs.axes, 0, 3) and hasAxis(attrs.axes, 1, 3) and numel(shapes.X) % 4 == 0))) or (ranks.X == 4 and hasAxis(attrs.axes, 3, 4) and (dim(shapes.X, 3) % 4 == 0 or (hasAxis(attrs.axes, 2, 4) and dim(shapes.X, 2) * dim(shapes.X, 3) % 4 == 0) or (hasAxis(attrs.axes, 1, 4) and hasAxis(attrs.axes, 2, 4) and dim(shapes.X, 1) * dim(shapes.X, 2) * dim(shapes.X, 3) % 4 == 0) or (hasAxis(attrs.axes, 0, 4) and hasAxis(attrs.axes, 1, 4) and hasAxis(attrs.axes, 2, 4) and numel(shapes.X) % 4 == 0))) or (ranks.X == 5 and hasAxis(attrs.axes, 4, 5) and (dim(shapes.X, 4) % 4 == 0 or (hasAxis(attrs.axes, 3, 5) and dim(shapes.X, 3) * dim(shapes.X, 4) % 4 == 0) or (hasAxis(attrs.axes, 2, 5) and hasAxis(attrs.axes, 3, 5) and dim(shapes.X, 2) * dim(shapes.X, 3) * dim(shapes.X, 4) % 4 == 0) or (hasAxis(attrs.axes, 1, 5) and hasAxis(attrs.axes, 2, 5) and hasAxis(attrs.axes, 3, 5) and dim(shapes.X, 1) * dim(shapes.X, 2) * dim(shapes.X, 3) * dim(shapes.X, 4) % 4 == 0) or (allAxesReduced and numel(shapes.X) % 4 == 0))) or (ranks.X == 6 and hasAxis(attrs.axes, 5, 6) and (dim(shapes.X, 5) % 4 == 0 or (hasAxis(attrs.axes, 4, 6) and dim(shapes.X, 4) * dim(shapes.X, 5) % 4 == 0) or (hasAxis(attrs.axes, 3, 6) and hasAxis(attrs.axes, 4, 6) and dim(shapes.X, 3) * dim(shapes.X, 4) * dim(shapes.X, 5) % 4 == 0) or (hasAxis(attrs.axes, 2, 6) and hasAxis(attrs.axes, 3, 6) and hasAxis(attrs.axes, 4, 6) and dim(shapes.X, 2) * dim(shapes.X, 3) * dim(shapes.X, 4) * dim(shapes.X, 5) % 4 == 0) or (hasAxis(attrs.axes, 1, 6) and hasAxis(attrs.axes, 2, 6) and hasAxis(attrs.axes, 3, 6) and hasAxis(attrs.axes, 4, 6) and dim(shapes.X, 1) * dim(shapes.X, 2) * dim(shapes.X, 3) * dim(shapes.X, 4) * dim(shapes.X, 5) % 4 == 0) or (allAxesReduced and numel(shapes.X) % 4 == 0))))",
|
| 43 |
+
"maxWorkgroupSize": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)",
|
| 44 |
+
"minSubgroupSize": "device.adapterInfo.subgroupMinSize if has(device.adapterInfo, \"subgroupMinSize\") else 1",
|
| 45 |
+
"useSubgroups": "device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and minSubgroupSize > 0",
|
| 46 |
+
"scalarWorkgroupSize": "min(maxWorkgroupSize, tunables.TREE_MEDIUM_WORKGROUP_SIZE) if not useSubgroups and reduceCount > tunables.TREE_MEDIUM_WORKGROUP_SIZE and reduceCount <= 2 * tunables.TREE_MEDIUM_WORKGROUP_SIZE else min(maxWorkgroupSize, max(1, pow2ceil(reduceCount)))",
|
| 47 |
+
"vectorWorkgroupSize": "min(maxWorkgroupSize, max(1, pow2ceil(ceilDiv(reduceCount, 4))))",
|
| 48 |
+
"serialWorkgroupSize": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX, (tunables.SERIAL_TINY_WORKGROUP_SIZE if reduceCount <= 4 else tunables.SERIAL_WORKGROUP_SIZE))",
|
| 49 |
+
"rowDispatchFits": "rowCount <= foldedDispatchCapacity",
|
| 50 |
+
"serialDispatchFits": "ceilDiv(rowCount, serialWorkgroupSize) <= foldedDispatchCapacity",
|
| 51 |
+
"applyDispatchFits": "ceilDiv(numel(shapes.Y), maxWorkgroupSize) <= foldedDispatchCapacity",
|
| 52 |
+
"scalarStorageFits": "scalarWorkgroupSize * 8 <= device.limits.maxComputeWorkgroupStorageSize",
|
| 53 |
+
"vectorStorageFits": "vectorWorkgroupSize * 8 <= device.limits.maxComputeWorkgroupStorageSize",
|
| 54 |
+
"flatSplit": "min(tunables.MAX_FLAT_SPLITS, pow2ceil(ceilDiv(numel(shapes.X), tunables.FLAT_SPLIT_TARGET_ELEMENTS)))",
|
| 55 |
+
"flatScratchBytes": "flatSplit * 8",
|
| 56 |
+
"flatPathFits": "flatSplit <= device.limits.maxComputeWorkgroupsPerDimension and flatScratchBytes <= device.limits.maxStorageBufferBindingSize and flatScratchBytes <= device.limits.maxBufferSize and maxWorkgroupSize * 8 <= device.limits.maxComputeWorkgroupStorageSize and applyDispatchFits"
|
| 57 |
+
},
|
| 58 |
+
"bindingSets": {
|
| 59 |
+
"rows": [
|
| 60 |
+
{
|
| 61 |
+
"name": "x",
|
| 62 |
+
"arg": "x",
|
| 63 |
+
"semantic": "X",
|
| 64 |
+
"buffer": { "type": "read-only-storage" },
|
| 65 |
+
"elementType": "$ioElement"
|
| 66 |
+
},
|
| 67 |
+
{ "name": "y", "arg": "y", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$ioElement" },
|
| 68 |
+
{
|
| 69 |
+
"name": "params",
|
| 70 |
+
"semantic": "kernel.params",
|
| 71 |
+
"buffer": { "type": "uniform" },
|
| 72 |
+
"struct": { "name": "Params", "fields": [{ "name": "rows", "type": "u32", "value": "rowCount" }] }
|
| 73 |
+
}
|
| 74 |
+
],
|
| 75 |
+
"flatPartials": [
|
| 76 |
+
{ "name": "x", "arg": "x", "semantic": "X", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" },
|
| 77 |
+
{ "name": "partials", "semantic": "partials", "buffer": { "type": "storage" }, "elementType": "vec2<f32>" },
|
| 78 |
+
{
|
| 79 |
+
"name": "params",
|
| 80 |
+
"semantic": "kernel.params",
|
| 81 |
+
"buffer": { "type": "uniform" },
|
| 82 |
+
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.X)" }] }
|
| 83 |
+
}
|
| 84 |
+
],
|
| 85 |
+
"flatCombine": [
|
| 86 |
+
{ "name": "x", "arg": "x", "semantic": "X", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" },
|
| 87 |
+
{
|
| 88 |
+
"name": "partials",
|
| 89 |
+
"semantic": "partials",
|
| 90 |
+
"buffer": { "type": "read-only-storage" },
|
| 91 |
+
"elementType": "vec2<f32>"
|
| 92 |
+
},
|
| 93 |
+
{ "name": "stats", "semantic": "stats", "buffer": { "type": "storage" }, "elementType": "f32", "length": 2 },
|
| 94 |
+
{
|
| 95 |
+
"name": "params",
|
| 96 |
+
"semantic": "kernel.params",
|
| 97 |
+
"buffer": { "type": "uniform" },
|
| 98 |
+
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.X)" }] }
|
| 99 |
+
}
|
| 100 |
+
],
|
| 101 |
+
"flatApply": [
|
| 102 |
+
{ "name": "x", "arg": "x", "semantic": "X", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" },
|
| 103 |
+
{
|
| 104 |
+
"name": "stats",
|
| 105 |
+
"semantic": "stats",
|
| 106 |
+
"buffer": { "type": "read-only-storage" },
|
| 107 |
+
"elementType": "f32",
|
| 108 |
+
"length": 2
|
| 109 |
+
},
|
| 110 |
+
{ "name": "y", "arg": "y", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$scalar" },
|
| 111 |
+
{
|
| 112 |
+
"name": "params",
|
| 113 |
+
"semantic": "kernel.params",
|
| 114 |
+
"buffer": { "type": "uniform" },
|
| 115 |
+
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.Y)" }] }
|
| 116 |
+
}
|
| 117 |
+
],
|
| 118 |
+
"noopParams": [
|
| 119 |
+
{
|
| 120 |
+
"name": "params",
|
| 121 |
+
"semantic": "kernel.params",
|
| 122 |
+
"buffer": { "type": "uniform" },
|
| 123 |
+
"struct": { "name": "Params", "fields": [{ "name": "dummy", "type": "u32", "value": 0 }] }
|
| 124 |
+
}
|
| 125 |
+
]
|
| 126 |
+
},
|
| 127 |
+
"variants": [
|
| 128 |
+
{
|
| 129 |
+
"id": "empty_noop",
|
| 130 |
+
"priority": 200,
|
| 131 |
+
"when": ["shapeContract", "numel(shapes.X) == 0"],
|
| 132 |
+
"passes": [
|
| 133 |
+
{
|
| 134 |
+
"id": "noop",
|
| 135 |
+
"name": "MeanVarianceNormalization.Empty",
|
| 136 |
+
"shader": "noop.wgsl.jinja",
|
| 137 |
+
"bindings": "noopParams",
|
| 138 |
+
"dispatch": { "x": 0 }
|
| 139 |
+
}
|
| 140 |
+
]
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"id": "all_axes_flat_split",
|
| 144 |
+
"priority": 120,
|
| 145 |
+
"when": ["shapeContract", "numel(shapes.X) > 0", "allAxesReduced", "numel(shapes.X) >= tunables.FLAT_SPLIT_MIN_ELEMENTS", "flatPathFits"],
|
| 146 |
+
"constants": { "scalar": "dtypes.T" },
|
| 147 |
+
"intermediates": [
|
| 148 |
+
{ "id": "partials", "dtype": "float32", "shape": "[flatSplit, 2]" },
|
| 149 |
+
{ "id": "stats", "dtype": "float32", "shape": "[2]" }
|
| 150 |
+
],
|
| 151 |
+
"passes": [
|
| 152 |
+
{
|
| 153 |
+
"id": "partials",
|
| 154 |
+
"name": "MeanVarianceNormalization.FlatPartials",
|
| 155 |
+
"source": {
|
| 156 |
+
"shader": "norm-flat-splitk-partials.wgsl.jinja",
|
| 157 |
+
"inputs": { "workgroupSize": "maxWorkgroupSize", "split": "flatSplit", "usesF16": "dtypes.T == \"f16\"" }
|
| 158 |
+
},
|
| 159 |
+
"bindings": "flatPartials",
|
| 160 |
+
"dispatch": { "workgroups": "flatSplit" }
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
"id": "combine",
|
| 164 |
+
"name": "MeanVarianceNormalization.FlatCombine",
|
| 165 |
+
"source": {
|
| 166 |
+
"shader": "norm-flat-splitk-combine.wgsl.jinja",
|
| 167 |
+
"inputs": { "split": "flatSplit", "usesF16": "dtypes.T == \"f16\"" }
|
| 168 |
+
},
|
| 169 |
+
"bindings": "flatCombine",
|
| 170 |
+
"dispatch": { "workgroups": 1 }
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"id": "apply",
|
| 174 |
+
"name": "MeanVarianceNormalization.FlatApply",
|
| 175 |
+
"source": {
|
| 176 |
+
"shader": "norm-flat-apply.wgsl.jinja",
|
| 177 |
+
"inputs": { "workgroupSize": "maxWorkgroupSize", "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" }
|
| 178 |
+
},
|
| 179 |
+
"bindings": "flatApply",
|
| 180 |
+
"dispatch": { "threads": "numel(shapes.Y)", "workgroupSize": "maxWorkgroupSize" }
|
| 181 |
+
}
|
| 182 |
+
]
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"id": "serial_rows",
|
| 186 |
+
"priority": 115,
|
| 187 |
+
"when": ["shapeContract", "numel(shapes.X) > 0", "reduceCount <= tunables.SERIAL_MAX_REDUCTION", "rowCount >= tunables.SERIAL_MIN_ROWS", "serialDispatchFits"],
|
| 188 |
+
"constants": { "scalar": "dtypes.T", "ioElement": "dtypes.T" },
|
| 189 |
+
"passes": [
|
| 190 |
+
{
|
| 191 |
+
"id": "main",
|
| 192 |
+
"name": "MeanVarianceNormalization.SerialRows",
|
| 193 |
+
"source": {
|
| 194 |
+
"shader": "mean-variance-normalization-serial-rows.wgsl.jinja",
|
| 195 |
+
"inputs": {
|
| 196 |
+
"xShape": "shapes.X",
|
| 197 |
+
"reduce": ["hasAxis(attrs.axes, 0, ranks.X)", "hasAxis(attrs.axes, 1, ranks.X)", "hasAxis(attrs.axes, 2, ranks.X)", "hasAxis(attrs.axes, 3, ranks.X)", "hasAxis(attrs.axes, 4, ranks.X)", "hasAxis(attrs.axes, 5, ranks.X)"],
|
| 198 |
+
"reduceCount": "reduceCount",
|
| 199 |
+
"workgroupSize": "serialWorkgroupSize",
|
| 200 |
+
"scalar": "dtypes.T",
|
| 201 |
+
"usesF16": "dtypes.T == \"f16\""
|
| 202 |
+
}
|
| 203 |
+
},
|
| 204 |
+
"bindings": "rows",
|
| 205 |
+
"dispatch": { "threads": "rowCount", "workgroupSize": "serialWorkgroupSize" }
|
| 206 |
+
}
|
| 207 |
+
]
|
| 208 |
+
},
|
| 209 |
+
{
|
| 210 |
+
"id": "cooperative_vec4",
|
| 211 |
+
"priority": 110,
|
| 212 |
+
"when": ["shapeContract", "numel(shapes.X) > 0", "reduceCount >= tunables.VEC4_MIN_REDUCTION", "vec4Eligible", "rowDispatchFits", "vectorStorageFits"],
|
| 213 |
+
"constants": {
|
| 214 |
+
"scalar": "dtypes.T",
|
| 215 |
+
"vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"",
|
| 216 |
+
"ioElement": "\"vec4<\" ~ dtypes.T ~ \">\""
|
| 217 |
+
},
|
| 218 |
+
"passes": [
|
| 219 |
+
{
|
| 220 |
+
"id": "main",
|
| 221 |
+
"name": "MeanVarianceNormalization.CooperativeVec4",
|
| 222 |
+
"source": {
|
| 223 |
+
"shader": "mean-variance-normalization-subgroup.wgsl.jinja",
|
| 224 |
+
"inputs": {
|
| 225 |
+
"xShape": "shapes.X",
|
| 226 |
+
"reduce": ["hasAxis(attrs.axes, 0, ranks.X)", "hasAxis(attrs.axes, 1, ranks.X)", "hasAxis(attrs.axes, 2, ranks.X)", "hasAxis(attrs.axes, 3, ranks.X)", "hasAxis(attrs.axes, 4, ranks.X)", "hasAxis(attrs.axes, 5, ranks.X)"],
|
| 227 |
+
"reduceCount": "reduceCount",
|
| 228 |
+
"wg": "vectorWorkgroupSize",
|
| 229 |
+
"minSubgroupSize": "minSubgroupSize",
|
| 230 |
+
"maxSubgroups": "ceilDiv(vectorWorkgroupSize, minSubgroupSize)",
|
| 231 |
+
"scalar": "dtypes.T",
|
| 232 |
+
"vecType": "\"vec4<\" ~ dtypes.T ~ \">\"",
|
| 233 |
+
"usesF16": "dtypes.T == \"f16\"",
|
| 234 |
+
"useSubgroups": "useSubgroups",
|
| 235 |
+
"vectorized": true
|
| 236 |
+
}
|
| 237 |
+
},
|
| 238 |
+
"bindings": "rows",
|
| 239 |
+
"dispatch": { "workgroups": "rowCount" }
|
| 240 |
+
}
|
| 241 |
+
]
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"id": "cooperative_scalar",
|
| 245 |
+
"priority": 100,
|
| 246 |
+
"when": ["shapeContract", "numel(shapes.X) > 0", "rowDispatchFits", "scalarStorageFits"],
|
| 247 |
+
"constants": { "scalar": "dtypes.T", "ioElement": "dtypes.T" },
|
| 248 |
+
"passes": [
|
| 249 |
+
{
|
| 250 |
+
"id": "main",
|
| 251 |
+
"name": "MeanVarianceNormalization.CooperativeScalar",
|
| 252 |
+
"source": {
|
| 253 |
+
"shader": "mean-variance-normalization-subgroup.wgsl.jinja",
|
| 254 |
+
"inputs": {
|
| 255 |
+
"xShape": "shapes.X",
|
| 256 |
+
"reduce": ["hasAxis(attrs.axes, 0, ranks.X)", "hasAxis(attrs.axes, 1, ranks.X)", "hasAxis(attrs.axes, 2, ranks.X)", "hasAxis(attrs.axes, 3, ranks.X)", "hasAxis(attrs.axes, 4, ranks.X)", "hasAxis(attrs.axes, 5, ranks.X)"],
|
| 257 |
+
"reduceCount": "reduceCount",
|
| 258 |
+
"wg": "scalarWorkgroupSize",
|
| 259 |
+
"minSubgroupSize": "minSubgroupSize",
|
| 260 |
+
"maxSubgroups": "ceilDiv(scalarWorkgroupSize, minSubgroupSize)",
|
| 261 |
+
"scalar": "dtypes.T",
|
| 262 |
+
"usesF16": "dtypes.T == \"f16\"",
|
| 263 |
+
"useSubgroups": "useSubgroups",
|
| 264 |
+
"vectorized": false
|
| 265 |
+
}
|
| 266 |
+
},
|
| 267 |
+
"bindings": "rows",
|
| 268 |
+
"dispatch": { "workgroups": "rowCount" }
|
| 269 |
+
}
|
| 270 |
+
]
|
| 271 |
+
}
|
| 272 |
+
]
|
| 273 |
+
}
|
build/webgpu/mean-variance-normalization-serial-rows.wgsl.jinja
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if source.usesF16 %}
|
| 2 |
+
enable f16;
|
| 3 |
+
{% endif %}
|
| 4 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 5 |
+
|
| 6 |
+
// One invocation owns one normalization group. For many short groups, adjacent
|
| 7 |
+
// invocations visit the same reduced coordinate, making their strided scalar
|
| 8 |
+
// loads adjacent across execution lanes.
|
| 9 |
+
//
|
| 10 |
+
// The reduction is shifted by its first value before accumulating moments. This
|
| 11 |
+
// stabilizes the variance calculation while retaining the zero-variance ONNX
|
| 12 |
+
// result as 0/0 = NaN.
|
| 13 |
+
{% macro nd_offset(target, index, reduced, indent) %}
|
| 14 |
+
{% set rank = source.xShape | length %}
|
| 15 |
+
{% for i in range(rank) %}
|
| 16 |
+
{% if source.reduce[i] if reduced else not source.reduce[i] %}
|
| 17 |
+
{% set pa = namespace(v=1) %}
|
| 18 |
+
{% set st = namespace(v=1) %}
|
| 19 |
+
{% for j in range(i + 1, rank) %}
|
| 20 |
+
{% set st.v = st.v * source.xShape[j] %}
|
| 21 |
+
{% if source.reduce[j] if reduced else not source.reduce[j] %}{% set pa.v = pa.v * source.xShape[j] %}{% endif %}
|
| 22 |
+
{% endfor %}
|
| 23 |
+
{{ indent }}{{ target }} = {{ target }} + (({{ index }} / {{ pa.v }}u) % {{ source.xShape[i] }}u) * {{ st.v }}u;
|
| 24 |
+
{% endif %}
|
| 25 |
+
{% endfor %}
|
| 26 |
+
{% endmacro %}
|
| 27 |
+
const WG: u32 = {{ source.workgroupSize }}u;
|
| 28 |
+
const R: u32 = {{ source.reduceCount }}u;
|
| 29 |
+
|
| 30 |
+
@compute @workgroup_size(WG, 1, 1)
|
| 31 |
+
fn main(
|
| 32 |
+
@builtin(global_invocation_id) gid: vec3<u32>,
|
| 33 |
+
@builtin(num_workgroups) nwg: vec3<u32>
|
| 34 |
+
) {
|
| 35 |
+
// `threads` dispatches fold past the WebGPU x-dimension limit into y.
|
| 36 |
+
let row = gid.x + gid.y * nwg.x * WG;
|
| 37 |
+
if (row >= params.rows) {
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
var base_off = 0u;
|
| 42 |
+
{{ nd_offset("base_off", "row", 0, " ") }}
|
| 43 |
+
let shift = f32(x[base_off]);
|
| 44 |
+
var sum_d = 0.0;
|
| 45 |
+
var sum_d2 = 0.0;
|
| 46 |
+
for (var r = 0u; r < R; r = r + 1u) {
|
| 47 |
+
var off = base_off;
|
| 48 |
+
{{ nd_offset("off", "r", 1, " ") }} let d = f32(x[off]) - shift;
|
| 49 |
+
sum_d = sum_d + d;
|
| 50 |
+
sum_d2 = sum_d2 + d * d;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
let mean_d = sum_d / f32(R);
|
| 54 |
+
let variance = max(sum_d2 / f32(R) - mean_d * mean_d, 0.0);
|
| 55 |
+
let mean = shift + mean_d;
|
| 56 |
+
let denom = sqrt(variance);
|
| 57 |
+
|
| 58 |
+
for (var r = 0u; r < R; r = r + 1u) {
|
| 59 |
+
var off = base_off;
|
| 60 |
+
{{ nd_offset("off", "r", 1, " ") }} y[off] = {{ source.scalar }}((f32(x[off]) - mean) / denom);
|
| 61 |
+
}
|
| 62 |
+
}
|
build/webgpu/mean-variance-normalization-subgroup.wgsl.jinja
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if source.usesF16 %}
|
| 2 |
+
enable f16;
|
| 3 |
+
{% endif %}
|
| 4 |
+
{% if source.useSubgroups %}
|
| 5 |
+
enable subgroups;
|
| 6 |
+
{% endif %}
|
| 7 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 8 |
+
|
| 9 |
+
{% macro nd_offset(target, index, reduced, indent) %}
|
| 10 |
+
{% set rank = source.xShape | length %}
|
| 11 |
+
{% for i in range(rank) %}
|
| 12 |
+
{% if source.reduce[i] if reduced else not source.reduce[i] %}
|
| 13 |
+
{% set pa = namespace(v=1) %}
|
| 14 |
+
{% set st = namespace(v=1) %}
|
| 15 |
+
{% for j in range(i + 1, rank) %}
|
| 16 |
+
{% set st.v = st.v * source.xShape[j] %}
|
| 17 |
+
{% if source.reduce[j] if reduced else not source.reduce[j] %}{% set pa.v = pa.v * source.xShape[j] %}{% endif %}
|
| 18 |
+
{% endfor %}
|
| 19 |
+
{{ indent }}{{ target }} = {{ target }} + (({{ index }} / {{ pa.v }}u) % {{ source.xShape[i] }}u) * {{ st.v }}u;
|
| 20 |
+
{% endif %}
|
| 21 |
+
{% endfor %}
|
| 22 |
+
{% endmacro %}
|
| 23 |
+
const WG: u32 = {{ source.wg }}u;
|
| 24 |
+
const R: u32 = {{ source.reduceCount }}u;
|
| 25 |
+
{% if source.vectorized %}
|
| 26 |
+
const RV: u32 = R / 4u;
|
| 27 |
+
|
| 28 |
+
{% endif %}
|
| 29 |
+
{% if source.useSubgroups %}
|
| 30 |
+
{% if source.wg > source.minSubgroupSize %}
|
| 31 |
+
// The device-reported minimum subgroup width bounds cross-subgroup partials.
|
| 32 |
+
const MAX_SG: u32 = {{ source.maxSubgroups }}u;
|
| 33 |
+
var<workgroup> sg_partials: array<vec2<f32>, MAX_SG>;
|
| 34 |
+
{% endif %}
|
| 35 |
+
{% else %}
|
| 36 |
+
var<workgroup> wg_red: array<vec2<f32>, WG>;
|
| 37 |
+
{% endif %}
|
| 38 |
+
|
| 39 |
+
fn reduce_pair(value: vec2<f32>{% if not source.useSubgroups or source.wg > source.minSubgroupSize %}, tid: u32{% endif %}{% if source.useSubgroups and source.wg > source.minSubgroupSize %}, sg_lane: u32, sg_size: u32{% endif %}) -> vec2<f32> {
|
| 40 |
+
{% if source.useSubgroups %}
|
| 41 |
+
let s = vec2<f32>(subgroupAdd(value.x), subgroupAdd(value.y));
|
| 42 |
+
{% if source.wg > source.minSubgroupSize %}
|
| 43 |
+
if (sg_lane == 0u) {
|
| 44 |
+
sg_partials[tid / sg_size] = s;
|
| 45 |
+
}
|
| 46 |
+
workgroupBarrier();
|
| 47 |
+
let num_sg = (WG + sg_size - 1u) / sg_size;
|
| 48 |
+
var total = vec2<f32>(0.0, 0.0);
|
| 49 |
+
for (var i = 0u; i < num_sg; i = i + 1u) {
|
| 50 |
+
total = total + sg_partials[i];
|
| 51 |
+
}
|
| 52 |
+
return total;
|
| 53 |
+
{% else %}
|
| 54 |
+
return s;
|
| 55 |
+
{% endif %}
|
| 56 |
+
{% else %}
|
| 57 |
+
wg_red[tid] = value;
|
| 58 |
+
workgroupBarrier();
|
| 59 |
+
for (var step = WG >> 1u; step > 0u; step = step >> 1u) {
|
| 60 |
+
if (tid < step) {
|
| 61 |
+
wg_red[tid] = wg_red[tid] + wg_red[tid + step];
|
| 62 |
+
}
|
| 63 |
+
workgroupBarrier();
|
| 64 |
+
}
|
| 65 |
+
return wg_red[0];
|
| 66 |
+
{% endif %}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
@compute @workgroup_size(WG, 1, 1)
|
| 70 |
+
fn main(
|
| 71 |
+
@builtin(workgroup_id) wg_id: vec3<u32>,
|
| 72 |
+
@builtin(local_invocation_id) lid: vec3<u32>,
|
| 73 |
+
@builtin(num_workgroups) nwg: vec3<u32>
|
| 74 |
+
{%- if source.useSubgroups and source.wg > source.minSubgroupSize %},
|
| 75 |
+
@builtin(subgroup_invocation_id) sg_lane: u32,
|
| 76 |
+
@builtin(subgroup_size) sg_size: u32
|
| 77 |
+
{%- endif %}
|
| 78 |
+
) {
|
| 79 |
+
let row = wg_id.x + wg_id.y * nwg.x;
|
| 80 |
+
if (row >= params.rows) {
|
| 81 |
+
return;
|
| 82 |
+
}
|
| 83 |
+
let tid = lid.x;
|
| 84 |
+
|
| 85 |
+
// Base offset from the kept-axis coordinates.
|
| 86 |
+
var base_off = 0u;
|
| 87 |
+
{{ nd_offset("base_off", "row", 0, " ") }}
|
| 88 |
+
{% if source.vectorized %}
|
| 89 |
+
let shift = f32(x[base_off / 4u].x);
|
| 90 |
+
{% else %}
|
| 91 |
+
let shift = f32(x[base_off]);
|
| 92 |
+
{% endif %}
|
| 93 |
+
var acc = vec2<f32>(0.0, 0.0);
|
| 94 |
+
{% if source.vectorized %}
|
| 95 |
+
for (var q = tid; q < RV; q = q + WG) {
|
| 96 |
+
let r = q * 4u;
|
| 97 |
+
{% else %}
|
| 98 |
+
for (var r = tid; r < R; r = r + WG) {
|
| 99 |
+
{% endif %}
|
| 100 |
+
var off = base_off;
|
| 101 |
+
{{ nd_offset("off", "r", 1, " ") }}{% if source.vectorized %}
|
| 102 |
+
let d = vec4<f32>(x[off / 4u]) - vec4<f32>(shift);
|
| 103 |
+
acc.x = acc.x + d.x + d.y + d.z + d.w;
|
| 104 |
+
acc.y = acc.y + dot(d, d);
|
| 105 |
+
{% else %}
|
| 106 |
+
let d = f32(x[off]) - shift;
|
| 107 |
+
acc.x = acc.x + d;
|
| 108 |
+
acc.y = acc.y + d * d;
|
| 109 |
+
{% endif %}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
{% if source.useSubgroups %}
|
| 113 |
+
let totals = reduce_pair(acc{% if source.wg > source.minSubgroupSize %}, tid, sg_lane, sg_size{% endif %});
|
| 114 |
+
{% else %}
|
| 115 |
+
let totals = reduce_pair(acc, tid);
|
| 116 |
+
{% endif %}
|
| 117 |
+
let mean_d = totals.x / f32(R);
|
| 118 |
+
let variance = max(totals.y / f32(R) - mean_d * mean_d, 0.0);
|
| 119 |
+
let mean = shift + mean_d;
|
| 120 |
+
let denom = sqrt(variance);
|
| 121 |
+
|
| 122 |
+
{% if source.vectorized %}
|
| 123 |
+
for (var q = tid; q < RV; q = q + WG) {
|
| 124 |
+
let r = q * 4u;
|
| 125 |
+
{% else %}
|
| 126 |
+
for (var r = tid; r < R; r = r + WG) {
|
| 127 |
+
{% endif %}
|
| 128 |
+
var off = base_off;
|
| 129 |
+
{{ nd_offset("off", "r", 1, " ") }}{% if source.vectorized %}
|
| 130 |
+
let v = vec4<f32>(x[off / 4u]);
|
| 131 |
+
y[off / 4u] = {{ source.vecType }}((v - vec4<f32>(mean)) / vec4<f32>(denom));
|
| 132 |
+
{% else %}
|
| 133 |
+
y[off] = {{ source.scalar }}((f32(x[off]) - mean) / denom);
|
| 134 |
+
{% endif %}
|
| 135 |
+
}
|
| 136 |
+
}
|
build/webgpu/metadata.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ai.onnx.MeanVarianceNormalization",
|
| 3 |
+
"id": "_ai_onnx_meanvariancenormalization_webgpu_09532e8",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"backend": { "type": "webgpu" },
|
| 7 |
+
"digest": {
|
| 8 |
+
"algorithm": "sha256",
|
| 9 |
+
"files": {
|
| 10 |
+
"bench.json": "Z7dtgwBXEEaVuYjwvsi+nzdPnqr+T3GbPX6F4A4qUyQ=",
|
| 11 |
+
"manifest.json": "8549q1hb8wFCRzXlrsGTXzEyEVO5WtP64OtKI3Hq6Ug=",
|
| 12 |
+
"mean-variance-normalization-serial-rows.wgsl.jinja": "C/TVvmYhaLeq+yKB4nAK535avgH9kcYaeSZKnRY/Df0=",
|
| 13 |
+
"mean-variance-normalization-subgroup.wgsl.jinja": "eFY8+N5f0/V/npXvheysb002bNEWtJLxNE//2aGzIr0=",
|
| 14 |
+
"noop.wgsl.jinja": "k/5BMD6UO81N7XlF+t4iSKyt3dbtcqNMCru5aUKNBKE=",
|
| 15 |
+
"norm-flat-apply.wgsl.jinja": "O8G9eyv748OmW3GMQjqSFbgsiJ/pW/plJAzAbFGvGNc=",
|
| 16 |
+
"norm-flat-splitk-combine.wgsl.jinja": "uBFuaqUxbf6Qr2uE5huMcdP2+S2nHF+zM3RH0tzAx9o=",
|
| 17 |
+
"norm-flat-splitk-partials.wgsl.jinja": "YwepfH5ztse2kwIz4xhl80Gw5GEnWNMue0oGZUD47p8=",
|
| 18 |
+
"test.json": "OAgHM6FyfQCVSV8h47D92KbimR901cmqk1fTTm4g3q8="
|
| 19 |
+
}
|
| 20 |
+
},
|
| 21 |
+
"provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
|
| 22 |
+
"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.MeanVarianceNormalization" }
|
| 23 |
+
}
|
build/webgpu/noop.wgsl.jinja
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 2 |
+
|
| 3 |
+
@compute @workgroup_size(1)
|
| 4 |
+
fn main() {}
|
build/webgpu/norm-flat-apply.wgsl.jinja
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if source.usesF16 %}
|
| 2 |
+
enable f16;
|
| 3 |
+
{% endif %}
|
| 4 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 5 |
+
|
| 6 |
+
@compute @workgroup_size({{ source.workgroupSize }}, 1, 1)
|
| 7 |
+
fn main(@builtin(global_invocation_id) gid: vec3<u32>,
|
| 8 |
+
@builtin(num_workgroups) nwg: vec3<u32>) {
|
| 9 |
+
let i = gid.x + gid.y * nwg.x * {{ source.workgroupSize }}u;
|
| 10 |
+
if (i >= params.count) {
|
| 11 |
+
return;
|
| 12 |
+
}
|
| 13 |
+
y[i] = {{ source.scalar }}((f32(x[i]) - stats[0]) / stats[1]);
|
| 14 |
+
}
|
build/webgpu/norm-flat-splitk-combine.wgsl.jinja
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if source.usesF16 %}
|
| 2 |
+
enable f16;
|
| 3 |
+
{% endif %}
|
| 4 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 5 |
+
|
| 6 |
+
const SPLIT: u32 = {{ source.split }}u;
|
| 7 |
+
|
| 8 |
+
@compute @workgroup_size(1, 1, 1)
|
| 9 |
+
fn main() {
|
| 10 |
+
var pair = vec2<f32>(0.0);
|
| 11 |
+
for (var part = 0u; part < SPLIT; part = part + 1u) {
|
| 12 |
+
pair = pair + partials[part];
|
| 13 |
+
}
|
| 14 |
+
let shift = f32(x[0]);
|
| 15 |
+
let n = f32(params.count);
|
| 16 |
+
let mean_d = pair.x / n;
|
| 17 |
+
let variance = max(pair.y / n - mean_d * mean_d, 0.0);
|
| 18 |
+
stats[0] = shift + mean_d;
|
| 19 |
+
stats[1] = sqrt(variance);
|
| 20 |
+
}
|
build/webgpu/norm-flat-splitk-partials.wgsl.jinja
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if source.usesF16 %}
|
| 2 |
+
enable f16;
|
| 3 |
+
{% endif %}
|
| 4 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 5 |
+
|
| 6 |
+
const WG: u32 = {{ source.workgroupSize }}u;
|
| 7 |
+
const SPLIT: u32 = {{ source.split }}u;
|
| 8 |
+
|
| 9 |
+
var<workgroup> reduction: array<vec2<f32>, WG>;
|
| 10 |
+
|
| 11 |
+
@compute @workgroup_size(WG, 1, 1)
|
| 12 |
+
fn main(
|
| 13 |
+
@builtin(workgroup_id) wg: vec3<u32>,
|
| 14 |
+
@builtin(local_invocation_id) lid: vec3<u32>
|
| 15 |
+
) {
|
| 16 |
+
let part = wg.x;
|
| 17 |
+
let tid = lid.x;
|
| 18 |
+
let chunk = (params.count + SPLIT - 1u) / SPLIT;
|
| 19 |
+
let start = part * chunk;
|
| 20 |
+
let end = min(start + chunk, params.count);
|
| 21 |
+
|
| 22 |
+
// Shifting by the first element keeps the two-moment variance stable for
|
| 23 |
+
// tensors with a large common offset. Variance is invariant to the shift.
|
| 24 |
+
let shift = f32(x[0]);
|
| 25 |
+
var pair = vec2<f32>(0.0);
|
| 26 |
+
for (var i = start + tid; i < end; i = i + WG) {
|
| 27 |
+
let d = f32(x[i]) - shift;
|
| 28 |
+
pair = pair + vec2<f32>(d, d * d);
|
| 29 |
+
}
|
| 30 |
+
reduction[tid] = pair;
|
| 31 |
+
workgroupBarrier();
|
| 32 |
+
|
| 33 |
+
for (var stride = WG >> 1u; stride > 0u; stride = stride >> 1u) {
|
| 34 |
+
if (tid < stride) {
|
| 35 |
+
reduction[tid] = reduction[tid] + reduction[tid + stride];
|
| 36 |
+
}
|
| 37 |
+
workgroupBarrier();
|
| 38 |
+
}
|
| 39 |
+
if (tid == 0u) {
|
| 40 |
+
partials[part] = reduction[0];
|
| 41 |
+
}
|
| 42 |
+
}
|
build/webgpu/test.json
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.MeanVarianceNormalization",
|
| 3 |
+
"fixtureArrays": {
|
| 4 |
+
"ort_axes_subset_rank5_0_2_4_input_x": [0.6369617, 0.2697867, 0.0409735, 0.0165276, 0.8132702, 0.9127556, 0.6066358, 0.7294966, 0.543625, 0.9350724, 0.8158536, 0.0027385, 0.8574043, 0.0335856, 0.7296554, 0.1756556, 0.8631789, 0.5414612, 0.2997119, 0.4226872, 0.0283197, 0.1242833, 0.6706244, 0.6471895, 0.6153851, 0.3836776, 0.9972099, 0.9808353, 0.685542, 0.6504593, 0.6884467, 0.3889214]
|
| 5 |
+
},
|
| 6 |
+
"cases": [
|
| 7 |
+
{
|
| 8 |
+
"name": "rank5_serial_rows_channel_axis_f32",
|
| 9 |
+
"provenance": {
|
| 10 |
+
"notes": "Exercises the coalesced serial-row path for a realistic channel-only reduction with many independent spatial groups."
|
| 11 |
+
},
|
| 12 |
+
"attrs": { "axes": [1] },
|
| 13 |
+
"inputs": {
|
| 14 |
+
"x": {
|
| 15 |
+
"dtype": "float32",
|
| 16 |
+
"shape": [2, 32, 8, 8, 4],
|
| 17 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.031, "scale": 0.5 }
|
| 18 |
+
}
|
| 19 |
+
},
|
| 20 |
+
"outputs": {
|
| 21 |
+
"y": { "dtype": "float32", "shape": [2, 32, 8, 8, 4], "tolerance": 0.00002, "relTolerance": 0.00002 }
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"name": "vec4_reduced_suffix_w6_hw12_f32",
|
| 26 |
+
"provenance": {
|
| 27 |
+
"notes": "The innermost dimension is not vec4-aligned, but the contiguous reduced HxW suffix is; vectors may safely cross an H/W boundary."
|
| 28 |
+
},
|
| 29 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 30 |
+
"inputs": {
|
| 31 |
+
"x": {
|
| 32 |
+
"dtype": "float32",
|
| 33 |
+
"shape": [2, 3, 2, 6],
|
| 34 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.071, "cosStep": 0.113, "scale": 0.5 }
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 3, 2, 6], "tolerance": 0.00002, "relTolerance": 0.00002 } }
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"name": "dispatch_cliff_rank3_over_16m_elements",
|
| 41 |
+
"attrs": { "axes": [2] },
|
| 42 |
+
"inputs": {
|
| 43 |
+
"x": {
|
| 44 |
+
"dtype": "float32",
|
| 45 |
+
"shape": [8388608, 1, 2],
|
| 46 |
+
"data": { "kind": "cycle", "values": [0.1, 0.9, 0.3, 0.7] }
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
"outputs": { "y": { "dtype": "float32", "shape": [8388608, 1, 2], "tolerance": 0.002 } }
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"name": "subgroup_default_axes_r768",
|
| 53 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 54 |
+
"inputs": {
|
| 55 |
+
"x": {
|
| 56 |
+
"dtype": "float32",
|
| 57 |
+
"shape": [2, 8, 16, 24],
|
| 58 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.21 }
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 8, 16, 24] } }
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"name": "subgroup_keep_inner_axes_0_1",
|
| 65 |
+
"attrs": { "axes": [0, 1] },
|
| 66 |
+
"inputs": {
|
| 67 |
+
"x": {
|
| 68 |
+
"dtype": "float32",
|
| 69 |
+
"shape": [4, 8, 6, 10],
|
| 70 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.29, "cosStep": 0.11 }
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
"outputs": { "y": { "dtype": "float32", "shape": [4, 8, 6, 10] } }
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"name": "subgroup_rank3_axes_0_1_r300",
|
| 77 |
+
"attrs": { "axes": [0, 1] },
|
| 78 |
+
"inputs": {
|
| 79 |
+
"x": {
|
| 80 |
+
"dtype": "float32",
|
| 81 |
+
"shape": [10, 30, 3],
|
| 82 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.19 }
|
| 83 |
+
}
|
| 84 |
+
},
|
| 85 |
+
"outputs": { "y": { "dtype": "float32", "shape": [10, 30, 3] } }
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"name": "ort_gen_rank3_axes_0_2",
|
| 89 |
+
"provenance": {
|
| 90 |
+
"source": "onnxruntime/test/providers/cpu/tensor/gen_mvn_test_data.py",
|
| 91 |
+
"test": "shape [2, 3, 2] reduced over axes [0, 2]",
|
| 92 |
+
"notes": "Small deterministic generator case with a non-contiguous reduction axis set."
|
| 93 |
+
},
|
| 94 |
+
"attrs": { "axes": [0, 2] },
|
| 95 |
+
"inputs": {
|
| 96 |
+
"x": {
|
| 97 |
+
"dtype": "float32",
|
| 98 |
+
"shape": [2, 3, 2],
|
| 99 |
+
"data": {
|
| 100 |
+
"kind": "values",
|
| 101 |
+
"values": [0.6369617, 0.2697867, 0.0409735, 0.0165276, 0.8132702, 0.9127556, 0.6066358, 0.7294966, 0.543625, 0.9350724, 0.8158536, 0.0027385]
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
},
|
| 105 |
+
"outputs": {
|
| 106 |
+
"y": {
|
| 107 |
+
"dtype": "float32",
|
| 108 |
+
"shape": [2, 3, 2],
|
| 109 |
+
"tolerance": 0.00001,
|
| 110 |
+
"data": {
|
| 111 |
+
"kind": "values",
|
| 112 |
+
"values": [0.438269436, -1.67241299, -0.899517715, -0.963612974, 0.48143062, 0.751848817, 0.263942957, 0.970200479, 0.418393701, 1.44473696, 0.488452703, -1.72173214]
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"name": "f32_tiny_variance_axis2_gpu_gap",
|
| 119 |
+
"skipGpu": {
|
| 120 |
+
"category": "permanent",
|
| 121 |
+
"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 in f32; the subnormal reduced-axis variance collapses to zero so normalization yields Infinity."
|
| 122 |
+
},
|
| 123 |
+
"provenance": {
|
| 124 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 125 |
+
"test": "MeanVarianceNormalizationTest.DefaultAxes",
|
| 126 |
+
"notes": "Valid finite inputs with a positive subnormal variance along the reduced axis; output should be finite instead of +/-Infinity."
|
| 127 |
+
},
|
| 128 |
+
"attrs": { "axes": [2] },
|
| 129 |
+
"inputs": {
|
| 130 |
+
"x": {
|
| 131 |
+
"dtype": "float32",
|
| 132 |
+
"shape": [2, 1, 2],
|
| 133 |
+
"data": { "kind": "values", "values": [1e-20, -1e-20, 2e-20, -2e-20] }
|
| 134 |
+
}
|
| 135 |
+
},
|
| 136 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 1, 2], "tolerance": 0.00001 } }
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"name": "f32_tiny_variance_default_axes_rank4_gpu_gap",
|
| 140 |
+
"skipGpu": {
|
| 141 |
+
"category": "permanent",
|
| 142 |
+
"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 in f32; the subnormal reduced variance collapses to zero so normalization is non-finite (rank-4)."
|
| 143 |
+
},
|
| 144 |
+
"provenance": {
|
| 145 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 146 |
+
"test": "MeanVarianceNormalizationTest.DefaultAxes",
|
| 147 |
+
"notes": "Rank-4 default/spatial axes companion: the variance is positive but subnormal, so the normalized output should be finite."
|
| 148 |
+
},
|
| 149 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 150 |
+
"inputs": {
|
| 151 |
+
"x": {
|
| 152 |
+
"dtype": "float32",
|
| 153 |
+
"shape": [1, 1, 2, 2],
|
| 154 |
+
"data": { "kind": "values", "values": [1e-20, -1e-20, 2e-20, -2e-20] }
|
| 155 |
+
}
|
| 156 |
+
},
|
| 157 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 1, 2, 2], "tolerance": 0.00001 } }
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"name": "f32_tiny_variance_default_axes_rank5_gpu_gap",
|
| 161 |
+
"skipGpu": {
|
| 162 |
+
"category": "permanent",
|
| 163 |
+
"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 in f32; the subnormal reduced variance collapses to zero so normalization is non-finite (rank-5)."
|
| 164 |
+
},
|
| 165 |
+
"provenance": {
|
| 166 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 167 |
+
"test": "MeanVarianceNormalizationTest.DefaultAxes",
|
| 168 |
+
"notes": "Rank-5 companion: the reduced variance is positive but subnormal, so normalization should produce finite values."
|
| 169 |
+
},
|
| 170 |
+
"attrs": { "axes": [0, 2, 3, 4] },
|
| 171 |
+
"inputs": {
|
| 172 |
+
"x": {
|
| 173 |
+
"dtype": "float32",
|
| 174 |
+
"shape": [1, 1, 1, 2, 2],
|
| 175 |
+
"data": { "kind": "values", "values": [1e-20, -1e-20, 2e-20, -2e-20] }
|
| 176 |
+
}
|
| 177 |
+
},
|
| 178 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 1, 1, 2, 2], "tolerance": 0.00001 } }
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"name": "subgroup_large_offset_cancellation",
|
| 182 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 183 |
+
"inputs": {
|
| 184 |
+
"x": {
|
| 185 |
+
"dtype": "float32",
|
| 186 |
+
"shape": [1, 2, 2, 4],
|
| 187 |
+
"data": {
|
| 188 |
+
"kind": "values",
|
| 189 |
+
"values": [4000.25, 4001.5, 3999.75, 4000.875, 4001.125, 3998.5, 4000.0, 4002.25, -2000.5, -2001.25, -1999.875, -2000.125, -2002.0, -1998.75, -2000.625, -2001.5]
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
},
|
| 193 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 2, 2, 4] } }
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"name": "default_axes_f32",
|
| 197 |
+
"inputs": {
|
| 198 |
+
"x": {
|
| 199 |
+
"dtype": "float32",
|
| 200 |
+
"shape": [2, 2, 1, 2],
|
| 201 |
+
"data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] }
|
| 202 |
+
}
|
| 203 |
+
},
|
| 204 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 2, 1, 2] } },
|
| 205 |
+
"tolerance": 0.00001
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"name": "spatial_axes_f16",
|
| 209 |
+
"attrs": { "axes": [2, 3] },
|
| 210 |
+
"inputs": {
|
| 211 |
+
"x": {
|
| 212 |
+
"dtype": "float16",
|
| 213 |
+
"shape": [1, 2, 2, 2],
|
| 214 |
+
"data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] }
|
| 215 |
+
}
|
| 216 |
+
},
|
| 217 |
+
"outputs": { "y": { "dtype": "float16", "shape": [1, 2, 2, 2] } },
|
| 218 |
+
"tolerance": 0.002
|
| 219 |
+
},
|
| 220 |
+
{
|
| 221 |
+
"name": "channel_axis_only_f32",
|
| 222 |
+
"attrs": { "axes": [1] },
|
| 223 |
+
"inputs": {
|
| 224 |
+
"x": {
|
| 225 |
+
"dtype": "float32",
|
| 226 |
+
"shape": [1, 3, 2, 2],
|
| 227 |
+
"data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 4.0, 6.0, 8.0, 10.0, -1.0, -2.0, -3.0, -4.0] }
|
| 228 |
+
}
|
| 229 |
+
},
|
| 230 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 3, 2, 2], "tolerance": 0.00001 } }
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"name": "channel_axis_no_subgroup_wg64_tail65_f32",
|
| 234 |
+
"provenance": {
|
| 235 |
+
"notes": "Locks the 65-value channel reduction where the portable reduction uses 64 fully occupied lanes plus one tail value instead of a half-empty 128-lane tree."
|
| 236 |
+
},
|
| 237 |
+
"attrs": { "axes": [1] },
|
| 238 |
+
"inputs": {
|
| 239 |
+
"x": {
|
| 240 |
+
"dtype": "float32",
|
| 241 |
+
"shape": [1, 65, 2, 2],
|
| 242 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.031, "scale": 0.5 }
|
| 243 |
+
}
|
| 244 |
+
},
|
| 245 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 65, 2, 2], "tolerance": 0.00002, "relTolerance": 0.00002 } }
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"name": "negative_spatial_axes_f32",
|
| 249 |
+
"attrs": { "axes": [-2, -1] },
|
| 250 |
+
"inputs": {
|
| 251 |
+
"x": {
|
| 252 |
+
"dtype": "float32",
|
| 253 |
+
"shape": [1, 2, 2, 3],
|
| 254 |
+
"data": { "kind": "values", "values": [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, -1.0, -2.0, -4.0, -8.0, -16.0, -32.0] }
|
| 255 |
+
}
|
| 256 |
+
},
|
| 257 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 2, 2, 3], "tolerance": 0.00001 } }
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"name": "f32_spatial_axes_2x8x32x32",
|
| 261 |
+
"provenance": {
|
| 262 |
+
"notes": "Compact sibling for the spatial-axes MVN benchmark; preserves axes=[2,3] over many channel planes without benchmark-scale tensors."
|
| 263 |
+
},
|
| 264 |
+
"attrs": { "axes": [2, 3] },
|
| 265 |
+
"inputs": {
|
| 266 |
+
"x": {
|
| 267 |
+
"dtype": "float32",
|
| 268 |
+
"shape": [2, 8, 32, 32],
|
| 269 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.011, "cosStep": 0.017, "scale": 0.5 }
|
| 270 |
+
}
|
| 271 |
+
},
|
| 272 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 8, 32, 32], "tolerance": 0.00001, "relTolerance": 0.00001 } }
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"name": "all_axes_f32",
|
| 276 |
+
"attrs": { "axes": [0, 1, 2, 3] },
|
| 277 |
+
"inputs": {
|
| 278 |
+
"x": {
|
| 279 |
+
"dtype": "float32",
|
| 280 |
+
"shape": [1, 2, 2, 2],
|
| 281 |
+
"data": { "kind": "values", "values": [-4.0, -2.0, -1.0, 0.0, 1.0, 2.0, 4.0, 8.0] }
|
| 282 |
+
}
|
| 283 |
+
},
|
| 284 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 2, 2, 2], "tolerance": 0.00001 } }
|
| 285 |
+
},
|
| 286 |
+
{
|
| 287 |
+
"name": "all_axes_zero_variance_nan",
|
| 288 |
+
"attrs": { "axes": [0, 1, 2, 3] },
|
| 289 |
+
"inputs": { "x": { "dtype": "float32", "shape": [1, 2, 2, 2], "data": { "kind": "constant", "value": 7.0 } } },
|
| 290 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 2, 2, 2], "tolerance": 0, "allowNaN": true } }
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"name": "ort_all_axes_rank3",
|
| 294 |
+
"provenance": {
|
| 295 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 296 |
+
"test": "MeanVarianceNormalizationTest.AllAxes",
|
| 297 |
+
"notes": "Covers ORT's rank-3 all-axes shape using the same deterministic value pattern."
|
| 298 |
+
},
|
| 299 |
+
"attrs": { "axes": [0, 1, 2] },
|
| 300 |
+
"inputs": {
|
| 301 |
+
"x": {
|
| 302 |
+
"dtype": "float32",
|
| 303 |
+
"shape": [2, 2, 4],
|
| 304 |
+
"data": {
|
| 305 |
+
"kind": "values",
|
| 306 |
+
"values": [-5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, -5.0, -4.0, -3.0, -2.0, -1.0]
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
},
|
| 310 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 2, 4], "tolerance": 0.00001 } }
|
| 311 |
+
},
|
| 312 |
+
{
|
| 313 |
+
"name": "ort_default_axes_rank4_two_batches",
|
| 314 |
+
"provenance": {
|
| 315 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 316 |
+
"test": "MeanVarianceNormalizationTest.DefaultAxes"
|
| 317 |
+
},
|
| 318 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 319 |
+
"inputs": {
|
| 320 |
+
"x": {
|
| 321 |
+
"dtype": "float32",
|
| 322 |
+
"shape": [2, 2, 2, 3],
|
| 323 |
+
"data": {
|
| 324 |
+
"kind": "values",
|
| 325 |
+
"values": [3.0, -3.0, -1.0, 1.0, 2.0, -1.0, -2.0, -2.0, -2.0, 4.0, 1.0, 4.0, 0.0, -2.0, -2.0, -4.0, 5.0, 7.0, 5.0, -5.0, -5.0, 3.0, 4.0, 4.0]
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
},
|
| 329 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 2, 2, 3], "tolerance": 0.00001 } }
|
| 330 |
+
},
|
| 331 |
+
{
|
| 332 |
+
"name": "ort_all_axes_rank4_two_batches",
|
| 333 |
+
"provenance": {
|
| 334 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 335 |
+
"test": "MeanVarianceNormalizationTest.AllAxes",
|
| 336 |
+
"notes": "Uses ORT's rank-4 all-axes shape with deterministic nonconstant values."
|
| 337 |
+
},
|
| 338 |
+
"attrs": { "axes": [0, 1, 2, 3] },
|
| 339 |
+
"inputs": {
|
| 340 |
+
"x": {
|
| 341 |
+
"dtype": "float32",
|
| 342 |
+
"shape": [2, 2, 2, 3],
|
| 343 |
+
"data": {
|
| 344 |
+
"kind": "values",
|
| 345 |
+
"values": [-5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, -5.0, -4.0]
|
| 346 |
+
}
|
| 347 |
+
}
|
| 348 |
+
},
|
| 349 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 2, 2, 3], "tolerance": 0.00001 } }
|
| 350 |
+
},
|
| 351 |
+
{
|
| 352 |
+
"name": "ort_axes_subset_rank5_0_2_4",
|
| 353 |
+
"provenance": {
|
| 354 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 355 |
+
"test": "MeanVarianceNormalizationTest.AxesSubsets5D"
|
| 356 |
+
},
|
| 357 |
+
"attrs": { "axes": [0, 2, 4] },
|
| 358 |
+
"inputs": {
|
| 359 |
+
"x": {
|
| 360 |
+
"dtype": "float32",
|
| 361 |
+
"shape": [2, 2, 2, 2, 2],
|
| 362 |
+
"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/ort_axes_subset_rank5_0_2_4_input_x" } }
|
| 363 |
+
}
|
| 364 |
+
},
|
| 365 |
+
"outputs": {
|
| 366 |
+
"y": {
|
| 367 |
+
"dtype": "float32",
|
| 368 |
+
"shape": [2, 2, 2, 2, 2],
|
| 369 |
+
"tolerance": 0.00002,
|
| 370 |
+
"data": {
|
| 371 |
+
"kind": "values",
|
| 372 |
+
"values": [0.3508345, -0.7870349, -1.4605863, -1.5525494, 0.8972119, 1.2055154, 0.6673803, 1.1295706, -0.168333, 1.3134559, 0.6321192, -1.7208749, 1.0194501, -2.0990413, 0.3826789, -1.220487, 1.0518781, 0.0548801, -0.4872377, -0.0246164, -1.5353374, -1.2379477, 0.9080993, 0.8199395, 0.1033084, -0.7737996, 1.1569287, 1.1095439, 0.3688809, 0.2360785, 0.2634291, -0.6033379]
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
},
|
| 377 |
+
{
|
| 378 |
+
"name": "ort_axes_subset_rank5_1_2_3",
|
| 379 |
+
"provenance": {
|
| 380 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 381 |
+
"test": "MeanVarianceNormalizationTest.AxesSubsets5D"
|
| 382 |
+
},
|
| 383 |
+
"attrs": { "axes": [1, 2, 3] },
|
| 384 |
+
"inputs": {
|
| 385 |
+
"x": {
|
| 386 |
+
"dtype": "float32",
|
| 387 |
+
"shape": [2, 2, 2, 2, 2],
|
| 388 |
+
"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/ort_axes_subset_rank5_0_2_4_input_x" } }
|
| 389 |
+
}
|
| 390 |
+
},
|
| 391 |
+
"outputs": {
|
| 392 |
+
"y": {
|
| 393 |
+
"dtype": "float32",
|
| 394 |
+
"shape": [2, 2, 2, 2, 2],
|
| 395 |
+
"tolerance": 0.00002,
|
| 396 |
+
"data": {
|
| 397 |
+
"kind": "values",
|
| 398 |
+
"values": [0.0260567, -0.3008327, -2.3950341, -0.9652744, 0.7422773, 1.3860379, -0.0971367, 0.905246, -0.3531062, 1.4445876, 0.7527716, -1.001451, 0.9215636, -0.9205217, 0.4026078, -0.5477917, 0.8924309, 0.1015335, -1.0632416, -0.4004898, -2.0051854, -1.6617567, 0.2241158, 0.5484163, 0.0323921, -0.5653723, 1.3576236, 1.9586404, 0.2758914, 0.5622366, 0.2859732, -0.543208]
|
| 399 |
+
}
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"name": "ort_axes_subset_rank5_0_1_4",
|
| 405 |
+
"provenance": {
|
| 406 |
+
"source": "onnxruntime/test/providers/cpu/tensor/mean_variance_normalization_test.cc",
|
| 407 |
+
"test": "MeanVarianceNormalizationTest.AxesSubsets5D"
|
| 408 |
+
},
|
| 409 |
+
"attrs": { "axes": [0, 1, 4] },
|
| 410 |
+
"inputs": {
|
| 411 |
+
"x": {
|
| 412 |
+
"dtype": "float32",
|
| 413 |
+
"shape": [2, 2, 2, 2, 2],
|
| 414 |
+
"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/ort_axes_subset_rank5_0_2_4_input_x" } }
|
| 415 |
+
}
|
| 416 |
+
},
|
| 417 |
+
"outputs": {
|
| 418 |
+
"y": {
|
| 419 |
+
"dtype": "float32",
|
| 420 |
+
"shape": [2, 2, 2, 2, 2],
|
| 421 |
+
"tolerance": 0.00002,
|
| 422 |
+
"data": {
|
| 423 |
+
"kind": "values",
|
| 424 |
+
"values": [0.1843672, -1.5822912, -1.0098907, -1.0706838, 0.8350127, 1.1118552, 0.1472972, 0.8161319, -0.2647213, 1.6187237, 0.9171133, -1.1049752, 0.9578265, -1.3346525, 0.8169968, -2.1988905, 1.2728089, -0.2751323, -0.3664493, -0.0606291, -1.3493062, -1.0822638, 0.4956413, 0.3680653, 0.0805517, -1.0343067, 1.3681179, 1.3273969, 0.4795772, 0.3819509, 0.5926631, -1.0379052]
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
},
|
| 429 |
+
{
|
| 430 |
+
"name": "onnx_backend_mvn",
|
| 431 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_mvn" },
|
| 432 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 433 |
+
"inputs": {
|
| 434 |
+
"x": {
|
| 435 |
+
"dtype": "float32",
|
| 436 |
+
"shape": [3, 3, 3, 1],
|
| 437 |
+
"data": {
|
| 438 |
+
"kind": "values",
|
| 439 |
+
"values": [0.8439682722091675, 0.5665143728256226, 0.058367349207401276, 0.029163669794797897, 0.12964272499084473, 0.5060197114944458, 0.7953830361366272, 0.9411345720291138, 0.9546573162078857, 0.17730942368507385, 0.46192094683647156, 0.264804482460022, 0.6746842265129089, 0.01665256917476654, 0.6247307658195496, 0.9240844249725342, 0.9722340703010559, 0.1196569874882698, 0.41356155276298523, 0.9129372835159302, 0.5933007597923279, 0.8192993402481079, 0.7862604260444641, 0.11799798905849457, 0.692484438419342, 0.5411941409111023, 0.07513222843408585]
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
},
|
| 443 |
+
"outputs": { "y": { "dtype": "float32", "shape": [3, 3, 3, 1], "tolerance": 0.00002 } }
|
| 444 |
+
},
|
| 445 |
+
{
|
| 446 |
+
"name": "empty_input_zero_dim",
|
| 447 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 448 |
+
"inputs": { "x": { "dtype": "float32", "shape": [0, 8, 16, 24], "data": { "kind": "values", "values": [] } } },
|
| 449 |
+
"outputs": { "y": { "dtype": "float32", "shape": [0, 8, 16, 24], "tolerance": 0 } }
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"name": "f32_vec4_reduce_innermost_only",
|
| 453 |
+
"attrs": { "axes": [3] },
|
| 454 |
+
"inputs": {
|
| 455 |
+
"x": {
|
| 456 |
+
"dtype": "float32",
|
| 457 |
+
"shape": [2, 3, 4, 16],
|
| 458 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.11, "cosStep": 0.23, "scale": 0.5 }
|
| 459 |
+
}
|
| 460 |
+
},
|
| 461 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 3, 4, 16], "tolerance": 0.00002 } }
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
"name": "vec4_dispatch_fold_over_65535_rows_axis3",
|
| 465 |
+
"attrs": { "axes": [3] },
|
| 466 |
+
"inputs": {
|
| 467 |
+
"x": {
|
| 468 |
+
"dtype": "float32",
|
| 469 |
+
"shape": [70000, 1, 1, 8],
|
| 470 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.031, "scale": 0.5 }
|
| 471 |
+
}
|
| 472 |
+
},
|
| 473 |
+
"outputs": { "y": { "dtype": "float32", "shape": [70000, 1, 1, 8], "tolerance": 0.0002 } }
|
| 474 |
+
},
|
| 475 |
+
{
|
| 476 |
+
"name": "reduce_size1_axis_zero_variance_nan_rank4",
|
| 477 |
+
"attrs": { "axes": [2] },
|
| 478 |
+
"inputs": {
|
| 479 |
+
"x": {
|
| 480 |
+
"dtype": "float32",
|
| 481 |
+
"shape": [2, 2, 1, 2],
|
| 482 |
+
"data": { "kind": "values", "values": [1.0, -3.0, 2.5, 100.0, -7.0, 0.0, 42.0, -0.5] }
|
| 483 |
+
}
|
| 484 |
+
},
|
| 485 |
+
"outputs": {
|
| 486 |
+
"y": {
|
| 487 |
+
"dtype": "float32",
|
| 488 |
+
"shape": [2, 2, 1, 2],
|
| 489 |
+
"tolerance": 0,
|
| 490 |
+
"allowNaN": true,
|
| 491 |
+
"data": { "kind": "values", "values": ["NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN"] }
|
| 492 |
+
}
|
| 493 |
+
}
|
| 494 |
+
},
|
| 495 |
+
{
|
| 496 |
+
"name": "vec4_negative_innermost_axis_axis_minus1",
|
| 497 |
+
"attrs": { "axes": [-1] },
|
| 498 |
+
"inputs": {
|
| 499 |
+
"x": {
|
| 500 |
+
"dtype": "float32",
|
| 501 |
+
"shape": [2, 3, 5, 8],
|
| 502 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.19, "cosStep": 0.07, "scale": 0.5 }
|
| 503 |
+
}
|
| 504 |
+
},
|
| 505 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 3, 5, 8], "tolerance": 0.00002 } }
|
| 506 |
+
},
|
| 507 |
+
{
|
| 508 |
+
"name": "kept_channel_dim_zero_empty_rank4",
|
| 509 |
+
"attrs": { "axes": [0, 2, 3] },
|
| 510 |
+
"inputs": { "x": { "dtype": "float32", "shape": [2, 0, 16, 24], "data": { "kind": "values", "values": [] } } },
|
| 511 |
+
"outputs": { "y": { "dtype": "float32", "shape": [2, 0, 16, 24], "tolerance": 0 } }
|
| 512 |
+
},
|
| 513 |
+
{
|
| 514 |
+
"name": "all_axes_flat_splitk_65536",
|
| 515 |
+
"attrs": { "axes": [0, 1, 2, 3] },
|
| 516 |
+
"inputs": {
|
| 517 |
+
"x": {
|
| 518 |
+
"dtype": "float32",
|
| 519 |
+
"shape": [1, 1, 256, 256],
|
| 520 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.013, "cosStep": 0.027, "scale": 0.5 }
|
| 521 |
+
}
|
| 522 |
+
},
|
| 523 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 1, 256, 256], "tolerance": 0.0002 } }
|
| 524 |
+
},
|
| 525 |
+
{
|
| 526 |
+
"name": "all_axes_flat_split_f16_65536",
|
| 527 |
+
"provenance": {
|
| 528 |
+
"notes": "Locks the widened-f32 split-reduction path for large f16 tensors; scratch stays f32 while input/output storage remains f16."
|
| 529 |
+
},
|
| 530 |
+
"attrs": { "axes": [0, 1, 2, 3] },
|
| 531 |
+
"inputs": {
|
| 532 |
+
"x": {
|
| 533 |
+
"dtype": "float16",
|
| 534 |
+
"shape": [1, 1, 256, 256],
|
| 535 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.013, "cosStep": 0.027, "scale": 0.5 }
|
| 536 |
+
}
|
| 537 |
+
},
|
| 538 |
+
"outputs": { "y": { "dtype": "float16", "shape": [1, 1, 256, 256], "tolerance": 0.004, "relTolerance": 0.004 } }
|
| 539 |
+
},
|
| 540 |
+
{
|
| 541 |
+
"name": "rank6_channel_axis_generic_geometry",
|
| 542 |
+
"attrs": { "axes": [1] },
|
| 543 |
+
"inputs": {
|
| 544 |
+
"x": {
|
| 545 |
+
"dtype": "float32",
|
| 546 |
+
"shape": [1, 4, 1, 2, 1, 2],
|
| 547 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.17, "cosStep": 0.29, "scale": 2.0 }
|
| 548 |
+
}
|
| 549 |
+
},
|
| 550 |
+
"outputs": {
|
| 551 |
+
"y": { "dtype": "float32", "shape": [1, 4, 1, 2, 1, 2], "tolerance": 0.00002, "relTolerance": 0.00002 }
|
| 552 |
+
}
|
| 553 |
+
},
|
| 554 |
+
{
|
| 555 |
+
"name": "rank8_channel_axis_generic_geometry",
|
| 556 |
+
"attrs": { "axes": [1] },
|
| 557 |
+
"inputs": {
|
| 558 |
+
"x": {
|
| 559 |
+
"dtype": "float32",
|
| 560 |
+
"shape": [1, 4, 1, 2, 1, 2, 2, 2],
|
| 561 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.27 }
|
| 562 |
+
}
|
| 563 |
+
},
|
| 564 |
+
"outputs": { "y": { "dtype": "float32", "shape": [1, 4, 1, 2, 1, 2, 2, 2], "tolerance": 0.00002 } }
|
| 565 |
+
},
|
| 566 |
+
{
|
| 567 |
+
"name": "rank5_serial_rows_channel_axis_f16",
|
| 568 |
+
"provenance": {
|
| 569 |
+
"notes": "float16 on the coalesced serial-row route, which needs at least SERIAL_MIN_ROWS independent rows and a reduction within SERIAL_MAX_REDUCTION. Only f32 cases and a bench had reached it."
|
| 570 |
+
},
|
| 571 |
+
"attrs": { "axes": [1] },
|
| 572 |
+
"inputs": {
|
| 573 |
+
"x": {
|
| 574 |
+
"dtype": "float16",
|
| 575 |
+
"shape": [2, 32, 8, 8, 4],
|
| 576 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.031, "scale": 0.5 }
|
| 577 |
+
}
|
| 578 |
+
},
|
| 579 |
+
"outputs": { "y": { "dtype": "float16", "shape": [2, 32, 8, 8, 4], "tolerance": 0.02 } }
|
| 580 |
+
}
|
| 581 |
+
]
|
| 582 |
+
}
|