Xenova HF Staff commited on
Commit
9663d5f
·
verified ·
1 Parent(s): 8d1ebb5

sync 2e7068faf55e

Browse files
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.Add
10
+
11
+ `ai.onnx` · standard ONNX operator · ONNX opset ≥ 14
12
+
13
+ ## Description
14
+
15
+ Performs elementwise binary addition of two tensors with multidirectional (NumPy-style) broadcasting support. The output has the same element type as the inputs.
16
+
17
+ See the [ONNX `Add` spec](https://onnx.ai/onnx/operators/onnx__Add.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` | Elementwise sum of `A` and `B`; 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.Add", { version: 1 });
61
+ const { c } = await kernel({ a: { data: aData, shape: [] }, b: { data: bData, shape: [] } });
62
+ ```
build/webgpu/bench.json ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "op": "ai.onnx.Add",
3
+ "tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] },
4
+ "cases": [
5
+ {
6
+ "name": "add-f32-4m",
7
+ "preset": "smoke",
8
+ "vars": { "dtype": "float32", "count": 4194304 },
9
+ "inputs": {
10
+ "a": { "shape": [4194304], "dtype": "float32", "dist": "normal", "seed": 102, "scale": 2 },
11
+ "b": { "shape": [4194304], "dtype": "float32", "dist": "normal", "seed": 103, "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": "add-f32-biasadd-2048x2048",
21
+ "preset": "model",
22
+ "vars": { "dtype": "float32" },
23
+ "inputs": {
24
+ "a": { "shape": [2048, 2048], "dtype": "float32", "dist": "normal", "seed": 202, "scale": 2 },
25
+ "b": { "shape": [2048], "dtype": "float32", "dist": "normal", "seed": 203, "scale": 2 }
26
+ },
27
+ "outputs": { "c": { "shape": [2048, 2048], "dtype": "float32" } },
28
+ "bench": { "metrics": [{ "type": "bandwidth", "value": "2048 * 2048 * 2 * dtypeBytes(args.dtype)" }] }
29
+ },
30
+ {
31
+ "name": "add-f32-channelscale-1x1024x64x64",
32
+ "preset": "model",
33
+ "vars": { "dtype": "float32" },
34
+ "inputs": {
35
+ "a": { "shape": [1, 1024, 64, 64], "dtype": "float32", "dist": "normal", "seed": 302, "scale": 2 },
36
+ "b": { "shape": [1, 1024, 1, 1], "dtype": "float32", "dist": "normal", "seed": 303, "scale": 2 }
37
+ },
38
+ "outputs": { "c": { "shape": [1, 1024, 64, 64], "dtype": "float32" } },
39
+ "bench": { "metrics": [{ "type": "bandwidth", "value": "1024 * 64 * 64 * 2 * dtypeBytes(args.dtype)" }] }
40
+ },
41
+ {
42
+ "name": "add-f32-broadcast-scalar-fallback-4m",
43
+ "preset": "stress",
44
+ "vars": { "dtype": "float32", "count": 4190208 },
45
+ "inputs": {
46
+ "a": { "shape": [4096, 1023], "dtype": "float32", "dist": "normal", "seed": 142, "scale": 2 },
47
+ "b": { "shape": [1, 1023], "dtype": "float32", "dist": "normal", "seed": 143, "scale": 2 }
48
+ },
49
+ "outputs": { "c": { "shape": [4096, 1023], "dtype": "float32", "dist": "empty" } },
50
+ "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
51
+ },
52
+ {
53
+ "name": "add-f32-odd-numel-same-shape-4m",
54
+ "preset": "smoke",
55
+ "vars": { "dtype": "float32", "count": 4194303 },
56
+ "inputs": {
57
+ "a": { "shape": [4194303], "dtype": "float32", "dist": "normal", "seed": 102, "scale": 2 },
58
+ "b": { "shape": [4194303], "dtype": "float32", "dist": "normal", "seed": 103, "scale": 2 }
59
+ },
60
+ "outputs": { "c": { "shape": [4194303], "dtype": "float32" } },
61
+ "bench": {
62
+ "primary": true,
63
+ "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 3" }]
64
+ }
65
+ }
66
+ ]
67
+ }
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": "Add",
4
+ "sinceVersion": 14,
5
+ "description": "Performs elementwise binary addition of two tensors with multidirectional (NumPy-style) broadcasting support. 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": "Elementwise sum of `A` and `B`; 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": "Add.vec4",
40
+ "source": { "shader": "binary-vec4.wgsl.jinja", "inputs": { "op": "\"add\"", "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": "Add",
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": "\"add\"",
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": "Add",
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": "\"add\"",
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": "Add",
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": "\"add\"",
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.Add",
3
+ "id": "_ai_onnx_add_webgpu_a199e91",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "backend": { "type": "webgpu" },
7
+ "digest": {
8
+ "algorithm": "sha256",
9
+ "files": {
10
+ "bench.json": "U0RcZ6cEwHaPzKmWjxkZIosg9WgaFSUCYGWbCefJhGY=",
11
+ "binary-broadcast-vec4.wgsl.jinja": "i2NgmeStm8zKVGrhtYRJoRwj1sT9hK7l23JOsnkSPaM=",
12
+ "binary-broadcast.wgsl.jinja": "JRtdDC2eKRvRIbOXPZ6/cnt1J6mD2xx/w+aBs5stGH8=",
13
+ "binary-vec4.wgsl.jinja": "mnGHNzK6EqW5t1KCp51LQgMM5tG3ufJTHiAGLGNtjqg=",
14
+ "manifest.json": "g9eLFcjl3csJ5qlpqOuRrAcpVBzLhRlrbZa2LHEH/tE=",
15
+ "test.json": "X1RwOC4YQxALtpaNkTZWgM4UQQqNU7llruve1sWX3uo="
16
+ }
17
+ },
18
+ "provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
19
+ "webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.Add" }
20
+ }
build/webgpu/test.json ADDED
@@ -0,0 +1,719 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "op": "ai.onnx.Add",
3
+ "fixtureArrays": {
4
+ "onnx_backend_add_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
+ },
6
+ "cases": [
7
+ {
8
+ "name": "vector_19",
9
+ "inputs": {
10
+ "a": { "dtype": "float32", "shape": [19], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 } },
11
+ "b": { "dtype": "float32", "shape": [19], "data": { "kind": "fillFloat32", "sinStep": 0.31, "cosStep": 0.07 } }
12
+ },
13
+ "outputs": { "c": { "dtype": "float32", "shape": [19], "tolerance": 0.000001 } }
14
+ },
15
+ {
16
+ "name": "f32_subnormal_identity_and_cancellation_gpu_gap",
17
+ "skipGpu": {
18
+ "category": "permanent",
19
+ "reason": "Portable WGSL floating-point semantics do not guarantee preservation of the subnormal values required by this fixture. Backend evidence: Metal flushes float32 subnormals to zero; the preserved-subnormal lanes cannot be reproduced on GPU."
20
+ },
21
+ "provenance": {
22
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
23
+ "test": "MathOpTest.Add_float",
24
+ "notes": "Finite subnormal addends are valid float32 values; zero-add identity and exact opposite cancellation should not flush unrelated lanes."
25
+ },
26
+ "inputs": {
27
+ "a": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [1e-40, -1e-40, 0.0, 1e-39] } },
28
+ "b": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [0.0, 0.0, 1e-40, -1e-39] } }
29
+ },
30
+ "outputs": {
31
+ "c": {
32
+ "dtype": "float32",
33
+ "shape": [4],
34
+ "tolerance": 0,
35
+ "data": { "kind": "values", "values": [1e-40, -1e-40, 1e-40, 0.0] }
36
+ }
37
+ }
38
+ },
39
+ {
40
+ "name": "f32_subnormal_identity_and_cancellation_scalar_gpu_gap",
41
+ "skipGpu": {
42
+ "category": "permanent",
43
+ "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."
44
+ },
45
+ "provenance": {
46
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
47
+ "test": "MathOpTest.Add_float",
48
+ "notes": "Scalar-path companion: zero-add identity should preserve finite subnormal lanes while exact opposites cancel."
49
+ },
50
+ "inputs": {
51
+ "a": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1e-40, -1e-40, 1e-39] } },
52
+ "b": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [0.0, 0.0, -1e-39] } }
53
+ },
54
+ "outputs": {
55
+ "c": {
56
+ "dtype": "float32",
57
+ "shape": [3],
58
+ "tolerance": 0,
59
+ "data": { "kind": "values", "values": [1e-40, -1e-40, 0.0] }
60
+ }
61
+ }
62
+ },
63
+ {
64
+ "name": "float16_vec4_same_shape",
65
+ "inputs": {
66
+ "a": {
67
+ "dtype": "float16",
68
+ "shape": [8],
69
+ "data": { "kind": "values", "values": [1.0, -2.0, 3.5, -4.0, 0.25, 10.0, -100.0, 0.001] }
70
+ },
71
+ "b": {
72
+ "dtype": "float16",
73
+ "shape": [8],
74
+ "data": { "kind": "values", "values": [0.5, 2.0, -1.5, 4.0, 0.75, -5.0, 100.0, -0.001] }
75
+ }
76
+ },
77
+ "outputs": { "c": { "dtype": "float16", "shape": [8], "tolerance": 0.001 } }
78
+ },
79
+ {
80
+ "name": "scalar_rhs_broadcast",
81
+ "inputs": {
82
+ "a": { "dtype": "float32", "shape": [17], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 } },
83
+ "b": { "dtype": "float32", "shape": [1], "data": { "kind": "values", "values": [1.25] } }
84
+ },
85
+ "outputs": { "c": { "dtype": "float32", "shape": [17], "tolerance": 0.000001 } }
86
+ },
87
+ {
88
+ "name": "row_vector_rank4_broadcast",
89
+ "inputs": {
90
+ "a": {
91
+ "dtype": "float32",
92
+ "shape": [2, 3, 4, 5],
93
+ "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.19 }
94
+ },
95
+ "b": {
96
+ "dtype": "float32",
97
+ "shape": [1, 1, 1, 5],
98
+ "data": { "kind": "fillFloat32", "sinStep": 0.29, "cosStep": 0.11, "scale": 0.2 }
99
+ }
100
+ },
101
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 3, 4, 5], "tolerance": 0.000001 } }
102
+ },
103
+ {
104
+ "name": "rank7_alternating_broadcast",
105
+ "inputs": {
106
+ "a": {
107
+ "dtype": "float32",
108
+ "shape": [2, 1, 3, 1, 2, 1, 2],
109
+ "data": { "kind": "fillFloat32", "sinStep": 0.05, "cosStep": 0.17 }
110
+ },
111
+ "b": {
112
+ "dtype": "float32",
113
+ "shape": [1, 4, 1, 5, 1, 3, 1],
114
+ "data": { "kind": "fillFloat32", "sinStep": 0.23, "cosStep": 0.11, "scale": 0.4 }
115
+ }
116
+ },
117
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 4, 3, 5, 2, 3, 2], "tolerance": 0.000001 } }
118
+ },
119
+ {
120
+ "name": "true_scalar_lhs_broadcast",
121
+ "inputs": {
122
+ "a": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [1.25] } },
123
+ "b": {
124
+ "dtype": "float32",
125
+ "shape": [2, 3],
126
+ "data": { "kind": "values", "values": [0.0, 1.0, -2.0, 3.5, 4.0, -5.0] }
127
+ }
128
+ },
129
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 3], "tolerance": 0.000001 } }
130
+ },
131
+ {
132
+ "name": "rank0_scalar_scalar_output",
133
+ "inputs": {
134
+ "a": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [-1.25] } },
135
+ "b": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [3.5] } }
136
+ },
137
+ "outputs": { "c": { "dtype": "float32", "shape": [], "tolerance": 0.000001 } }
138
+ },
139
+ {
140
+ "name": "ort_broadcast_scalar_lhs_to_length1",
141
+ "provenance": {
142
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
143
+ "test": "MathOpTest.Add_Broadcast_0x1"
144
+ },
145
+ "inputs": {
146
+ "a": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [10.0] } },
147
+ "b": { "dtype": "float32", "shape": [1], "data": { "kind": "values", "values": [2.0] } }
148
+ },
149
+ "outputs": { "c": { "dtype": "float32", "shape": [1], "tolerance": 0 } }
150
+ },
151
+ {
152
+ "name": "ort_broadcast_scalar_rhs_to_length1",
153
+ "provenance": {
154
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
155
+ "test": "MathOpTest.Add_Broadcast_1x0"
156
+ },
157
+ "inputs": {
158
+ "a": { "dtype": "float32", "shape": [1], "data": { "kind": "values", "values": [10.0] } },
159
+ "b": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [2.0] } }
160
+ },
161
+ "outputs": { "c": { "dtype": "float32", "shape": [1], "tolerance": 0 } }
162
+ },
163
+ {
164
+ "name": "ort_broadcast_length1_length1",
165
+ "provenance": {
166
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
167
+ "test": "MathOpTest.Add_Broadcast_1x1"
168
+ },
169
+ "inputs": {
170
+ "a": { "dtype": "float32", "shape": [1], "data": { "kind": "values", "values": [10.0] } },
171
+ "b": { "dtype": "float32", "shape": [1], "data": { "kind": "values", "values": [2.0] } }
172
+ },
173
+ "outputs": { "c": { "dtype": "float32", "shape": [1], "tolerance": 0 } }
174
+ },
175
+ {
176
+ "name": "ort_broadcast_3x2_3x1",
177
+ "provenance": {
178
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
179
+ "test": "MathOpTest.Add_Broadcast_3x2_3x1"
180
+ },
181
+ "inputs": {
182
+ "a": {
183
+ "dtype": "float32",
184
+ "shape": [3, 2],
185
+ "data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] }
186
+ },
187
+ "b": { "dtype": "float32", "shape": [3, 1], "data": { "kind": "values", "values": [1.0, 2.0, 3.0] } }
188
+ },
189
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 2], "tolerance": 0 } }
190
+ },
191
+ {
192
+ "name": "ort_broadcast_2x2x2_1x2x2",
193
+ "provenance": {
194
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
195
+ "test": "MathOpTest.Add_Broadcast_2x2x2_1x2x2"
196
+ },
197
+ "inputs": {
198
+ "a": {
199
+ "dtype": "float32",
200
+ "shape": [2, 2, 2],
201
+ "data": { "kind": "values", "values": [101.0, 102.0, 103.0, 104.0, 201.0, 202.0, 203.0, 204.0] }
202
+ },
203
+ "b": {
204
+ "dtype": "float32",
205
+ "shape": [1, 2, 2],
206
+ "data": { "kind": "values", "values": [10.0, 20.0, 30.0, 40.0] }
207
+ }
208
+ },
209
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 2, 2], "tolerance": 0 } }
210
+ },
211
+ {
212
+ "name": "ort_broadcast_2x1x1_3x4",
213
+ "provenance": {
214
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
215
+ "test": "MathOpTest.Add_Broadcast_2x1x1_3x4"
216
+ },
217
+ "inputs": {
218
+ "a": { "dtype": "float32", "shape": [2, 1, 1], "data": { "kind": "values", "values": [100.0, 200.0] } },
219
+ "b": {
220
+ "dtype": "float32",
221
+ "shape": [3, 4],
222
+ "data": {
223
+ "kind": "values",
224
+ "values": [11.0, 12.0, 13.0, 14.0, 21.0, 22.0, 23.0, 24.0, 31.0, 32.0, 33.0, 34.0]
225
+ }
226
+ }
227
+ },
228
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 3, 4], "tolerance": 0 } }
229
+ },
230
+ {
231
+ "name": "int32_exact_above_float24",
232
+ "inputs": {
233
+ "a": {
234
+ "dtype": "int32",
235
+ "shape": [4],
236
+ "data": { "kind": "values", "values": [16777217, -16777217, 123456789, -123456789] }
237
+ },
238
+ "b": { "dtype": "int32", "shape": [4], "data": { "kind": "values", "values": [2, -2, 10, -10] } }
239
+ },
240
+ "outputs": { "c": { "dtype": "int32", "shape": [4] } }
241
+ },
242
+ {
243
+ "name": "ort_float_3x3",
244
+ "provenance": {
245
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
246
+ "test": "MathOpTest.Add_float"
247
+ },
248
+ "inputs": {
249
+ "a": {
250
+ "dtype": "float32",
251
+ "shape": [3, 3],
252
+ "data": { "kind": "values", "values": [1.0, 2.0, -1.0, 0.0, 1.5, -100.0, -5.4, 9.3, -10000.0] }
253
+ },
254
+ "b": {
255
+ "dtype": "float32",
256
+ "shape": [3, 3],
257
+ "data": { "kind": "values", "values": [-1.0, 4.4, 432.3, 0.0, 3.5, 64.0, -5.4, 9.3, 10000.0] }
258
+ }
259
+ },
260
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 3], "tolerance": 0.000001 } }
261
+ },
262
+ {
263
+ "name": "ort_int8_vector",
264
+ "provenance": {
265
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
266
+ "test": "MathOpTest.Add_int8"
267
+ },
268
+ "inputs": {
269
+ "a": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [1, -2, 3] } },
270
+ "b": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [4, 5, 6] } }
271
+ },
272
+ "outputs": { "c": { "dtype": "int8", "shape": [3], "tolerance": 0 } }
273
+ },
274
+ {
275
+ "name": "ort_int8_overflow_wrap",
276
+ "provenance": {
277
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
278
+ "test": "MathOpTest.Add_int8",
279
+ "notes": "Extends ORT's int8 Add coverage with signed overflow values that must wrap to logical int8 width."
280
+ },
281
+ "inputs": {
282
+ "a": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [127, -128, 100] } },
283
+ "b": { "dtype": "int8", "shape": [3], "data": { "kind": "values", "values": [1, -1, 30] } }
284
+ },
285
+ "outputs": { "c": { "dtype": "int8", "shape": [3], "tolerance": 0 } }
286
+ },
287
+ {
288
+ "name": "ort_int32_vector",
289
+ "provenance": {
290
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
291
+ "test": "MathOpTest.Add_int32"
292
+ },
293
+ "inputs": {
294
+ "a": { "dtype": "int32", "shape": [3], "data": { "kind": "values", "values": [1, 2, 3] } },
295
+ "b": { "dtype": "int32", "shape": [3], "data": { "kind": "values", "values": [4, 5, 6] } }
296
+ },
297
+ "outputs": { "c": { "dtype": "int32", "shape": [3], "tolerance": 0 } }
298
+ },
299
+ {
300
+ "name": "ort_uint8_vector",
301
+ "provenance": {
302
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
303
+ "test": "MathOpTest.Add_uint8"
304
+ },
305
+ "inputs": {
306
+ "a": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [1, 2, 3] } },
307
+ "b": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [4, 5, 6] } }
308
+ },
309
+ "outputs": { "c": { "dtype": "uint8", "shape": [3], "tolerance": 0 } }
310
+ },
311
+ {
312
+ "name": "ort_uint8_overflow_wrap",
313
+ "provenance": {
314
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
315
+ "test": "MathOpTest.Add_uint8",
316
+ "notes": "Extends ORT's uint8 Add coverage with overflow values that must wrap to logical uint8 width."
317
+ },
318
+ "inputs": {
319
+ "a": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [255, 0, 200] } },
320
+ "b": { "dtype": "uint8", "shape": [3], "data": { "kind": "values", "values": [1, 255, 100] } }
321
+ },
322
+ "outputs": { "c": { "dtype": "uint8", "shape": [3], "tolerance": 0 } }
323
+ },
324
+ {
325
+ "name": "ort_uint32_vector",
326
+ "provenance": {
327
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
328
+ "test": "MathOpTest.Add_uint32"
329
+ },
330
+ "inputs": {
331
+ "a": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [1, 2, 3] } },
332
+ "b": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [4, 5, 6] } }
333
+ },
334
+ "outputs": { "c": { "dtype": "uint32", "shape": [3], "tolerance": 0 } }
335
+ },
336
+ {
337
+ "name": "ort_broadcast_axis_3x3_3x1",
338
+ "provenance": {
339
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
340
+ "test": "MathOpTest.Add_Broadcast_Axis"
341
+ },
342
+ "inputs": {
343
+ "a": {
344
+ "dtype": "float32",
345
+ "shape": [3, 3],
346
+ "data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] }
347
+ },
348
+ "b": { "dtype": "float32", "shape": [3, 1], "data": { "kind": "values", "values": [3.0, 2.0, 1.0] } }
349
+ },
350
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 3], "tolerance": 0.000001 } }
351
+ },
352
+ {
353
+ "name": "ort_broadcast_multidirectional_ab",
354
+ "provenance": {
355
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
356
+ "test": "MathOpTest.Add_Broadcast_MultidirectionalAB"
357
+ },
358
+ "inputs": {
359
+ "a": { "dtype": "float32", "shape": [3, 1], "data": { "kind": "values", "values": [3.0, 2.0, 1.0] } },
360
+ "b": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1.0, 2.0, 3.0] } }
361
+ },
362
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 3], "tolerance": 0.000001 } }
363
+ },
364
+ {
365
+ "name": "ort_broadcast_multidirectional_ba",
366
+ "provenance": {
367
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
368
+ "test": "MathOpTest.Add_Broadcast_MultidirectionalBA"
369
+ },
370
+ "inputs": {
371
+ "a": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1.0, 2.0, 3.0] } },
372
+ "b": { "dtype": "float32", "shape": [3, 1], "data": { "kind": "values", "values": [3.0, 2.0, 1.0] } }
373
+ },
374
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 3], "tolerance": 0.000001 } }
375
+ },
376
+ {
377
+ "name": "ort_broadcast_scalar_scalar",
378
+ "provenance": {
379
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
380
+ "test": "MathOpTest.Add_Broadcast_0x0"
381
+ },
382
+ "inputs": {
383
+ "a": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [10.0] } },
384
+ "b": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [2.0] } }
385
+ },
386
+ "outputs": { "c": { "dtype": "float32", "shape": [], "tolerance": 0.000001 } }
387
+ },
388
+ {
389
+ "name": "ort_broadcast_2x1x4_1x3x1",
390
+ "provenance": {
391
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
392
+ "test": "MathOpTest.Add_Broadcast_2x1x4_1x3x1"
393
+ },
394
+ "inputs": {
395
+ "a": {
396
+ "dtype": "float32",
397
+ "shape": [2, 1, 4],
398
+ "data": { "kind": "values", "values": [101.0, 102.0, 103.0, 104.0, 201.0, 202.0, 203.0, 204.0] }
399
+ },
400
+ "b": { "dtype": "float32", "shape": [1, 3, 1], "data": { "kind": "values", "values": [10.0, 20.0, 30.0] } }
401
+ },
402
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 3, 4], "tolerance": 0.000001 } }
403
+ },
404
+ {
405
+ "name": "ort_dim_zero_equal_rank",
406
+ "provenance": {
407
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
408
+ "test": "MathOpTest.DimWithZeroHandling",
409
+ "notes": "Float32 projection of ORT's equal-rank zero-dimension Add broadcast case."
410
+ },
411
+ "inputs": {
412
+ "a": { "dtype": "float32", "shape": [3, 1], "data": { "kind": "values", "values": [1.0, 2.0, 3.0] } },
413
+ "b": { "dtype": "float32", "shape": [3, 0], "data": { "kind": "values", "values": [] } }
414
+ },
415
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 0], "tolerance": 0 } }
416
+ },
417
+ {
418
+ "name": "ort_dim_zero_smaller_rank",
419
+ "provenance": {
420
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
421
+ "test": "MathOpTest.DimWithZeroHandling",
422
+ "notes": "Float32 projection of ORT's smaller-rank zero-dimension Add broadcast case."
423
+ },
424
+ "inputs": {
425
+ "a": { "dtype": "float32", "shape": [2, 1, 2], "data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0] } },
426
+ "b": { "dtype": "float32", "shape": [0, 2], "data": { "kind": "values", "values": [] } }
427
+ },
428
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 0, 2], "tolerance": 0 } }
429
+ },
430
+ {
431
+ "name": "ort_dim_zero_larger_rank",
432
+ "provenance": {
433
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
434
+ "test": "MathOpTest.DimWithZeroHandling",
435
+ "notes": "Float32 projection of ORT's larger-rank zero-dimension Add broadcast case."
436
+ },
437
+ "inputs": {
438
+ "a": { "dtype": "float32", "shape": [0, 2, 2], "data": { "kind": "values", "values": [] } },
439
+ "b": { "dtype": "float32", "shape": [1, 2], "data": { "kind": "values", "values": [1.0, 2.0] } }
440
+ },
441
+ "outputs": { "c": { "dtype": "float32", "shape": [0, 2, 2], "tolerance": 0 } }
442
+ },
443
+ {
444
+ "name": "ort_dim_zero_scalar_broadcast",
445
+ "provenance": {
446
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
447
+ "test": "MathOpTest.DimWithZeroHandling",
448
+ "notes": "Float32 projection of ORT's scalar-to-zero-dimension Add broadcast case."
449
+ },
450
+ "inputs": {
451
+ "a": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [1.0] } },
452
+ "b": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } }
453
+ },
454
+ "outputs": { "c": { "dtype": "float32", "shape": [0], "tolerance": 0 } }
455
+ },
456
+ {
457
+ "name": "onnx_backend_add_bcast",
458
+ "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_add_bcast" },
459
+ "inputs": {
460
+ "a": {
461
+ "dtype": "float32",
462
+ "shape": [3, 4, 5],
463
+ "data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/onnx_backend_add_input_a" } }
464
+ },
465
+ "b": {
466
+ "dtype": "float32",
467
+ "shape": [5],
468
+ "data": {
469
+ "kind": "values",
470
+ "values": [-0.6724604368209839, -0.35955315828323364, -0.8131462931632996, -1.7262825965881348, 0.17742614448070526]
471
+ }
472
+ }
473
+ },
474
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0 } }
475
+ },
476
+ {
477
+ "name": "onnx_backend_add",
478
+ "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_add", "test": "test_add" },
479
+ "inputs": {
480
+ "a": {
481
+ "dtype": "float32",
482
+ "shape": [3, 4, 5],
483
+ "data": { "kind": "values", "values": { "$ref": "#/fixtureArrays/onnx_backend_add_input_a" } }
484
+ },
485
+ "b": {
486
+ "dtype": "float32",
487
+ "shape": [3, 4, 5],
488
+ "data": {
489
+ "kind": "values",
490
+ "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]
491
+ }
492
+ }
493
+ },
494
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0.000001 } }
495
+ },
496
+ {
497
+ "name": "onnx_backend_add_int8",
498
+ "provenance": {
499
+ "source": "cmake/external/onnx/onnx/backend/test/data/node/test_add_int8",
500
+ "test": "test_add_int8"
501
+ },
502
+ "inputs": {
503
+ "a": {
504
+ "dtype": "int8",
505
+ "shape": [3, 4, 5],
506
+ "data": {
507
+ "kind": "values",
508
+ "values": [0, 8, 11, 8, 22, 3, 11, 20, 17, 10, 4, 22, 22, 22, 0, 11, 15, 20, 5, 21, 20, 23, 2, 6, 22, 7, 15, 2, 8, 9, 2, 3, 9, 22, 0, 2, 19, 15, 21, 4, 22, 10, 23, 10, 18, 21, 3, 15, 7, 19, 17, 23, 14, 4, 12, 20, 20, 12, 14, 21]
509
+ }
510
+ },
511
+ "b": {
512
+ "dtype": "int8",
513
+ "shape": [3, 4, 5],
514
+ "data": {
515
+ "kind": "values",
516
+ "values": [22, 16, 17, 3, 21, 3, 3, 10, 8, 7, 3, 1, 8, 9, 13, 20, 17, 9, 8, 10, 9, 17, 10, 18, 23, 15, 3, 20, 14, 15, 10, 11, 2, 18, 23, 19, 12, 12, 11, 3, 7, 17, 7, 9, 1, 4, 10, 13, 21, 14, 17, 13, 17, 2, 7, 0, 17, 3, 7, 5]
517
+ }
518
+ }
519
+ },
520
+ "outputs": { "c": { "dtype": "int8", "shape": [3, 4, 5], "tolerance": 0 } }
521
+ },
522
+ {
523
+ "name": "onnx_backend_add_uint8",
524
+ "provenance": {
525
+ "source": "cmake/external/onnx/onnx/backend/test/data/node/test_add_uint8",
526
+ "test": "test_add_uint8"
527
+ },
528
+ "inputs": {
529
+ "a": {
530
+ "dtype": "uint8",
531
+ "shape": [3, 4, 5],
532
+ "data": {
533
+ "kind": "values",
534
+ "values": [23, 21, 13, 9, 1, 9, 14, 7, 11, 12, 5, 17, 0, 22, 22, 9, 6, 23, 16, 0, 15, 6, 23, 22, 20, 9, 16, 4, 11, 8, 10, 9, 3, 4, 0, 0, 3, 2, 9, 5, 14, 20, 5, 2, 20, 15, 1, 3, 4, 12, 17, 19, 5, 8, 7, 8, 16, 10, 2, 3]
535
+ }
536
+ },
537
+ "b": {
538
+ "dtype": "uint8",
539
+ "shape": [3, 4, 5],
540
+ "data": {
541
+ "kind": "values",
542
+ "values": [19, 22, 12, 19, 23, 20, 14, 10, 11, 5, 23, 20, 4, 1, 0, 0, 3, 0, 19, 8, 6, 8, 18, 22, 15, 7, 6, 6, 23, 4, 10, 12, 13, 12, 12, 12, 5, 2, 17, 22, 5, 15, 20, 12, 14, 20, 7, 10, 19, 23, 11, 4, 20, 0, 15, 11, 10, 0, 2, 11]
543
+ }
544
+ }
545
+ },
546
+ "outputs": { "c": { "dtype": "uint8", "shape": [3, 4, 5], "tolerance": 0 } }
547
+ },
548
+ {
549
+ "name": "onnx_backend_add_uint32",
550
+ "provenance": {
551
+ "source": "cmake/external/onnx/onnx/backend/test/data/node/test_add_uint32",
552
+ "test": "test_add_uint32"
553
+ },
554
+ "inputs": {
555
+ "a": {
556
+ "dtype": "uint32",
557
+ "shape": [3, 4, 5],
558
+ "data": {
559
+ "kind": "values",
560
+ "values": [17, 7, 20, 2, 16, 18, 13, 23, 4, 4, 12, 17, 23, 22, 20, 1, 5, 23, 1, 19, 21, 23, 19, 22, 22, 7, 9, 17, 9, 22, 0, 19, 4, 17, 20, 21, 16, 3, 10, 1, 20, 4, 4, 16, 16, 15, 10, 13, 8, 11, 20, 6, 9, 15, 3, 19, 12, 18, 17, 10]
561
+ }
562
+ },
563
+ "b": {
564
+ "dtype": "uint32",
565
+ "shape": [3, 4, 5],
566
+ "data": {
567
+ "kind": "values",
568
+ "values": [2, 1, 11, 3, 12, 4, 1, 17, 0, 7, 4, 3, 5, 6, 3, 2, 8, 1, 4, 0, 13, 19, 9, 21, 5, 1, 7, 8, 22, 20, 7, 3, 21, 12, 3, 6, 20, 7, 19, 0, 5, 11, 9, 19, 7, 21, 5, 8, 11, 14, 0, 8, 19, 6, 10, 19, 2, 23, 0, 19]
569
+ }
570
+ }
571
+ },
572
+ "outputs": { "c": { "dtype": "uint32", "shape": [3, 4, 5], "tolerance": 0 } }
573
+ },
574
+ {
575
+ "name": "ort_int16_basic_gpu_gap",
576
+ "skipGpu": {
577
+ "category": "todo",
578
+ "reason": "The widened-i32 Add path does not yet restore signed 16-bit wraparound after overflow; enable int16 only with explicit narrowing and overflow fixtures."
579
+ },
580
+ "provenance": {
581
+ "source": "onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc",
582
+ "test": "MathOpTest.Add_int16"
583
+ },
584
+ "inputs": {
585
+ "a": { "dtype": "int16", "shape": [3], "data": { "kind": "values", "values": [1, -2, 3] } },
586
+ "b": { "dtype": "int16", "shape": [3], "data": { "kind": "values", "values": [4, 5, 6] } }
587
+ },
588
+ "outputs": { "c": { "dtype": "int16", "shape": [3], "tolerance": 0 } }
589
+ },
590
+ {
591
+ "name": "broadcast_vec4_biasadd_row",
592
+ "inputs": {
593
+ "a": {
594
+ "dtype": "float32",
595
+ "shape": [3, 8],
596
+ "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 }
597
+ },
598
+ "b": { "dtype": "float32", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.19 } }
599
+ },
600
+ "outputs": { "c": { "dtype": "float32", "shape": [3, 8], "tolerance": 0.00001 } }
601
+ },
602
+ {
603
+ "name": "broadcast_vec4_channelscale_inner",
604
+ "inputs": {
605
+ "a": {
606
+ "dtype": "float32",
607
+ "shape": [1, 3, 2, 8],
608
+ "data": { "kind": "fillFloat32", "sinStep": 0.11, "cosStep": 0.23 }
609
+ },
610
+ "b": {
611
+ "dtype": "float32",
612
+ "shape": [1, 3, 1, 1],
613
+ "data": { "kind": "fillFloat32", "sinStep": 0.05, "cosStep": 0.17 }
614
+ }
615
+ },
616
+ "outputs": { "c": { "dtype": "float32", "shape": [1, 3, 2, 8], "tolerance": 0.00001 } }
617
+ },
618
+ {
619
+ "name": "broadcast_vec4_scalar_operand",
620
+ "inputs": {
621
+ "a": {
622
+ "dtype": "float32",
623
+ "shape": [2, 8],
624
+ "data": { "kind": "fillFloat32", "sinStep": 0.17, "cosStep": 0.31 }
625
+ },
626
+ "b": { "dtype": "float32", "shape": [1], "data": { "kind": "values", "values": [2.5] } }
627
+ },
628
+ "outputs": { "c": { "dtype": "float32", "shape": [2, 8], "tolerance": 0.00001 } }
629
+ },
630
+ {
631
+ "name": "broadcast_vec4_f16_biasadd",
632
+ "inputs": {
633
+ "a": {
634
+ "dtype": "float16",
635
+ "shape": [3, 8],
636
+ "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 }
637
+ },
638
+ "b": { "dtype": "float16", "shape": [8], "data": { "kind": "fillFloat32", "sinStep": 0.07, "cosStep": 0.19 } }
639
+ },
640
+ "outputs": { "c": { "dtype": "float16", "shape": [3, 8], "tolerance": 0.01 } }
641
+ },
642
+ {
643
+ "name": "broadcast_vec4_2d_fold_boundary",
644
+ "inputs": {
645
+ "a": {
646
+ "dtype": "float32",
647
+ "shape": [65537, 4],
648
+ "data": { "kind": "fillFloat32", "sinStep": 0.01, "cosStep": 0.02, "scale": 0.5 }
649
+ },
650
+ "b": {
651
+ "dtype": "float32",
652
+ "shape": [65537, 4],
653
+ "data": { "kind": "fillFloat32", "sinStep": 0.03, "cosStep": 0.05, "scale": 0.5 }
654
+ }
655
+ },
656
+ "outputs": { "c": { "dtype": "float32", "shape": [65537, 4], "tolerance": 0.000001 } }
657
+ },
658
+ {
659
+ "name": "broadcast_vec4_rank_mismatch_outer_broadcast",
660
+ "inputs": {
661
+ "a": {
662
+ "dtype": "int32",
663
+ "shape": [3, 4],
664
+ "data": { "kind": "values", "values": [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200] }
665
+ },
666
+ "b": {
667
+ "dtype": "int32",
668
+ "shape": [4, 3, 4],
669
+ "data": {
670
+ "kind": "values",
671
+ "values": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48]
672
+ }
673
+ }
674
+ },
675
+ "outputs": { "c": { "dtype": "int32", "shape": [4, 3, 4], "tolerance": 0 } }
676
+ },
677
+ {
678
+ "name": "f16_result_overflows_to_inf",
679
+ "inputs": {
680
+ "a": {
681
+ "dtype": "float16",
682
+ "shape": [4],
683
+ "data": { "kind": "values", "values": [60000.0, -60000.0, 32768.0, 0.0] }
684
+ },
685
+ "b": {
686
+ "dtype": "float16",
687
+ "shape": [4],
688
+ "data": { "kind": "values", "values": [10000.0, -10000.0, 32768.0, 65504.0] }
689
+ }
690
+ },
691
+ "outputs": { "c": { "dtype": "float16", "shape": [4], "tolerance": 0, "allowNaN": false } }
692
+ },
693
+ {
694
+ "name": "int8_broadcast_vec4_wrap_splat",
695
+ "inputs": {
696
+ "a": {
697
+ "dtype": "int8",
698
+ "shape": [2, 8],
699
+ "data": {
700
+ "kind": "values",
701
+ "values": [120, 121, 122, 123, 124, 125, 126, 127, -128, -127, -126, -125, -124, -123, -122, -121]
702
+ }
703
+ },
704
+ "b": { "dtype": "int8", "shape": [2, 1], "data": { "kind": "values", "values": [10, -10] } }
705
+ },
706
+ "outputs": {
707
+ "c": {
708
+ "dtype": "int8",
709
+ "shape": [2, 8],
710
+ "tolerance": 0,
711
+ "data": {
712
+ "kind": "values",
713
+ "values": [-126, -125, -124, -123, -122, -121, -120, -119, 118, 119, 120, 121, 122, 123, 124, 125]
714
+ }
715
+ }
716
+ }
717
+ }
718
+ ]
719
+ }