sync 2e7068faf55e
Browse files- README.md +59 -0
- build/webgpu/bench.json +64 -0
- build/webgpu/binary-broadcast-vec4.wgsl.jinja +172 -0
- build/webgpu/binary-broadcast.wgsl.jinja +120 -0
- build/webgpu/binary-vec4.wgsl.jinja +32 -0
- build/webgpu/manifest.json +234 -0
- build/webgpu/metadata.json +20 -0
- build/webgpu/test.json +521 -0
README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
| 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.Sub
|
| 10 |
+
|
| 11 |
+
`ai.onnx` · standard ONNX operator · ONNX opset ≥ 14
|
| 12 |
+
|
| 13 |
+
## Description
|
| 14 |
+
|
| 15 |
+
Performs elementwise binary subtraction (`A - B`) with multidirectional NumPy-style broadcasting support. Inputs must share a compatible numeric element type; the output has the same element type as the inputs.
|
| 16 |
+
|
| 17 |
+
See the [ONNX `Sub` spec](https://onnx.ai/onnx/operators/onnx__Sub.html) for the reference semantics.
|
| 18 |
+
|
| 19 |
+
## Inputs
|
| 20 |
+
|
| 21 |
+
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|
| 22 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 23 |
+
| `A` | `a` | `T` | — | — | First operand. | required |
|
| 24 |
+
| `B` | `b` | `T` | — | — | Second operand. | required |
|
| 25 |
+
|
| 26 |
+
## Outputs
|
| 27 |
+
|
| 28 |
+
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|
| 29 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 30 |
+
| `C` | `c` | `T` | derived | broadcast result of `A` and `B` | Result of the subtraction; has the same element type as the inputs. | required |
|
| 31 |
+
|
| 32 |
+
## Type constraints
|
| 33 |
+
|
| 34 |
+
| Variable | Allowed dtypes |
|
| 35 |
+
| --- | --- |
|
| 36 |
+
| `T` | `float32`, `float16`, `int32`, `uint32`, `int8`, `uint8` |
|
| 37 |
+
|
| 38 |
+
## Files
|
| 39 |
+
|
| 40 |
+
- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)
|
| 41 |
+
- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
|
| 42 |
+
- [`test.json`](build/webgpu/test.json) — correctness cases
|
| 43 |
+
- [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
|
| 44 |
+
- [`binary-broadcast-vec4.wgsl.jinja`](build/webgpu/binary-broadcast-vec4.wgsl.jinja)
|
| 45 |
+
- [`binary-broadcast.wgsl.jinja`](build/webgpu/binary-broadcast.wgsl.jinja)
|
| 46 |
+
- [`binary-vec4.wgsl.jinja`](build/webgpu/binary-vec4.wgsl.jinja)
|
| 47 |
+
|
| 48 |
+
## Use with `@huggingface/kernels`
|
| 49 |
+
|
| 50 |
+
The loader derives every required output's shape and logical dtype from the manifest contract and this call.
|
| 51 |
+
It then allocates the result tensors automatically.
|
| 52 |
+
|
| 53 |
+
The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
|
| 54 |
+
|
| 55 |
+
Replace each `*Data` placeholder with a typed array containing the corresponding input data.
|
| 56 |
+
|
| 57 |
+
```js
|
| 58 |
+
import { getKernel } from "@huggingface/kernels";
|
| 59 |
+
|
| 60 |
+
const kernel = await getKernel("webgpu-kernels/ai.onnx.Sub", { version: 1 });
|
| 61 |
+
const { c } = await kernel({ a: { data: aData, shape: [3] }, b: { data: bData, shape: [3] } });
|
| 62 |
+
```
|
build/webgpu/bench.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Sub",
|
| 3 |
+
"tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] },
|
| 4 |
+
"cases": [
|
| 5 |
+
{
|
| 6 |
+
"name": "sub-f32-4m",
|
| 7 |
+
"preset": "smoke",
|
| 8 |
+
"vars": { "dtype": "float32", "count": 4194304 },
|
| 9 |
+
"inputs": {
|
| 10 |
+
"a": { "shape": [4194304], "dtype": "float32", "dist": "normal", "seed": 302, "scale": 2 },
|
| 11 |
+
"b": { "shape": [4194304], "dtype": "float32", "dist": "normal", "seed": 303, "scale": 2 }
|
| 12 |
+
},
|
| 13 |
+
"outputs": { "c": { "shape": [4194304], "dtype": "float32" } },
|
| 14 |
+
"bench": {
|
| 15 |
+
"primary": true,
|
| 16 |
+
"metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 3" }]
|
| 17 |
+
}
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"name": "sub-f16-4m-same-shape",
|
| 21 |
+
"preset": "smoke",
|
| 22 |
+
"vars": { "dtype": "float16", "count": 4194304 },
|
| 23 |
+
"inputs": {
|
| 24 |
+
"a": { "shape": [4194304], "dtype": "float16", "dist": "normal", "seed": 312, "scale": 2 },
|
| 25 |
+
"b": { "shape": [4194304], "dtype": "float16", "dist": "normal", "seed": 313, "scale": 2 }
|
| 26 |
+
},
|
| 27 |
+
"outputs": { "c": { "shape": [4194304], "dtype": "float16" } },
|
| 28 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 3" }] }
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"name": "sub-f32-rank4-broadcast",
|
| 32 |
+
"preset": "smoke",
|
| 33 |
+
"vars": { "dtype": "float32", "count": 2097152 },
|
| 34 |
+
"inputs": {
|
| 35 |
+
"a": { "shape": [8, 128, 32, 64], "dtype": "float32", "dist": "normal", "seed": 322, "scale": 2 },
|
| 36 |
+
"b": { "shape": [1, 128, 1, 64], "dtype": "float32", "dist": "normal", "seed": 323, "scale": 2 }
|
| 37 |
+
},
|
| 38 |
+
"outputs": { "c": { "shape": [8, 128, 32, 64], "dtype": "float32" } },
|
| 39 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"name": "sub-f32-scalar-rhs-odd-lastdim",
|
| 43 |
+
"preset": "smoke",
|
| 44 |
+
"vars": { "dtype": "float32", "count": 3000009 },
|
| 45 |
+
"inputs": {
|
| 46 |
+
"a": { "shape": [3, 1000003], "dtype": "float32", "dist": "normal", "seed": 332, "scale": 2 },
|
| 47 |
+
"b": { "shape": [], "dtype": "float32", "data": { "kind": "values", "values": [0.5] } }
|
| 48 |
+
},
|
| 49 |
+
"outputs": { "c": { "shape": [3, 1000003], "dtype": "float32" } },
|
| 50 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"name": "sub-f32-broadcast-scalar-fallback-rank3-odd",
|
| 54 |
+
"preset": "stress",
|
| 55 |
+
"vars": { "dtype": "float32", "count": 3407872 },
|
| 56 |
+
"inputs": {
|
| 57 |
+
"a": { "shape": [512, 512, 13], "dtype": "float32", "dist": "normal", "seed": 371, "scale": 2 },
|
| 58 |
+
"b": { "shape": [1, 1, 13], "dtype": "float32", "dist": "normal", "seed": 372, "scale": 2 }
|
| 59 |
+
},
|
| 60 |
+
"outputs": { "c": { "shape": [512, 512, 13], "dtype": "float32", "dist": "empty" } },
|
| 61 |
+
"bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
|
| 62 |
+
}
|
| 63 |
+
]
|
| 64 |
+
}
|
build/webgpu/binary-broadcast-vec4.wgsl.jinja
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% macro offset_fn(fn_name, opShape, opRank, op_same, op_numel, outShape, outRank, out_numel) %}
|
| 2 |
+
fn {{ fn_name }}({% if out_numel != 0 and op_numel != 1 %}out_index: u32{% endif %}) -> u32 {
|
| 3 |
+
{% if out_numel == 0 %}
|
| 4 |
+
return 0u;
|
| 5 |
+
{% elif op_numel == 1 %}
|
| 6 |
+
return 0u;
|
| 7 |
+
{% elif op_same %}
|
| 8 |
+
return out_index;
|
| 9 |
+
{% else %}
|
| 10 |
+
var offset = 0u;
|
| 11 |
+
{% for axis in range(outRank) %}
|
| 12 |
+
{% set op_axis = axis - (outRank - opRank) %}
|
| 13 |
+
{% if op_axis >= 0 and opShape[op_axis] != 1 %}
|
| 14 |
+
{% set c_stride = namespace(value=1) %}
|
| 15 |
+
{% for j in range(axis + 1, outRank) %}
|
| 16 |
+
{% set c_stride.value = c_stride.value * outShape[j] %}
|
| 17 |
+
{% endfor %}
|
| 18 |
+
{% set op_stride = namespace(value=1) %}
|
| 19 |
+
{% for j in range(op_axis + 1, opRank) %}
|
| 20 |
+
{% set op_stride.value = op_stride.value * opShape[j] %}
|
| 21 |
+
{% endfor %}
|
| 22 |
+
{% if c_stride.value == 1 %}
|
| 23 |
+
let coord{{ axis }} = out_index % {{ outShape[axis] }}u;
|
| 24 |
+
{% else %}
|
| 25 |
+
let coord{{ axis }} = (out_index / {{ c_stride.value }}u) % {{ outShape[axis] }}u;
|
| 26 |
+
{% endif %}
|
| 27 |
+
{% if op_stride.value == 1 %}
|
| 28 |
+
offset = offset + coord{{ axis }};
|
| 29 |
+
{% else %}
|
| 30 |
+
offset = offset + coord{{ axis }} * {{ op_stride.value }}u;
|
| 31 |
+
{% endif %}
|
| 32 |
+
{% endif %}
|
| 33 |
+
{% endfor %}
|
| 34 |
+
return offset;
|
| 35 |
+
{% endif %}
|
| 36 |
+
}
|
| 37 |
+
{%- endmacro %}{% macro broadcast_offset_call(fn_name, opShape, outShape, out_index) %}
|
| 38 |
+
{% set op_numel = namespace(value=1) %}
|
| 39 |
+
{% for d in opShape %}{% set op_numel.value = op_numel.value * d %}{% endfor %}
|
| 40 |
+
{% set out_numel = namespace(value=1) %}
|
| 41 |
+
{% for d in outShape %}{% set out_numel.value = out_numel.value * d %}{% endfor %}
|
| 42 |
+
{{ fn_name }}({% if out_numel.value != 0 and op_numel.value != 1 %}{{ out_index }}{% endif %})
|
| 43 |
+
{%- endmacro %}
|
| 44 |
+
|
| 45 |
+
{% if usesF16 %}
|
| 46 |
+
enable f16;
|
| 47 |
+
{% endif %}
|
| 48 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 49 |
+
|
| 50 |
+
// Vec4 broadcast binary op. The same compiled-stride folding as
|
| 51 |
+
// binary-broadcast (offsets are compile-time-strength-reducible), but each
|
| 52 |
+
// thread writes a vec4 of the output. If the output's innermost axis is a
|
| 53 |
+
// multiple of four, each operand uses one base offset. For an
|
| 54 |
+
// odd innermost extent, a vec4 may cross a row boundary: same-shape operands
|
| 55 |
+
// remain contiguous, while broadcast operands compute the four lane offsets
|
| 56 |
+
// independently so their outer broadcast coordinates wrap correctly. Under
|
| 57 |
+
// broadcasting each operand axis is either matched (== output) or 1, so the
|
| 58 |
+
// innermost axis of each operand is exactly one of:
|
| 59 |
+
// - "scalar" : the whole operand is one element -> splat a[0]
|
| 60 |
+
// - "splat" : innermost axis is 1 (broadcast) -> splat a[offset(base)]
|
| 61 |
+
// - "contiguous" : innermost axis matches the output -> vec4 a[offset(base)..+3]
|
| 62 |
+
// Outer-axis broadcasting is captured by offset(base). A fully same-shape
|
| 63 |
+
// operand is vector-bound and loaded directly; broadcast operands remain
|
| 64 |
+
// scalar-bound so their independent lane offsets stay addressable.
|
| 65 |
+
{% set a_numel = namespace(value=1) %}
|
| 66 |
+
{% for d in source.aShape %}
|
| 67 |
+
{% set a_numel.value = a_numel.value * d %}
|
| 68 |
+
{% endfor %}
|
| 69 |
+
{% set b_numel = namespace(value=1) %}
|
| 70 |
+
{% for d in source.bShape %}
|
| 71 |
+
{% set b_numel.value = b_numel.value * d %}
|
| 72 |
+
{% endfor %}
|
| 73 |
+
{% set c_numel = namespace(value=1) %}
|
| 74 |
+
{% for d in source.cShape %}
|
| 75 |
+
{% set c_numel.value = c_numel.value * d %}
|
| 76 |
+
{% endfor %}
|
| 77 |
+
{% set a_same = namespace(value=(source.aRank == source.cRank)) %}
|
| 78 |
+
{% if a_same.value %}
|
| 79 |
+
{% for axis in range(source.cRank) %}
|
| 80 |
+
{% if source.aShape[axis] != source.cShape[axis] %}
|
| 81 |
+
{% set a_same.value = false %}
|
| 82 |
+
{% endif %}
|
| 83 |
+
{% endfor %}
|
| 84 |
+
{% endif %}
|
| 85 |
+
{% set b_same = namespace(value=(source.bRank == source.cRank)) %}
|
| 86 |
+
{% if b_same.value %}
|
| 87 |
+
{% for axis in range(source.cRank) %}
|
| 88 |
+
{% if source.bShape[axis] != source.cShape[axis] %}
|
| 89 |
+
{% set b_same.value = false %}
|
| 90 |
+
{% endif %}
|
| 91 |
+
{% endfor %}
|
| 92 |
+
{% endif %}
|
| 93 |
+
{% set a_inner = source.aShape[source.aRank - 1] if source.aRank >= 1 else 1 %}
|
| 94 |
+
{% set b_inner = source.bShape[source.bRank - 1] if source.bRank >= 1 else 1 %}
|
| 95 |
+
{% set c_inner = source.cShape[source.cRank - 1] %}
|
| 96 |
+
{% set crosses_inner_rows = c_inner % 4 != 0 %}
|
| 97 |
+
{% if a_numel.value == 1 %}{% set a_mode = "scalar" %}
|
| 98 |
+
{% elif a_inner == 1 %}{% set a_mode = "splat" %}
|
| 99 |
+
{% else %}{% set a_mode = "contig" %}{% endif %}
|
| 100 |
+
{% if b_numel.value == 1 %}{% set b_mode = "scalar" %}
|
| 101 |
+
{% elif b_inner == 1 %}{% set b_mode = "splat" %}
|
| 102 |
+
{% else %}{% set b_mode = "contig" %}{% endif %}
|
| 103 |
+
|
| 104 |
+
{% if not a_same.value and a_mode != "scalar" %}
|
| 105 |
+
{{ offset_fn("a_offset", source.aShape, source.aRank, false, a_numel.value, source.cShape, source.cRank, c_numel.value) }}
|
| 106 |
+
{% endif %}
|
| 107 |
+
|
| 108 |
+
{% if not b_same.value and b_mode != "scalar" %}
|
| 109 |
+
{{ offset_fn("b_offset", source.bShape, source.bRank, false, b_numel.value, source.cShape, source.cRank, c_numel.value) }}
|
| 110 |
+
{% endif %}
|
| 111 |
+
|
| 112 |
+
{% set is_int = scalar == "i32" or scalar == "u32" %}
|
| 113 |
+
{% set acc = scalar if is_int else "f32" %}
|
| 114 |
+
// Narrow integer operations wrap modulo the logical dtype width; int8/uint8
|
| 115 |
+
// use i32/u32 storage.
|
| 116 |
+
{% if source.cDtype == "int8" %}
|
| 117 |
+
fn wrap_dtype(v: vec4<i32>) -> vec4<i32> { return (v << vec4<u32>(24u)) >> vec4<u32>(24u); }
|
| 118 |
+
{% set wrap = "wrap_dtype" %}
|
| 119 |
+
{% elif source.cDtype == "uint8" %}
|
| 120 |
+
fn wrap_dtype(v: vec4<u32>) -> vec4<u32> { return v & vec4<u32>(0xFFu); }
|
| 121 |
+
{% set wrap = "wrap_dtype" %}
|
| 122 |
+
{% else %}
|
| 123 |
+
{% set wrap = "" %}
|
| 124 |
+
{% endif %}
|
| 125 |
+
@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
|
| 126 |
+
fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {
|
| 127 |
+
// 2D-folded flat index: gid.y carries the high bits when the element count exceeds the
|
| 128 |
+
// maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills the rest into y).
|
| 129 |
+
let i4 = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
|
| 130 |
+
if (i4 >= params.count) {
|
| 131 |
+
return;
|
| 132 |
+
}
|
| 133 |
+
{% set needsBase = c_numel.value != 0 and ((not a_same.value and a_mode != "scalar") or (not b_same.value and b_mode != "scalar")) %}
|
| 134 |
+
{% if needsBase %}
|
| 135 |
+
let base = i4 * 4u;
|
| 136 |
+
{% endif %}
|
| 137 |
+
{% if a_same.value %}
|
| 138 |
+
let av = vec4<{{ acc }}>(a[i4]);
|
| 139 |
+
{% elif a_mode == "scalar" %}
|
| 140 |
+
let av = vec4<{{ acc }}>({{ acc }}(a[0]));
|
| 141 |
+
{% elif crosses_inner_rows %}
|
| 142 |
+
let av = vec4<{{ acc }}>(
|
| 143 |
+
{{ acc }}(a[{{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "base") }}]),
|
| 144 |
+
{{ acc }}(a[{{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "base + 1u") }}]),
|
| 145 |
+
{{ acc }}(a[{{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "base + 2u") }}]),
|
| 146 |
+
{{ acc }}(a[{{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "base + 3u") }}])
|
| 147 |
+
);
|
| 148 |
+
{% elif a_mode == "splat" %}
|
| 149 |
+
let av = vec4<{{ acc }}>({{ acc }}(a[{{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "base") }}]));
|
| 150 |
+
{% else %}
|
| 151 |
+
let ao = {{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "base") }};
|
| 152 |
+
let av = vec4<{{ acc }}>({{ acc }}(a[ao]), {{ acc }}(a[ao + 1u]), {{ acc }}(a[ao + 2u]), {{ acc }}(a[ao + 3u]));
|
| 153 |
+
{% endif %}
|
| 154 |
+
{% if b_same.value %}
|
| 155 |
+
let bv = vec4<{{ acc }}>(b[i4]);
|
| 156 |
+
{% elif b_mode == "scalar" %}
|
| 157 |
+
let bv = vec4<{{ acc }}>({{ acc }}(b[0]));
|
| 158 |
+
{% elif crosses_inner_rows %}
|
| 159 |
+
let bv = vec4<{{ acc }}>(
|
| 160 |
+
{{ acc }}(b[{{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "base") }}]),
|
| 161 |
+
{{ acc }}(b[{{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "base + 1u") }}]),
|
| 162 |
+
{{ acc }}(b[{{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "base + 2u") }}]),
|
| 163 |
+
{{ acc }}(b[{{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "base + 3u") }}])
|
| 164 |
+
);
|
| 165 |
+
{% elif b_mode == "splat" %}
|
| 166 |
+
let bv = vec4<{{ acc }}>({{ acc }}(b[{{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "base") }}]));
|
| 167 |
+
{% else %}
|
| 168 |
+
let bo = {{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "base") }};
|
| 169 |
+
let bv = vec4<{{ acc }}>({{ acc }}(b[bo]), {{ acc }}(b[bo + 1u]), {{ acc }}(b[bo + 2u]), {{ acc }}(b[bo + 3u]));
|
| 170 |
+
{% endif %}
|
| 171 |
+
c[i4] = {{ wrap }}(vec4<{{ scalar }}>(av - bv));
|
| 172 |
+
}
|
build/webgpu/binary-broadcast.wgsl.jinja
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{% if source.itemsPerInvocation is defined %}
|
| 8 |
+
// Tail-safe scalar x4 keeps vector-like dispatch density without requiring
|
| 9 |
+
// the logical tensor length (or its storage binding) to be vec4 aligned.
|
| 10 |
+
let begin = invocation * {{ source.itemsPerInvocation }}u;
|
| 11 |
+
let end = min(begin + {{ source.itemsPerInvocation }}u, params.count);
|
| 12 |
+
for (var i = begin; i < end; i = i + 1u) {
|
| 13 |
+
{%- else %}
|
| 14 |
+
let i = invocation;
|
| 15 |
+
if (i >= params.count) {
|
| 16 |
+
return;
|
| 17 |
+
}
|
| 18 |
+
{%- endif %}
|
| 19 |
+
{% endmacro %}
|
| 20 |
+
{% macro flat_tail_close() %}
|
| 21 |
+
{% if source.itemsPerInvocation is defined %}
|
| 22 |
+
}
|
| 23 |
+
{% endif %}
|
| 24 |
+
{% endmacro %}
|
| 25 |
+
|
| 26 |
+
{% macro offset_fn(fn_name, opShape, opRank, op_same, op_numel, outShape, outRank, out_numel) %}
|
| 27 |
+
fn {{ fn_name }}({% if out_numel != 0 and op_numel != 1 %}out_index: u32{% endif %}) -> u32 {
|
| 28 |
+
{% if out_numel == 0 %}
|
| 29 |
+
return 0u;
|
| 30 |
+
{% elif op_numel == 1 %}
|
| 31 |
+
return 0u;
|
| 32 |
+
{% elif op_same %}
|
| 33 |
+
return out_index;
|
| 34 |
+
{% else %}
|
| 35 |
+
var offset = 0u;
|
| 36 |
+
{% for axis in range(outRank) %}
|
| 37 |
+
{% set op_axis = axis - (outRank - opRank) %}
|
| 38 |
+
{% if op_axis >= 0 and opShape[op_axis] != 1 %}
|
| 39 |
+
{% set c_stride = namespace(value=1) %}
|
| 40 |
+
{% for j in range(axis + 1, outRank) %}
|
| 41 |
+
{% set c_stride.value = c_stride.value * outShape[j] %}
|
| 42 |
+
{% endfor %}
|
| 43 |
+
{% set op_stride = namespace(value=1) %}
|
| 44 |
+
{% for j in range(op_axis + 1, opRank) %}
|
| 45 |
+
{% set op_stride.value = op_stride.value * opShape[j] %}
|
| 46 |
+
{% endfor %}
|
| 47 |
+
{% if c_stride.value == 1 %}
|
| 48 |
+
let coord{{ axis }} = out_index % {{ outShape[axis] }}u;
|
| 49 |
+
{% else %}
|
| 50 |
+
let coord{{ axis }} = (out_index / {{ c_stride.value }}u) % {{ outShape[axis] }}u;
|
| 51 |
+
{% endif %}
|
| 52 |
+
{% if op_stride.value == 1 %}
|
| 53 |
+
offset = offset + coord{{ axis }};
|
| 54 |
+
{% else %}
|
| 55 |
+
offset = offset + coord{{ axis }} * {{ op_stride.value }}u;
|
| 56 |
+
{% endif %}
|
| 57 |
+
{% endif %}
|
| 58 |
+
{% endfor %}
|
| 59 |
+
return offset;
|
| 60 |
+
{% endif %}
|
| 61 |
+
}
|
| 62 |
+
{%- endmacro %}{% macro broadcast_offset_call(fn_name, opShape, outShape, out_index) %}
|
| 63 |
+
{% set op_numel = namespace(value=1) %}
|
| 64 |
+
{% for d in opShape %}{% set op_numel.value = op_numel.value * d %}{% endfor %}
|
| 65 |
+
{% set out_numel = namespace(value=1) %}
|
| 66 |
+
{% for d in outShape %}{% set out_numel.value = out_numel.value * d %}{% endfor %}
|
| 67 |
+
{{ fn_name }}({% if out_numel.value != 0 and op_numel.value != 1 %}{{ out_index }}{% endif %})
|
| 68 |
+
{%- endmacro %}{% macro broadcast_offset_fn(fn_name, opShape, opRank, outShape, outRank) %}
|
| 69 |
+
{% set op_numel = namespace(value=1) %}
|
| 70 |
+
{% for d in opShape %}
|
| 71 |
+
{% set op_numel.value = op_numel.value * d %}
|
| 72 |
+
{% endfor %}
|
| 73 |
+
{% set out_numel = namespace(value=1) %}
|
| 74 |
+
{% for d in outShape %}
|
| 75 |
+
{% set out_numel.value = out_numel.value * d %}
|
| 76 |
+
{% endfor %}
|
| 77 |
+
{% set op_same = namespace(value=(opRank == outRank)) %}
|
| 78 |
+
{% if op_same.value %}
|
| 79 |
+
{% for axis in range(outRank) %}
|
| 80 |
+
{% if opShape[axis] != outShape[axis] %}
|
| 81 |
+
{% set op_same.value = false %}
|
| 82 |
+
{% endif %}
|
| 83 |
+
{% endfor %}
|
| 84 |
+
{% endif %}
|
| 85 |
+
{{ offset_fn(fn_name, opShape, opRank, op_same.value, op_numel.value, outShape, outRank, out_numel.value) }}
|
| 86 |
+
{%- endmacro %}{% macro binary_broadcast_offsets() %}
|
| 87 |
+
{{ broadcast_offset_fn("a_offset", source.aShape, source.aRank, source.cShape, source.cRank) }}
|
| 88 |
+
|
| 89 |
+
{{ broadcast_offset_fn("b_offset", source.bShape, source.bRank, source.cShape, source.cRank) }}
|
| 90 |
+
{%- endmacro %}
|
| 91 |
+
|
| 92 |
+
{% if usesF16 %}
|
| 93 |
+
enable f16;
|
| 94 |
+
{% endif %}
|
| 95 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
{{ binary_broadcast_offsets() }}
|
| 99 |
+
|
| 100 |
+
{{ flat_tail_open() }}
|
| 101 |
+
{% if scalar == "i32" or scalar == "u32" %}
|
| 102 |
+
let av = a[{{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "i") }}];
|
| 103 |
+
let bv = b[{{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "i") }}];
|
| 104 |
+
let r = av - bv;
|
| 105 |
+
// Narrow integer operations wrap modulo the logical dtype width; int8/uint8
|
| 106 |
+
// use i32/u32 storage.
|
| 107 |
+
{% if source.cDtype == "int8" %}
|
| 108 |
+
c[i] = (r << 24u) >> 24u;
|
| 109 |
+
{% elif source.cDtype == "uint8" %}
|
| 110 |
+
c[i] = r & 0xFFu;
|
| 111 |
+
{% else %}
|
| 112 |
+
c[i] = r;
|
| 113 |
+
{% endif %}
|
| 114 |
+
{% else %}
|
| 115 |
+
let av = f32(a[{{ broadcast_offset_call("a_offset", source.aShape, source.cShape, "i") }}]);
|
| 116 |
+
let bv = f32(b[{{ broadcast_offset_call("b_offset", source.bShape, source.cShape, "i") }}]);
|
| 117 |
+
c[i] = {{ scalar }}(av - bv);
|
| 118 |
+
{% endif %}
|
| 119 |
+
{{ flat_tail_close() -}}
|
| 120 |
+
}
|
build/webgpu/binary-vec4.wgsl.jinja
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% if usesF16 %}
|
| 2 |
+
enable f16;
|
| 3 |
+
{% endif %}
|
| 4 |
+
{{ env.wgsl.resourceDeclarations }}
|
| 5 |
+
|
| 6 |
+
@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
|
| 7 |
+
fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {
|
| 8 |
+
// 2D-folded flat index: gid.y carries the high bits when the element count exceeds the
|
| 9 |
+
// maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills the rest into y).
|
| 10 |
+
let i = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
|
| 11 |
+
if (i >= params.count) {
|
| 12 |
+
return;
|
| 13 |
+
}
|
| 14 |
+
let av = a[i];
|
| 15 |
+
let bv = b[i];
|
| 16 |
+
{% if scalar == "i32" or scalar == "u32" %}
|
| 17 |
+
let r = av - bv;
|
| 18 |
+
// Narrow integer operations wrap modulo the logical dtype width; int8/uint8
|
| 19 |
+
// use i32/u32 storage.
|
| 20 |
+
{% if source.cDtype == "int8" %}
|
| 21 |
+
c[i] = (r << vec4<u32>(24u)) >> vec4<u32>(24u);
|
| 22 |
+
{% elif source.cDtype == "uint8" %}
|
| 23 |
+
c[i] = r & vec4<u32>(0xFFu);
|
| 24 |
+
{% else %}
|
| 25 |
+
c[i] = r;
|
| 26 |
+
{% endif %}
|
| 27 |
+
{% elif scalar == "f16" %}
|
| 28 |
+
c[i] = vec4<f16>(vec4<f32>(av) - vec4<f32>(bv));
|
| 29 |
+
{% else %}
|
| 30 |
+
c[i] = av - bv;
|
| 31 |
+
{% endif %}
|
| 32 |
+
}
|
build/webgpu/manifest.json
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"domain": "ai.onnx",
|
| 3 |
+
"name": "Sub",
|
| 4 |
+
"sinceVersion": 14,
|
| 5 |
+
"description": "Performs elementwise binary subtraction (`A - B`) with multidirectional NumPy-style broadcasting support. Inputs must share a compatible numeric element type; the output has the same element type as the inputs.",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{ "role": "A", "dtype": "T", "description": "First operand." },
|
| 8 |
+
{ "role": "B", "dtype": "T", "description": "Second operand." }
|
| 9 |
+
],
|
| 10 |
+
"outputs": [
|
| 11 |
+
{
|
| 12 |
+
"role": "C",
|
| 13 |
+
"dtype": "T",
|
| 14 |
+
"rank": "max(ranks.A, ranks.B)",
|
| 15 |
+
"description": "Result of the subtraction; has the same element type as the inputs.",
|
| 16 |
+
"shape": "broadcastShape(shapes.A, shapes.B)"
|
| 17 |
+
}
|
| 18 |
+
],
|
| 19 |
+
"typeConstraints": { "T": ["float32", "float16", "int32", "uint32", "int8", "uint8"] },
|
| 20 |
+
"args": {
|
| 21 |
+
"a": { "kind": "tensor", "semantic": "A", "role": "input" },
|
| 22 |
+
"b": { "kind": "tensor", "semantic": "B", "role": "input" },
|
| 23 |
+
"c": { "kind": "tensor", "semantic": "C", "role": "output" }
|
| 24 |
+
},
|
| 25 |
+
"tunables": { "WORKGROUP_SIZE": 256 },
|
| 26 |
+
"variants": [
|
| 27 |
+
{
|
| 28 |
+
"id": "same_shape_vec4",
|
| 29 |
+
"priority": 20,
|
| 30 |
+
"when": ["sameShape(shapes.A, shapes.C)", "sameShape(shapes.B, shapes.C)", "numel(shapes.C) > 0", "numel(shapes.C) % 4 == 0", "f16Ok(dtypes.T)"],
|
| 31 |
+
"constants": {
|
| 32 |
+
"scalar": "dtypes.T",
|
| 33 |
+
"vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"",
|
| 34 |
+
"usesF16": "dtypes.T == \"f16\""
|
| 35 |
+
},
|
| 36 |
+
"passes": [
|
| 37 |
+
{
|
| 38 |
+
"id": "main",
|
| 39 |
+
"name": "Sub.vec4",
|
| 40 |
+
"source": { "shader": "binary-vec4.wgsl.jinja", "inputs": { "op": "\"sub\"", "cDtype": "tensorDtypes.C" } },
|
| 41 |
+
"bindings": [
|
| 42 |
+
{
|
| 43 |
+
"name": "a",
|
| 44 |
+
"arg": "a",
|
| 45 |
+
"semantic": "A",
|
| 46 |
+
"buffer": { "type": "read-only-storage" },
|
| 47 |
+
"elementType": "$vectorScalar"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "b",
|
| 51 |
+
"arg": "b",
|
| 52 |
+
"semantic": "B",
|
| 53 |
+
"buffer": { "type": "read-only-storage" },
|
| 54 |
+
"elementType": "$vectorScalar"
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"name": "c",
|
| 58 |
+
"arg": "c",
|
| 59 |
+
"semantic": "C",
|
| 60 |
+
"buffer": { "type": "storage" },
|
| 61 |
+
"elementType": "$vectorScalar"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"name": "params",
|
| 65 |
+
"semantic": "kernel.params",
|
| 66 |
+
"buffer": { "type": "uniform" },
|
| 67 |
+
"struct": {
|
| 68 |
+
"name": "Params",
|
| 69 |
+
"fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C) / 4" }]
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
],
|
| 73 |
+
"dispatch": { "threads": "numel(shapes.C) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 74 |
+
}
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"id": "broadcast_vec4",
|
| 79 |
+
"when": ["ranks.A <= ranks.C", "ranks.B <= ranks.C", "ranks.C >= 1", "numel(shapes.C) % 4 == 0", "numel(shapes.C) >= 4", "f16Ok(dtypes.T)"],
|
| 80 |
+
"constants": {
|
| 81 |
+
"scalar": "dtypes.T",
|
| 82 |
+
"aElement": "\"vec4<\" ~ dtypes.T ~ \">\" if sameShape(shapes.A, shapes.C) else dtypes.T",
|
| 83 |
+
"bElement": "\"vec4<\" ~ dtypes.T ~ \">\" if sameShape(shapes.B, shapes.C) else dtypes.T",
|
| 84 |
+
"vec4Scalar": "\"vec4<\" ~ dtypes.T ~ \">\"",
|
| 85 |
+
"usesF16": "dtypes.T == \"f16\""
|
| 86 |
+
},
|
| 87 |
+
"passes": [
|
| 88 |
+
{
|
| 89 |
+
"id": "main",
|
| 90 |
+
"name": "Sub",
|
| 91 |
+
"source": {
|
| 92 |
+
"shader": "binary-broadcast-vec4.wgsl.jinja",
|
| 93 |
+
"inputs": {
|
| 94 |
+
"aShape": "shapes.A",
|
| 95 |
+
"bShape": "shapes.B",
|
| 96 |
+
"cShape": "shapes.C",
|
| 97 |
+
"aRank": "ranks.A",
|
| 98 |
+
"bRank": "ranks.B",
|
| 99 |
+
"cRank": "ranks.C",
|
| 100 |
+
"op": "\"sub\"",
|
| 101 |
+
"cDtype": "tensorDtypes.C"
|
| 102 |
+
}
|
| 103 |
+
},
|
| 104 |
+
"bindings": [
|
| 105 |
+
{
|
| 106 |
+
"name": "a",
|
| 107 |
+
"arg": "a",
|
| 108 |
+
"semantic": "A",
|
| 109 |
+
"buffer": { "type": "read-only-storage" },
|
| 110 |
+
"elementType": "$aElement"
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"name": "b",
|
| 114 |
+
"arg": "b",
|
| 115 |
+
"semantic": "B",
|
| 116 |
+
"buffer": { "type": "read-only-storage" },
|
| 117 |
+
"elementType": "$bElement"
|
| 118 |
+
},
|
| 119 |
+
{ "name": "c", "arg": "c", "semantic": "C", "buffer": { "type": "storage" }, "elementType": "$vec4Scalar" },
|
| 120 |
+
{
|
| 121 |
+
"name": "params",
|
| 122 |
+
"semantic": "kernel.params",
|
| 123 |
+
"buffer": { "type": "uniform" },
|
| 124 |
+
"struct": {
|
| 125 |
+
"name": "Params",
|
| 126 |
+
"fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C) / 4" }]
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
],
|
| 130 |
+
"dispatch": { "threads": "numel(shapes.C) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 131 |
+
}
|
| 132 |
+
],
|
| 133 |
+
"priority": 10
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"id": "same_shape_scalar_x4",
|
| 137 |
+
"priority": 15,
|
| 138 |
+
"when": ["sameShape(shapes.A, shapes.C)", "sameShape(shapes.B, shapes.C)", "numel(shapes.C) > 0", "numel(shapes.C) % 4 != 0", "f16Ok(dtypes.T)"],
|
| 139 |
+
"constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" },
|
| 140 |
+
"passes": [
|
| 141 |
+
{
|
| 142 |
+
"id": "main",
|
| 143 |
+
"name": "Sub",
|
| 144 |
+
"source": {
|
| 145 |
+
"shader": "binary-broadcast.wgsl.jinja",
|
| 146 |
+
"inputs": {
|
| 147 |
+
"aShape": "shapes.A",
|
| 148 |
+
"bShape": "shapes.B",
|
| 149 |
+
"cShape": "shapes.C",
|
| 150 |
+
"aRank": "ranks.A",
|
| 151 |
+
"bRank": "ranks.B",
|
| 152 |
+
"cRank": "ranks.C",
|
| 153 |
+
"op": "\"sub\"",
|
| 154 |
+
"cDtype": "tensorDtypes.C",
|
| 155 |
+
"itemsPerInvocation": 4
|
| 156 |
+
}
|
| 157 |
+
},
|
| 158 |
+
"bindings": [
|
| 159 |
+
{
|
| 160 |
+
"name": "a",
|
| 161 |
+
"arg": "a",
|
| 162 |
+
"semantic": "A",
|
| 163 |
+
"buffer": { "type": "read-only-storage" },
|
| 164 |
+
"elementType": "$scalar"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"name": "b",
|
| 168 |
+
"arg": "b",
|
| 169 |
+
"semantic": "B",
|
| 170 |
+
"buffer": { "type": "read-only-storage" },
|
| 171 |
+
"elementType": "$scalar"
|
| 172 |
+
},
|
| 173 |
+
{ "name": "c", "arg": "c", "semantic": "C", "buffer": { "type": "storage" }, "elementType": "$scalar" },
|
| 174 |
+
{
|
| 175 |
+
"name": "params",
|
| 176 |
+
"semantic": "kernel.params",
|
| 177 |
+
"buffer": { "type": "uniform" },
|
| 178 |
+
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C)" }] }
|
| 179 |
+
}
|
| 180 |
+
],
|
| 181 |
+
"dispatch": { "threads": "ceilDiv(numel(shapes.C), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 182 |
+
}
|
| 183 |
+
]
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
"id": "broadcast",
|
| 187 |
+
"when": ["ranks.A <= ranks.C", "ranks.B <= ranks.C", "f16Ok(dtypes.T)"],
|
| 188 |
+
"constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" },
|
| 189 |
+
"passes": [
|
| 190 |
+
{
|
| 191 |
+
"id": "main",
|
| 192 |
+
"name": "Sub",
|
| 193 |
+
"source": {
|
| 194 |
+
"shader": "binary-broadcast.wgsl.jinja",
|
| 195 |
+
"inputs": {
|
| 196 |
+
"aShape": "shapes.A",
|
| 197 |
+
"bShape": "shapes.B",
|
| 198 |
+
"cShape": "shapes.C",
|
| 199 |
+
"aRank": "ranks.A",
|
| 200 |
+
"bRank": "ranks.B",
|
| 201 |
+
"cRank": "ranks.C",
|
| 202 |
+
"op": "\"sub\"",
|
| 203 |
+
"cDtype": "tensorDtypes.C"
|
| 204 |
+
}
|
| 205 |
+
},
|
| 206 |
+
"bindings": [
|
| 207 |
+
{
|
| 208 |
+
"name": "a",
|
| 209 |
+
"arg": "a",
|
| 210 |
+
"semantic": "A",
|
| 211 |
+
"buffer": { "type": "read-only-storage" },
|
| 212 |
+
"elementType": "$scalar"
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"name": "b",
|
| 216 |
+
"arg": "b",
|
| 217 |
+
"semantic": "B",
|
| 218 |
+
"buffer": { "type": "read-only-storage" },
|
| 219 |
+
"elementType": "$scalar"
|
| 220 |
+
},
|
| 221 |
+
{ "name": "c", "arg": "c", "semantic": "C", "buffer": { "type": "storage" }, "elementType": "$scalar" },
|
| 222 |
+
{
|
| 223 |
+
"name": "params",
|
| 224 |
+
"semantic": "kernel.params",
|
| 225 |
+
"buffer": { "type": "uniform" },
|
| 226 |
+
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C)" }] }
|
| 227 |
+
}
|
| 228 |
+
],
|
| 229 |
+
"dispatch": { "threads": "numel(shapes.C)", "workgroupSize": "tunables.WORKGROUP_SIZE" }
|
| 230 |
+
}
|
| 231 |
+
]
|
| 232 |
+
}
|
| 233 |
+
]
|
| 234 |
+
}
|
build/webgpu/metadata.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ai.onnx.Sub",
|
| 3 |
+
"id": "_ai_onnx_sub_webgpu_d5e0c86",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"backend": { "type": "webgpu" },
|
| 7 |
+
"digest": {
|
| 8 |
+
"algorithm": "sha256",
|
| 9 |
+
"files": {
|
| 10 |
+
"bench.json": "lWLk58oMaDoHDeONhX1uGhYlFv2T6DHU9iZLWHsLcEs=",
|
| 11 |
+
"binary-broadcast-vec4.wgsl.jinja": "RwqJ+9q1E9Hmx4WPB8XnYYgYVhaO4X6vHghv0iHkXOE=",
|
| 12 |
+
"binary-broadcast.wgsl.jinja": "/zVxgYa7b3kFuPbdgujCkcuhEnLjg29JQ4xES9ouF/c=",
|
| 13 |
+
"binary-vec4.wgsl.jinja": "VtSzBDt9S766ph3QPveK+YJgNlh/FBOKvznRIQWfKIg=",
|
| 14 |
+
"manifest.json": "TcwriQEmCNeWZi1rnkAYhJTf3vlf3G98yIF0ETvAJ3w=",
|
| 15 |
+
"test.json": "/HGe/vteCb46Xnc+SHBVlJ6Xcpv+Jx+rXV+GXJARgD8="
|
| 16 |
+
}
|
| 17 |
+
},
|
| 18 |
+
"provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
|
| 19 |
+
"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.Sub" }
|
| 20 |
+
}
|
build/webgpu/test.json
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op": "ai.onnx.Sub",
|
| 3 |
+
"fixtureArrays": {
|
| 4 |
+
"onnx_backend_sub_input_a": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, -0.9772778749465942, 0.9500884413719177, -0.15135720372200012, -0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, -0.2051582634449005, 0.3130677044391632, -0.8540957570075989, -2.5529897212982178, 0.653618574142456, 0.8644362092018127, -0.7421650290489197, 2.269754648208618, -1.4543657302856445, 0.04575851559638977, -0.18718385696411133, 1.5327792167663574, 1.4693588018417358, 0.154947429895401, 0.37816253304481506, -0.8877857327461243, -1.980796456336975, -0.34791216254234314, 0.15634897351264954, 1.2302906513214111, 1.202379822731018, -0.38732680678367615, -0.302302747964859, -1.0485529899597168, -1.420017957687378, -1.7062702178955078, 1.950775384902954, -0.5096521973609924, -0.4380742907524109, -1.2527953386306763, 0.7774903774261475, -1.6138978004455566, -0.21274028718471527, -0.8954665660858154, 0.38690251111984253, -0.5108051300048828, -1.18063223361969, -0.02818222902715206, 0.4283318817615509, 0.06651721894741058, 0.30247190594673157, -0.6343221068382263, -0.3627411723136902],
|
| 5 |
+
"f32_sub_exact_cancellation_broadcast_input_a": [1, 2, 3, 4, 5, 6, 7, 8, 10, 20, 30, 40, 50, 60, 70, 80, 100, 200, 300, 400, 500, 600, 700, 800]
|
| 6 |
+
},
|
| 7 |
+
"cases": [
|
| 8 |
+
{
|
| 9 |
+
"name": "same_shape",
|
| 10 |
+
"inputs": {
|
| 11 |
+
"a": { "dtype": "float32", "shape": [19], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 } },
|
| 12 |
+
"b": { "dtype": "float32", "shape": [19], "data": { "kind": "fillFloat32", "sinStep": 0.31, "cosStep": 0.07 } }
|
| 13 |
+
},
|
| 14 |
+
"outputs": { "c": { "dtype": "float32", "shape": [19], "tolerance": 0.000001 } }
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"name": "f32_subnormal_identity_and_cancellation_gpu_gap",
|
| 18 |
+
"skipGpu": {
|
| 19 |
+
"category": "permanent",
|
| 20 |
+
"reason": "Portable WGSL floating-point semantics do not guarantee preservation of the subnormal values required by this fixture. Backend evidence: Metal flushes float32 subnormals to zero; the preserved-subnormal lanes cannot be reproduced on GPU."
|
| 21 |
+
},
|
| 22 |
+
"provenance": {
|
| 23 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 24 |
+
"test": "MathOpTest.Sub_float",
|
| 25 |
+
"notes": "Finite subnormal minuends/subtrahends are valid float32 values; subtracting zero preserves them while equal finite values cancel exactly."
|
| 26 |
+
},
|
| 27 |
+
"inputs": {
|
| 28 |
+
"a": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [1e-40, -1e-40, 0.0, 1e-39] } },
|
| 29 |
+
"b": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [0.0, 0.0, -1e-40, 1e-39] } }
|
| 30 |
+
},
|
| 31 |
+
"outputs": {
|
| 32 |
+
"c": {
|
| 33 |
+
"dtype": "float32",
|
| 34 |
+
"shape": [4],
|
| 35 |
+
"tolerance": 0,
|
| 36 |
+
"data": { "kind": "values", "values": [1e-40, -1e-40, 1e-40, 0.0] }
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"name": "f32_subnormal_identity_and_cancellation_scalar_gpu_gap",
|
| 42 |
+
"skipGpu": {
|
| 43 |
+
"category": "permanent",
|
| 44 |
+
"reason": "Portable WGSL floating-point semantics do not guarantee preservation of the subnormal values required by this fixture. Backend evidence: Metal flushes float32 subnormals to zero; the preserved-subnormal lanes cannot be reproduced on GPU."
|
| 45 |
+
},
|
| 46 |
+
"provenance": {
|
| 47 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 48 |
+
"test": "MathOpTest.Sub_float",
|
| 49 |
+
"notes": "Scalar-path companion: subtracting zero should preserve finite subnormal lanes while equal finite values cancel."
|
| 50 |
+
},
|
| 51 |
+
"inputs": {
|
| 52 |
+
"a": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1e-40, -1e-40, 1e-39] } },
|
| 53 |
+
"b": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [0.0, 0.0, 1e-39] } }
|
| 54 |
+
},
|
| 55 |
+
"outputs": {
|
| 56 |
+
"c": {
|
| 57 |
+
"dtype": "float32",
|
| 58 |
+
"shape": [3],
|
| 59 |
+
"tolerance": 0,
|
| 60 |
+
"data": { "kind": "values", "values": [1e-40, -1e-40, 0.0] }
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"name": "float16_vec4_same_shape",
|
| 66 |
+
"inputs": {
|
| 67 |
+
"a": {
|
| 68 |
+
"dtype": "float16",
|
| 69 |
+
"shape": [8],
|
| 70 |
+
"data": { "kind": "values", "values": [1.0, -2.0, 3.5, -4.0, 0.25, 10.0, -100.0, 0.001] }
|
| 71 |
+
},
|
| 72 |
+
"b": {
|
| 73 |
+
"dtype": "float16",
|
| 74 |
+
"shape": [8],
|
| 75 |
+
"data": { "kind": "values", "values": [0.5, 2.0, -1.5, 4.0, 0.75, -5.0, 100.0, -0.001] }
|
| 76 |
+
}
|
| 77 |
+
},
|
| 78 |
+
"outputs": { "c": { "dtype": "float16", "shape": [8], "tolerance": 0.001 } }
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"name": "rank4_broadcast",
|
| 82 |
+
"inputs": {
|
| 83 |
+
"a": {
|
| 84 |
+
"dtype": "float32",
|
| 85 |
+
"shape": [2, 3, 4, 5],
|
| 86 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.19 }
|
| 87 |
+
},
|
| 88 |
+
"b": {
|
| 89 |
+
"dtype": "float32",
|
| 90 |
+
"shape": [1, 3, 1, 5],
|
| 91 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.29, "cosStep": 0.11, "scale": 0.2 }
|
| 92 |
+
}
|
| 93 |
+
},
|
| 94 |
+
"outputs": { "c": { "dtype": "float32", "shape": [2, 3, 4, 5], "tolerance": 0.000001 } }
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"name": "rank0_lhs_scalar_broadcast",
|
| 98 |
+
"inputs": {
|
| 99 |
+
"a": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [10.0] } },
|
| 100 |
+
"b": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [1.0, -2.0, 3.5, 10.0] } }
|
| 101 |
+
},
|
| 102 |
+
"outputs": { "c": { "dtype": "float32", "shape": [4], "tolerance": 0.000001 } }
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"name": "uint32_exact_above_float24",
|
| 106 |
+
"inputs": {
|
| 107 |
+
"a": {
|
| 108 |
+
"dtype": "uint32",
|
| 109 |
+
"shape": [4],
|
| 110 |
+
"data": { "kind": "values", "values": [16777217, 4000000001, 4294967295, 123456789] }
|
| 111 |
+
},
|
| 112 |
+
"b": { "dtype": "uint32", "shape": [4], "data": { "kind": "values", "values": [1, 3, 255, 10] } }
|
| 113 |
+
},
|
| 114 |
+
"outputs": { "c": { "dtype": "uint32", "shape": [4] } }
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"name": "ort_float_3x3",
|
| 118 |
+
"provenance": {
|
| 119 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 120 |
+
"test": "MathOpTest.Sub_float"
|
| 121 |
+
},
|
| 122 |
+
"inputs": {
|
| 123 |
+
"a": {
|
| 124 |
+
"dtype": "float32",
|
| 125 |
+
"shape": [3, 3],
|
| 126 |
+
"data": { "kind": "values", "values": [1.0, 2.0, -1.0, 0.0, 1.5, -100.0, -5.4, 9.3, -10000.0] }
|
| 127 |
+
},
|
| 128 |
+
"b": {
|
| 129 |
+
"dtype": "float32",
|
| 130 |
+
"shape": [3, 3],
|
| 131 |
+
"data": { "kind": "values", "values": [-1.0, 4.4, 432.3, 0.0, 3.5, 64.0, -5.4, 9.3, 10000.0] }
|
| 132 |
+
}
|
| 133 |
+
},
|
| 134 |
+
"outputs": { "c": { "dtype": "float32", "shape": [3, 3], "tolerance": 0.000001 } }
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"name": "ort_int8_vector",
|
| 138 |
+
"provenance": {
|
| 139 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 140 |
+
"test": "MathOpTest.Sub_int8"
|
| 141 |
+
},
|
| 142 |
+
"inputs": {
|
| 143 |
+
"a": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [1, 5, 6] } },
|
| 144 |
+
"b": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [4, 5, 3] } }
|
| 145 |
+
},
|
| 146 |
+
"outputs": { "c": { "dtype": "int8", "shape": [3], "tolerance": 0 } }
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"name": "ort_int8_overflow_wrap",
|
| 150 |
+
"provenance": {
|
| 151 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 152 |
+
"test": "MathOpTest.Sub_int8",
|
| 153 |
+
"notes": "Extends ORT's int8 Sub coverage with signed overflow values that must wrap to logical int8 width."
|
| 154 |
+
},
|
| 155 |
+
"inputs": {
|
| 156 |
+
"a": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [-128, 127, -100] } },
|
| 157 |
+
"b": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [1, -1, 30] } }
|
| 158 |
+
},
|
| 159 |
+
"outputs": { "c": { "dtype": "int8", "shape": [3], "tolerance": 0 } }
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"name": "ort_int32_vector",
|
| 163 |
+
"provenance": {
|
| 164 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 165 |
+
"test": "MathOpTest.Sub_int32"
|
| 166 |
+
},
|
| 167 |
+
"inputs": {
|
| 168 |
+
"a": { "dtype": "int32", "shape": [3], "data": { "kind": "values", "values": [1, 4, 3] } },
|
| 169 |
+
"b": { "dtype": "int32", "shape": [3], "data": { "kind": "values", "values": [4, 2, 4] } }
|
| 170 |
+
},
|
| 171 |
+
"outputs": { "c": { "dtype": "int32", "shape": [3], "tolerance": 0 } }
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"name": "ort_uint8_vector",
|
| 175 |
+
"provenance": {
|
| 176 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 177 |
+
"test": "MathOpTest.Sub_uint8"
|
| 178 |
+
},
|
| 179 |
+
"inputs": {
|
| 180 |
+
"a": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [4, 5, 6] } },
|
| 181 |
+
"b": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [1, 5, 3] } }
|
| 182 |
+
},
|
| 183 |
+
"outputs": { "c": { "dtype": "uint8", "shape": [3], "tolerance": 0 } }
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
"name": "ort_uint8_overflow_wrap",
|
| 187 |
+
"provenance": {
|
| 188 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 189 |
+
"test": "MathOpTest.Sub_uint8",
|
| 190 |
+
"notes": "Extends ORT's uint8 Sub coverage with underflow values that must wrap to logical uint8 width."
|
| 191 |
+
},
|
| 192 |
+
"inputs": {
|
| 193 |
+
"a": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [0, 10, 200] } },
|
| 194 |
+
"b": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [1, 20, 250] } }
|
| 195 |
+
},
|
| 196 |
+
"outputs": { "c": { "dtype": "uint8", "shape": [3], "tolerance": 0 } }
|
| 197 |
+
},
|
| 198 |
+
{
|
| 199 |
+
"name": "ort_uint32_vector",
|
| 200 |
+
"provenance": {
|
| 201 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 202 |
+
"test": "MathOpTest.Sub_uint32"
|
| 203 |
+
},
|
| 204 |
+
"inputs": {
|
| 205 |
+
"a": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [4, 5, 6] } },
|
| 206 |
+
"b": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [1, 5, 3] } }
|
| 207 |
+
},
|
| 208 |
+
"outputs": { "c": { "dtype": "uint32", "shape": [3], "tolerance": 0 } }
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"name": "ort_broadcast_scalar_rhs",
|
| 212 |
+
"provenance": {
|
| 213 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 214 |
+
"test": "MathOpTest.Sub_Broadcast_Scalar"
|
| 215 |
+
},
|
| 216 |
+
"inputs": {
|
| 217 |
+
"a": {
|
| 218 |
+
"dtype": "float32",
|
| 219 |
+
"shape": [3, 3],
|
| 220 |
+
"data": { "kind": "values", "values": [1.0, 2.0, -1.0, 0.0, 1.5, -100.0, -5.4, 9.3, -10000.0] }
|
| 221 |
+
},
|
| 222 |
+
"b": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [5.0] } }
|
| 223 |
+
},
|
| 224 |
+
"outputs": { "c": { "dtype": "float32", "shape": [3, 3], "tolerance": 0.000001 } }
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"name": "ort_float16_3x3_projection",
|
| 228 |
+
"provenance": {
|
| 229 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 230 |
+
"test": "MathOpTest.Sub_float",
|
| 231 |
+
"notes": "Float16 projection of the ORT float Sub case."
|
| 232 |
+
},
|
| 233 |
+
"inputs": {
|
| 234 |
+
"a": {
|
| 235 |
+
"dtype": "float16",
|
| 236 |
+
"shape": [3, 3],
|
| 237 |
+
"data": { "kind": "values", "values": [1.0, 2.0, -1.0, 0.0, 1.5, -100.0, -5.4, 9.3, -10000.0] }
|
| 238 |
+
},
|
| 239 |
+
"b": {
|
| 240 |
+
"dtype": "float16",
|
| 241 |
+
"shape": [3, 3],
|
| 242 |
+
"data": { "kind": "values", "values": [-1.0, 4.4, 432.3, 0.0, 3.5, 64.0, -5.4, 9.3, 10000.0] }
|
| 243 |
+
}
|
| 244 |
+
},
|
| 245 |
+
"outputs": { "c": { "dtype": "float16", "shape": [3, 3], "tolerance": 0.125 } }
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"name": "onnx_backend_sub_bcast",
|
| 249 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_sub_bcast" },
|
| 250 |
+
"inputs": {
|
| 251 |
+
"a": {
|
| 252 |
+
"dtype": "float32",
|
| 253 |
+
"shape": [3, 4, 5],
|
| 254 |
+
"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/onnx_backend_sub_input_a" } }
|
| 255 |
+
},
|
| 256 |
+
"b": {
|
| 257 |
+
"dtype": "float32",
|
| 258 |
+
"shape": [5],
|
| 259 |
+
"data": {
|
| 260 |
+
"kind": "values",
|
| 261 |
+
"values": [-0.6724604368209839, -0.35955315828323364, -0.8131462931632996, -1.7262825965881348, 0.17742614448070526]
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
},
|
| 265 |
+
"outputs": { "c": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0 } }
|
| 266 |
+
},
|
| 267 |
+
{
|
| 268 |
+
"name": "onnx_backend_sub_example",
|
| 269 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_sub_example" },
|
| 270 |
+
"inputs": {
|
| 271 |
+
"a": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1.0, 2.0, 3.0] } },
|
| 272 |
+
"b": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [3.0, 2.0, 1.0] } }
|
| 273 |
+
},
|
| 274 |
+
"outputs": { "c": { "dtype": "float32", "shape": [3], "tolerance": 0 } }
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
"name": "onnx_backend_sub",
|
| 278 |
+
"provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_sub", "test": "test_sub" },
|
| 279 |
+
"inputs": {
|
| 280 |
+
"a": {
|
| 281 |
+
"dtype": "float32",
|
| 282 |
+
"shape": [3, 4, 5],
|
| 283 |
+
"data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/onnx_backend_sub_input_a" } }
|
| 284 |
+
},
|
| 285 |
+
"b": {
|
| 286 |
+
"dtype": "float32",
|
| 287 |
+
"shape": [3, 4, 5],
|
| 288 |
+
"data": {
|
| 289 |
+
"kind": "values",
|
| 290 |
+
"values": [-0.6724604368209839, -0.35955315828323364, -0.8131462931632996, -1.7262825965881348, 0.17742614448070526, -0.4017809331417084, -1.630198359489441, 0.46278226375579834, -0.9072983860969543, 0.05194539576768875, 0.7290905714035034, 0.12898291647434235, 1.1394007205963135, -1.234825849533081, 0.4023416340351105, -0.6848101019859314, -0.8707971572875977, -0.5788496732711792, -0.3115525245666504, 0.056165341287851334, -1.1651498079299927, 0.9008265137672424, 0.4656624495983124, -1.5362436771392822, 1.4882521629333496, 1.895889163017273, 1.1787796020507812, -0.1799248307943344, -1.0707526206970215, 1.0544517040252686, -0.4031769335269928, 1.222445011138916, 0.2082749754190445, 0.9766390323638916, 0.3563663959503174, 0.7065731883049011, 0.01050002034753561, 1.7858705520629883, 0.12691208720207214, 0.4019893705844879, 1.8831506967544556, -1.3477590084075928, -1.2704850435256958, 0.969396710395813, -1.1731233596801758, 1.9436211585998535, -0.4136189818382263, -0.747454822063446, 1.922942042350769, 1.4805147647857666, 1.8675589561462402, 0.9060446619987488, -0.8612256646156311, 1.910064935684204, -0.26800337433815, 0.8024563789367676, 0.9472519755363464, -0.15501008927822113, 0.6140793561935425, 0.922206699848175]
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
},
|
| 294 |
+
"outputs": { "c": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0.000001 } }
|
| 295 |
+
},
|
| 296 |
+
{
|
| 297 |
+
"name": "onnx_backend_sub_int8",
|
| 298 |
+
"provenance": {
|
| 299 |
+
"source": "cmake/external/onnx/onnx/backend/test/data/node/test_sub_int8",
|
| 300 |
+
"test": "test_sub_int8"
|
| 301 |
+
},
|
| 302 |
+
"inputs": {
|
| 303 |
+
"a": {
|
| 304 |
+
"dtype": "int8",
|
| 305 |
+
"shape": [3, 4, 5],
|
| 306 |
+
"data": {
|
| 307 |
+
"kind": "values",
|
| 308 |
+
"values": [12, 20, 20, 21, 23, 21, 20, 18, 15, 23, 16, 20, 13, 22, 22, 16, 20, 18, 18, 18, 12, 20, 23, 16, 17, 17, 16, 19, 14, 18, 18, 19, 14, 20, 21, 14, 15, 21, 21, 23, 18, 12, 14, 15, 17, 21, 16, 18, 22, 19, 22, 14, 17, 15, 19, 15, 13, 19, 21, 16]
|
| 309 |
+
}
|
| 310 |
+
},
|
| 311 |
+
"b": {
|
| 312 |
+
"dtype": "int8",
|
| 313 |
+
"shape": [3, 4, 5],
|
| 314 |
+
"data": {
|
| 315 |
+
"kind": "values",
|
| 316 |
+
"values": [4, 4, 5, 11, 1, 9, 6, 0, 1, 3, 5, 3, 3, 10, 8, 7, 3, 1, 8, 9, 4, 1, 9, 8, 10, 11, 9, 1, 10, 2, 7, 11, 3, 11, 4, 10, 11, 10, 2, 8, 8, 2, 7, 3, 11, 11, 3, 7, 1, 7, 11, 9, 9, 11, 1, 4, 10, 5, 11, 11]
|
| 317 |
+
}
|
| 318 |
+
}
|
| 319 |
+
},
|
| 320 |
+
"outputs": { "c": { "dtype": "int8", "shape": [3, 4, 5], "tolerance": 0 } }
|
| 321 |
+
},
|
| 322 |
+
{
|
| 323 |
+
"name": "onnx_backend_sub_uint8",
|
| 324 |
+
"provenance": {
|
| 325 |
+
"source": "cmake/external/onnx/onnx/backend/test/data/node/test_sub_uint8",
|
| 326 |
+
"test": "test_sub_uint8"
|
| 327 |
+
},
|
| 328 |
+
"inputs": {
|
| 329 |
+
"a": {
|
| 330 |
+
"dtype": "uint8",
|
| 331 |
+
"shape": [3, 4, 5],
|
| 332 |
+
"data": {
|
| 333 |
+
"kind": "values",
|
| 334 |
+
"values": [21, 12, 23, 21, 14, 21, 17, 22, 12, 21, 17, 16, 23, 19, 17, 21, 13, 21, 19, 23, 23, 17, 13, 12, 18, 18, 21, 22, 18, 22, 19, 12, 20, 12, 18, 19, 18, 16, 21, 12, 16, 23, 20, 22, 20, 21, 15, 16, 12, 12, 15, 14, 21, 17, 20, 22, 16, 22, 17, 14]
|
| 335 |
+
}
|
| 336 |
+
},
|
| 337 |
+
"b": {
|
| 338 |
+
"dtype": "uint8",
|
| 339 |
+
"shape": [3, 4, 5],
|
| 340 |
+
"data": {
|
| 341 |
+
"kind": "values",
|
| 342 |
+
"values": [4, 1, 3, 4, 1, 3, 5, 8, 7, 8, 0, 10, 2, 8, 3, 2, 5, 11, 3, 11, 6, 3, 11, 7, 4, 10, 11, 5, 7, 4, 4, 1, 0, 0, 3, 0, 3, 8, 6, 8, 2, 6, 7, 9, 6, 6, 7, 4, 10, 10, 5, 2, 1, 6, 5, 8, 4, 4, 7, 10]
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
},
|
| 346 |
+
"outputs": { "c": { "dtype": "uint8", "shape": [3, 4, 5], "tolerance": 0 } }
|
| 347 |
+
},
|
| 348 |
+
{
|
| 349 |
+
"name": "onnx_backend_sub_uint32",
|
| 350 |
+
"provenance": {
|
| 351 |
+
"source": "cmake/external/onnx/onnx/backend/test/data/node/test_sub_uint32",
|
| 352 |
+
"test": "test_sub_uint32"
|
| 353 |
+
},
|
| 354 |
+
"inputs": {
|
| 355 |
+
"a": {
|
| 356 |
+
"dtype": "uint32",
|
| 357 |
+
"shape": [3, 4, 5],
|
| 358 |
+
"data": {
|
| 359 |
+
"kind": "values",
|
| 360 |
+
"values": [20, 20, 19, 12, 20, 18, 20, 21, 20, 15, 18, 13, 19, 16, 21, 14, 12, 20, 14, 19, 20, 16, 16, 13, 19, 18, 21, 16, 13, 17, 21, 19, 23, 13, 15, 17, 19, 15, 18, 18, 19, 21, 13, 21, 18, 12, 15, 20, 16, 13, 16, 17, 12, 15, 22, 13, 16, 16, 16, 12]
|
| 361 |
+
}
|
| 362 |
+
},
|
| 363 |
+
"b": {
|
| 364 |
+
"dtype": "uint32",
|
| 365 |
+
"shape": [3, 4, 5],
|
| 366 |
+
"data": {
|
| 367 |
+
"kind": "values",
|
| 368 |
+
"values": [0, 10, 8, 11, 11, 4, 6, 9, 11, 3, 3, 2, 1, 10, 2, 1, 11, 3, 4, 10, 1, 1, 0, 7, 8, 10, 4, 3, 5, 6, 3, 2, 9, 8, 1, 4, 10, 0, 8, 3, 9, 5, 5, 1, 7, 8, 6, 4, 7, 3, 5, 11, 3, 6, 4, 7, 3, 0, 5, 11]
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
},
|
| 372 |
+
"outputs": { "c": { "dtype": "uint32", "shape": [3, 4, 5], "tolerance": 0 } }
|
| 373 |
+
},
|
| 374 |
+
{
|
| 375 |
+
"name": "ort_dim_zero_equal_rank",
|
| 376 |
+
"provenance": {
|
| 377 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 378 |
+
"test": "MathOpTest.DimWithZeroHandling",
|
| 379 |
+
"notes": "Projected from ORT's binary elementwise zero-dimension Add coverage to generic ONNX multidirectional broadcasting."
|
| 380 |
+
},
|
| 381 |
+
"inputs": {
|
| 382 |
+
"a": { "dtype": "float32", "shape": [3, 1], "data": { "kind": "values", "values": [1.0, 2.0, 3.0] } },
|
| 383 |
+
"b": { "dtype": "float32", "shape": [3, 0], "data": { "kind": "values", "values": [] } }
|
| 384 |
+
},
|
| 385 |
+
"outputs": { "c": { "dtype": "float32", "shape": [3, 0], "tolerance": 0 } }
|
| 386 |
+
},
|
| 387 |
+
{
|
| 388 |
+
"name": "ort_dim_zero_smaller_rank",
|
| 389 |
+
"provenance": {
|
| 390 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 391 |
+
"test": "MathOpTest.DimWithZeroHandling",
|
| 392 |
+
"notes": "Projected from ORT's binary elementwise zero-dimension Add coverage to generic ONNX multidirectional broadcasting."
|
| 393 |
+
},
|
| 394 |
+
"inputs": {
|
| 395 |
+
"a": { "dtype": "float32", "shape": [2, 1, 2], "data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0] } },
|
| 396 |
+
"b": { "dtype": "float32", "shape": [0, 2], "data": { "kind": "values", "values": [] } }
|
| 397 |
+
},
|
| 398 |
+
"outputs": { "c": { "dtype": "float32", "shape": [2, 0, 2], "tolerance": 0 } }
|
| 399 |
+
},
|
| 400 |
+
{
|
| 401 |
+
"name": "ort_dim_zero_larger_rank",
|
| 402 |
+
"provenance": {
|
| 403 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 404 |
+
"test": "MathOpTest.DimWithZeroHandling",
|
| 405 |
+
"notes": "Projected from ORT's binary elementwise zero-dimension Add coverage to generic ONNX multidirectional broadcasting."
|
| 406 |
+
},
|
| 407 |
+
"inputs": {
|
| 408 |
+
"a": { "dtype": "float32", "shape": [0, 2, 2], "data": { "kind": "values", "values": [] } },
|
| 409 |
+
"b": { "dtype": "float32", "shape": [1, 2], "data": { "kind": "values", "values": [1.0, 2.0] } }
|
| 410 |
+
},
|
| 411 |
+
"outputs": { "c": { "dtype": "float32", "shape": [0, 2, 2], "tolerance": 0 } }
|
| 412 |
+
},
|
| 413 |
+
{
|
| 414 |
+
"name": "ort_dim_zero_scalar_broadcast",
|
| 415 |
+
"provenance": {
|
| 416 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 417 |
+
"test": "MathOpTest.DimWithZeroHandling",
|
| 418 |
+
"notes": "Projected from ORT's binary elementwise zero-dimension Add coverage to generic ONNX multidirectional broadcasting."
|
| 419 |
+
},
|
| 420 |
+
"inputs": {
|
| 421 |
+
"a": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [1.0] } },
|
| 422 |
+
"b": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } }
|
| 423 |
+
},
|
| 424 |
+
"outputs": { "c": { "dtype": "float32", "shape": [0], "tolerance": 0 } }
|
| 425 |
+
},
|
| 426 |
+
{
|
| 427 |
+
"name": "ort_int16_basic_gpu_gap",
|
| 428 |
+
"skipGpu": {
|
| 429 |
+
"category": "todo",
|
| 430 |
+
"reason": "The widened-i32 Sub path does not yet restore signed 16-bit wraparound after overflow; enable int16 only with explicit narrowing and overflow fixtures."
|
| 431 |
+
},
|
| 432 |
+
"provenance": {
|
| 433 |
+
"source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
|
| 434 |
+
"test": "MathOpTest.Sub_int16"
|
| 435 |
+
},
|
| 436 |
+
"inputs": {
|
| 437 |
+
"a": { "dtype": "int16", "shape": [3], "data": { "kind": "values", "values": [1, 5, 6] } },
|
| 438 |
+
"b": { "dtype": "int16", "shape": [3], "data": { "kind": "values", "values": [4, 5, 3] } }
|
| 439 |
+
},
|
| 440 |
+
"outputs": { "c": { "dtype": "int16", "shape": [3], "tolerance": 0 } }
|
| 441 |
+
},
|
| 442 |
+
{
|
| 443 |
+
"name": "rank7_broadcast_vec4_even_lastdim",
|
| 444 |
+
"inputs": {
|
| 445 |
+
"a": {
|
| 446 |
+
"dtype": "float32",
|
| 447 |
+
"shape": [2, 1, 2, 1, 3, 1, 4],
|
| 448 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.09, "cosStep": 0.15 }
|
| 449 |
+
},
|
| 450 |
+
"b": {
|
| 451 |
+
"dtype": "float32",
|
| 452 |
+
"shape": [1, 2, 1, 3, 1, 4, 4],
|
| 453 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.07, "scale": 0.3 }
|
| 454 |
+
}
|
| 455 |
+
},
|
| 456 |
+
"outputs": { "c": { "dtype": "float32", "shape": [2, 2, 2, 3, 3, 4, 4], "tolerance": 0.000001 } }
|
| 457 |
+
},
|
| 458 |
+
{
|
| 459 |
+
"name": "uint8_underflow_wrap_broadcast_vec4",
|
| 460 |
+
"inputs": {
|
| 461 |
+
"a": {
|
| 462 |
+
"dtype": "uint8",
|
| 463 |
+
"shape": [2, 8],
|
| 464 |
+
"data": { "kind": "values", "values": [5, 10, 15, 20, 25, 30, 35, 40, 50, 45, 40, 35, 30, 25, 20, 15] }
|
| 465 |
+
},
|
| 466 |
+
"b": { "dtype": "uint8", "shape": [2, 1], "data": { "kind": "values", "values": [20, 60] } }
|
| 467 |
+
},
|
| 468 |
+
"outputs": {
|
| 469 |
+
"c": {
|
| 470 |
+
"dtype": "uint8",
|
| 471 |
+
"shape": [2, 8],
|
| 472 |
+
"tolerance": 0,
|
| 473 |
+
"data": {
|
| 474 |
+
"kind": "values",
|
| 475 |
+
"values": [241, 246, 251, 0, 5, 10, 15, 20, 246, 241, 236, 231, 226, 221, 216, 211]
|
| 476 |
+
}
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
},
|
| 480 |
+
{
|
| 481 |
+
"name": "f32_sub_exact_cancellation_broadcast",
|
| 482 |
+
"inputs": {
|
| 483 |
+
"a": {
|
| 484 |
+
"dtype": "float32",
|
| 485 |
+
"shape": [3, 8],
|
| 486 |
+
"data": {
|
| 487 |
+
"kind": "values",
|
| 488 |
+
"values": { "$ref": "#/fixtureArrays/f32_sub_exact_cancellation_broadcast_input_a" }
|
| 489 |
+
}
|
| 490 |
+
},
|
| 491 |
+
"b": {
|
| 492 |
+
"dtype": "float32",
|
| 493 |
+
"shape": [3, 8],
|
| 494 |
+
"data": {
|
| 495 |
+
"kind": "values",
|
| 496 |
+
"values": { "$ref": "#/fixtureArrays/f32_sub_exact_cancellation_broadcast_input_a" }
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
},
|
| 500 |
+
"outputs": {
|
| 501 |
+
"c": { "dtype": "float32", "shape": [3, 8], "tolerance": 0, "data": { "kind": "constant", "value": 0.0 } }
|
| 502 |
+
}
|
| 503 |
+
},
|
| 504 |
+
{
|
| 505 |
+
"name": "rank8_broadcast_alternating",
|
| 506 |
+
"inputs": {
|
| 507 |
+
"a": {
|
| 508 |
+
"dtype": "float32",
|
| 509 |
+
"shape": [2, 1, 2, 1, 2, 1, 2, 3],
|
| 510 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.19 }
|
| 511 |
+
},
|
| 512 |
+
"b": {
|
| 513 |
+
"dtype": "float32",
|
| 514 |
+
"shape": [1, 2, 1, 2, 1, 2, 1, 1],
|
| 515 |
+
"data": { "kind": "fillFloat32", "sinStep": 0.29, "cosStep": 0.11, "scale": 0.2 }
|
| 516 |
+
}
|
| 517 |
+
},
|
| 518 |
+
"outputs": { "c": { "dtype": "float32", "shape": [2, 2, 2, 2, 2, 2, 2, 3], "tolerance": 0.000001 } }
|
| 519 |
+
}
|
| 520 |
+
]
|
| 521 |
+
}
|