Xenova HF Staff commited on
Commit
e17c874
·
verified ·
1 Parent(s): 77b755a

sync 2e7068faf55e

Browse files
README.md CHANGED
@@ -1,3 +1,76 @@
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.ConstantOfShape
10
+
11
+ `ai.onnx` · standard ONNX operator · ONNX opset ≥ 9
12
+
13
+ ## Description
14
+
15
+ Generates a tensor filled with a constant value and a caller-specified shape. The shape is provided as a 1-D integer tensor; if empty, the output is a scalar. The fill value and its dtype are taken from the `value` attribute, defaulting to `0` of type float32.
16
+
17
+ See the [ONNX `ConstantOfShape` spec](https://onnx.ai/onnx/operators/onnx__ConstantOfShape.html) for the reference semantics.
18
+
19
+ ## Inputs
20
+
21
+ | Name | Bind key | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
22
+ | --- | --- | --- | --- | --- | --- | --- | --- |
23
+ | `input` | `input` | `S` | `uint32` | `1` | — | Logical int64 1-D tensor whose elements define the output shape; all values must be non-negative and use uint32 WebGPU storage. | required |
24
+
25
+ ## Outputs
26
+
27
+ | Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
28
+ | --- | --- | --- | --- | --- | --- | --- |
29
+ | `output` | `output` | `T` | derived | — | Output tensor of the shape given by `input`, filled with the constant `value`. | required |
30
+
31
+ ## Attributes
32
+
33
+ Attributes and default values (overridable per request):
34
+
35
+ | Attribute | Default | Description |
36
+ | --- | --- | --- |
37
+ | `value` | — | Optional single-element tensor specifying the fill value and output dtype; defaults to 0 of type float32 if omitted. |
38
+
39
+ ## Type constraints
40
+
41
+ | Variable | Allowed dtypes |
42
+ | --- | --- |
43
+ | `S` | `int64` |
44
+ | `T` | `float32`, `float16`, `int32`, `int16`, `uint32`, `int8`, `uint8`, `bool` |
45
+
46
+ ## Files
47
+
48
+ - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)
49
+ - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
50
+ - [`test.json`](build/webgpu/test.json) — correctness cases
51
+ - [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases
52
+ - [`constant-of-shape.wgsl.jinja`](build/webgpu/constant-of-shape.wgsl.jinja)
53
+
54
+ ## Use with `@huggingface/kernels`
55
+
56
+ The loader automatically allocates outputs whose metadata it can derive from the manifest contract and this call.
57
+
58
+ The explicit `outputs` entries provide shape and logical dtype metadata for the results listed below:
59
+
60
+ - `output`
61
+
62
+ Each entry either requests an optional result or supplies metadata that cannot be inferred from the inputs.
63
+
64
+ The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
65
+
66
+ Replace each `*Data` placeholder with a typed array containing the corresponding input data.
67
+
68
+ ```js
69
+ import { getKernel } from "@huggingface/kernels";
70
+
71
+ const kernel = await getKernel("webgpu-kernels/ai.onnx.ConstantOfShape", { version: 1 });
72
+ // Explicit destinations request optional results or supply metadata that cannot be inferred.
73
+ const { output } = await kernel({ input: { data: inputData, shape: [2] } }, {
74
+ outputs: { output: { shape: [2, 3], dtype: "float32" } },
75
+ });
76
+ ```
build/webgpu/bench.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "op": "ai.onnx.ConstantOfShape",
3
+ "cases": [
4
+ {
5
+ "name": "mask_16m_f32",
6
+ "preset": "smoke",
7
+ "attrs": { "value": -10000 },
8
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [4096, 4096] } } },
9
+ "outputs": { "output": { "dtype": "float32", "shape": [4096, 4096] } },
10
+ "bench": { "primary": true, "metrics": [{ "type": "bandwidth", "value": "4096 * 4096 * 4" }] }
11
+ },
12
+ {
13
+ "name": "1m_f32",
14
+ "attrs": { "value": -10000 },
15
+ "inputs": { "input": { "dtype": "uint32", "shape": [1], "data": { "kind": "values", "values": [1048576] } } },
16
+ "outputs": { "output": { "dtype": "float32", "shape": [1048576] } }
17
+ },
18
+ {
19
+ "name": "fill_16m_f32_scalar_fallback",
20
+ "attrs": { "value": -10000 },
21
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [4097, 4097] } } },
22
+ "outputs": { "output": { "dtype": "float32", "shape": [4097, 4097] } },
23
+ "vars": { "dtype": "float32", "count": 16785409 },
24
+ "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype)" }] }
25
+ },
26
+ {
27
+ "name": "mask_16m_f16",
28
+ "attrs": { "value": -10000 },
29
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [4096, 4096] } } },
30
+ "outputs": { "output": { "dtype": "float16", "shape": [4096, 4096] } },
31
+ "vars": { "dtype": "float16", "count": 16777216 },
32
+ "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype)" }] }
33
+ },
34
+ {
35
+ "name": "fill_134m_f32_2dfold",
36
+ "attrs": { "value": -10000 },
37
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [16384, 8192] } } },
38
+ "outputs": { "output": { "dtype": "float32", "shape": [16384, 8192] } },
39
+ "vars": { "dtype": "float32", "count": 134217728 },
40
+ "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype)" }] }
41
+ },
42
+ {
43
+ "name": "fill_16m_f16_scalar_fallback",
44
+ "preset": "stress",
45
+ "attrs": { "value": -10000 },
46
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [4097, 4097] } } },
47
+ "outputs": { "output": { "dtype": "float16", "shape": [4097, 4097] } },
48
+ "vars": { "dtype": "float16", "count": 16785409 },
49
+ "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype)" }] }
50
+ }
51
+ ]
52
+ }
build/webgpu/constant-of-shape.wgsl.jinja ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% macro flat_index_2d(name="i", bound="params.count", guardInline=false, note="dispatch-limit") %}
2
+ {% if note == "dispatch-limit" %}
3
+ // 2D-folded flat index: gid.y carries the high bits past the
4
+ // maxComputeWorkgroupsPerDimension dispatch limit (outputs > 16.7M elements).
5
+ {% elif note == "limit" %}
6
+ // 2D-folded flat index: gid.y carries the high bits past the
7
+ // maxComputeWorkgroupsPerDimension limit.
8
+ {% elif note == "device-axis" %}
9
+ // The flat dispatch is folded across x/y at the device's per-axis workgroup
10
+ // limit; gid.y carries the high portion of the output index.
11
+ {% elif note == "vec4-limit" %}
12
+ // 2D-folded flat vec4 index: gid.y carries the high bits past the
13
+ // maxComputeWorkgroupsPerDimension limit (the dispatch caps x and spills into y).
14
+ {% elif note == "element-limit" %}
15
+ // 2D-folded flat element index: gid.y carries the high bits past the
16
+ // maxComputeWorkgroupsPerDimension limit.
17
+ {% elif note == "dispatch" %}
18
+ // 2D-folded flat index: gid.y carries the high bits past the
19
+ // maxComputeWorkgroupsPerDimension dispatch limit.
20
+ {% endif %}
21
+ {% if bound == "" %}
22
+ let {{ name }} = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
23
+ {%- elif guardInline %}
24
+ let {{ name }} = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
25
+ if ({{ name }} >= {{ bound }}) { return; }
26
+ {%- else %}
27
+ let {{ name }} = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;
28
+ if ({{ name }} >= {{ bound }}) {
29
+ return;
30
+ }
31
+ {%- endif %}
32
+ {% endmacro %}
33
+
34
+ {% if usesF16 %}
35
+ enable f16;
36
+ {% endif %}
37
+ {{ env.wgsl.resourceDeclarations }}
38
+
39
+ const COUNT: u32 = {{ source.count }}u;
40
+
41
+ @compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})
42
+ fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {
43
+ {{ flat_index_2d("i", "COUNT", note="element-limit") }}
44
+ {% if source.vectorized %}
45
+ {% if source.valueFromUniform %}
46
+ output[i] = {{ vectorScalar }}({{ scalar }}(params.value));
47
+ {% else %}
48
+ output[i] = {{ vectorScalar }}({{ scalar }}({{ source.value }}));
49
+ {% endif %}
50
+ {% else %}
51
+ {% if source.valueFromUniform %}
52
+ output[i] = {{ scalar }}(params.value);
53
+ {% else %}
54
+ output[i] = {{ scalar }}({{ source.value }});
55
+ {% endif %}
56
+ {% endif %}
57
+ }
build/webgpu/manifest.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "domain": "ai.onnx",
3
+ "name": "ConstantOfShape",
4
+ "sinceVersion": 9,
5
+ "description": "Generates a tensor filled with a constant value and a caller-specified shape. The shape is provided as a 1-D integer tensor; if empty, the output is a scalar. The fill value and its dtype are taken from the `value` attribute, defaulting to `0` of type float32.",
6
+ "inputs": [
7
+ {
8
+ "role": "input",
9
+ "dtype": "S",
10
+ "description": "Logical int64 1-D tensor whose elements define the output shape; all values must be non-negative and use uint32 WebGPU storage.",
11
+ "rank": 1
12
+ }
13
+ ],
14
+ "outputs": [
15
+ {
16
+ "role": "output",
17
+ "dtype": "T",
18
+ "description": "Output tensor of the shape given by `input`, filled with the constant `value`.",
19
+ "rank": "dim(shapes.input, 0)"
20
+ }
21
+ ],
22
+ "attributes": {},
23
+ "attributeDescriptions": {
24
+ "value": "Optional single-element tensor specifying the fill value and output dtype; defaults to 0 of type float32 if omitted."
25
+ },
26
+ "typeConstraints": {
27
+ "S": ["int64"],
28
+ "T": ["float32", "float16", "int32", "int16", "uint32", "int8", "uint8", "bool"]
29
+ },
30
+ "args": {
31
+ "input": { "kind": "tensor", "semantic": "input", "role": "shape", "dtype": "uint32", "narrowing": "checked" },
32
+ "output": { "kind": "tensor", "semantic": "output", "role": "output" }
33
+ },
34
+ "tunables": { "WORKGROUP_SIZE": 256 },
35
+ "derive": {
36
+ "baseContract": "dtypes.S == \"u32\" and ranks.input == 1 and ranks.output >= 0 and ranks.output <= 8 and f16Ok(dtypes.T) and (has(attrs, \"value\") or tensorDtypes.output == \"float32\")",
37
+ "fillValue": "attrs.value if has(attrs, \"value\") else 0"
38
+ },
39
+ "constants": {
40
+ "scalar": "dtypes.T",
41
+ "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"",
42
+ "outputScalar": "\"vec4<\" ~ dtypes.T ~ \">\" if numel(shapes.output) % 4 == 0 else dtypes.T"
43
+ },
44
+ "bindingSets": {
45
+ "floatFill": [
46
+ {
47
+ "name": "output",
48
+ "arg": "output",
49
+ "semantic": "output",
50
+ "buffer": { "type": "storage" },
51
+ "elementType": "$outputScalar"
52
+ },
53
+ {
54
+ "name": "params",
55
+ "semantic": "kernel.params",
56
+ "buffer": { "type": "uniform" },
57
+ "struct": { "name": "Params", "fields": [{ "name": "value", "type": "f32", "value": "fillValue" }] }
58
+ }
59
+ ],
60
+ "integerFill": [
61
+ {
62
+ "name": "output",
63
+ "arg": "output",
64
+ "semantic": "output",
65
+ "buffer": { "type": "storage" },
66
+ "elementType": "$outputScalar"
67
+ }
68
+ ]
69
+ },
70
+ "variants": [
71
+ {
72
+ "id": "fill_float",
73
+ "when": ["baseContract", "(dtypes.T == \"f32\" or dtypes.T == \"f16\")"],
74
+ "constants": { "usesF16": "dtypes.T == \"f16\"" },
75
+ "passes": [
76
+ {
77
+ "id": "main",
78
+ "name": "ConstantOfShape.float",
79
+ "source": {
80
+ "shader": "constant-of-shape.wgsl.jinja",
81
+ "inputs": {
82
+ "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)",
83
+ "valueFromUniform": true,
84
+ "vectorized": "numel(shapes.output) % 4 == 0"
85
+ }
86
+ },
87
+ "bindings": "floatFill",
88
+ "dispatch": {
89
+ "threads": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)",
90
+ "workgroupSize": "tunables.WORKGROUP_SIZE"
91
+ }
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ "id": "fill_integer",
97
+ "when": ["baseContract", "dtypes.T != \"f32\" and dtypes.T != \"f16\""],
98
+ "constants": { "usesF16": false },
99
+ "passes": [
100
+ {
101
+ "id": "main",
102
+ "name": "ConstantOfShape.integer",
103
+ "source": {
104
+ "shader": "constant-of-shape.wgsl.jinja",
105
+ "inputs": {
106
+ "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)",
107
+ "value": "fillValue",
108
+ "valueFromUniform": false,
109
+ "vectorized": "numel(shapes.output) % 4 == 0"
110
+ }
111
+ },
112
+ "bindings": "integerFill",
113
+ "dispatch": {
114
+ "threads": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)",
115
+ "workgroupSize": "tunables.WORKGROUP_SIZE"
116
+ }
117
+ }
118
+ ]
119
+ }
120
+ ]
121
+ }
build/webgpu/metadata.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "ai.onnx.ConstantOfShape",
3
+ "id": "_ai_onnx_constantofshape_webgpu_8abe390",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "backend": { "type": "webgpu" },
7
+ "digest": {
8
+ "algorithm": "sha256",
9
+ "files": {
10
+ "bench.json": "hw5exM30DtUDB3GcNZRZZLLlss8j08uRGSj+WowzDRI=",
11
+ "constant-of-shape.wgsl.jinja": "vIBoi4zlY5R5eGCNEUQdtotvQnPKLMokdYPvBLr39eg=",
12
+ "manifest.json": "bvhlqmL0sQ4VC3S3twA7PQVbUCmyyQ3H5R6IWmYwEWg=",
13
+ "test.json": "8Y206ANaAdGdYOYNjOOQuuwZ31uxxZx9ZPMuhFzMNWc="
14
+ }
15
+ },
16
+ "provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },
17
+ "webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.ConstantOfShape" }
18
+ }
build/webgpu/test.json ADDED
@@ -0,0 +1,383 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "op": "ai.onnx.ConstantOfShape",
3
+ "usageCase": "zero_default",
4
+ "cases": [
5
+ {
6
+ "name": "zero_default",
7
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 3] } } },
8
+ "outputs": { "output": { "dtype": "float32", "shape": [2, 3] } }
9
+ },
10
+ {
11
+ "name": "f32_vec4_fill_4096",
12
+ "provenance": {
13
+ "notes": "Compact sibling for the f32 ConstantOfShape fill benchmark; preserves a vec4-aligned flat fill without benchmark-scale output."
14
+ },
15
+ "attrs": { "value": -10000 },
16
+ "inputs": { "input": { "dtype": "uint32", "shape": [1], "data": { "kind": "values", "values": [4096] } } },
17
+ "outputs": { "output": { "dtype": "float32", "shape": [4096], "tolerance": 0 } }
18
+ },
19
+ {
20
+ "name": "f32_subnormal_fill_value",
21
+ "provenance": {
22
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
23
+ "test": "ConstantOfShape.Float_Ones",
24
+ "notes": "Valid float32 fill value below the normal range; the uniform-to-storage fill path must preserve finite subnormal payloads."
25
+ },
26
+ "attrs": { "value": 1e-40 },
27
+ "inputs": { "input": { "dtype": "uint32", "shape": [1], "data": { "kind": "values", "values": [4] } } },
28
+ "outputs": {
29
+ "output": {
30
+ "dtype": "float32",
31
+ "shape": [4],
32
+ "tolerance": 0,
33
+ "data": { "kind": "values", "values": [1e-40, 1e-40, 1e-40, 1e-40] }
34
+ }
35
+ }
36
+ },
37
+ {
38
+ "name": "f32_positive_infinity_fill",
39
+ "attrs": { "value": "Infinity" },
40
+ "inputs": { "input": { "dtype": "uint32", "shape": [1], "data": { "kind": "values", "values": [4] } } },
41
+ "outputs": {
42
+ "output": {
43
+ "dtype": "float32",
44
+ "shape": [4],
45
+ "data": { "kind": "values", "values": ["Infinity", "Infinity", "Infinity", "Infinity"] }
46
+ }
47
+ }
48
+ },
49
+ {
50
+ "name": "f32_negative_infinity_fill",
51
+ "attrs": { "value": "-Infinity" },
52
+ "inputs": { "input": { "dtype": "uint32", "shape": [1], "data": { "kind": "values", "values": [3] } } },
53
+ "outputs": {
54
+ "output": {
55
+ "dtype": "float32",
56
+ "shape": [3],
57
+ "data": { "kind": "values", "values": ["-Infinity", "-Infinity", "-Infinity"] }
58
+ }
59
+ }
60
+ },
61
+ {
62
+ "name": "f16_fill",
63
+ "attrs": { "value": 1.5 },
64
+ "inputs": { "input": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [1, 2, 4] } } },
65
+ "outputs": { "output": { "dtype": "float16", "shape": [1, 2, 4] } },
66
+ "tolerance": 0.001
67
+ },
68
+ {
69
+ "name": "scalar_output_empty_shape",
70
+ "attrs": { "value": -4.25 },
71
+ "inputs": { "input": { "dtype": "uint32", "shape": [0], "data": { "kind": "values", "values": [] } } },
72
+ "outputs": { "output": { "dtype": "float32", "shape": [], "tolerance": 0.000001 } }
73
+ },
74
+ {
75
+ "name": "rank7_output_fill",
76
+ "attrs": { "value": -2.75 },
77
+ "inputs": {
78
+ "input": { "dtype": "uint32", "shape": [7], "data": { "kind": "values", "values": [1, 2, 1, 3, 1, 2, 2] } }
79
+ },
80
+ "outputs": { "output": { "dtype": "float32", "shape": [1, 2, 1, 3, 1, 2, 2], "tolerance": 0.000001 } }
81
+ },
82
+ {
83
+ "name": "zero_sized_output_fill",
84
+ "attrs": { "value": 6.5 },
85
+ "inputs": { "input": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [2, 0, 3] } } },
86
+ "outputs": { "output": { "dtype": "float32", "shape": [2, 0, 3], "tolerance": 0.000001 } }
87
+ },
88
+ {
89
+ "name": "ort_int32_zeros_10x6",
90
+ "provenance": {
91
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
92
+ "test": "ConstantOfShape.Int32_Zeros"
93
+ },
94
+ "attrs": { "value": 0 },
95
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [10, 6] } } },
96
+ "outputs": { "output": { "dtype": "int32", "shape": [10, 6], "tolerance": 0 } }
97
+ },
98
+ {
99
+ "name": "int32_negative_fill_exact",
100
+ "attrs": { "value": -17 },
101
+ "inputs": { "input": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [2, 1, 3] } } },
102
+ "outputs": { "output": { "dtype": "int32", "shape": [2, 1, 3], "tolerance": 0 } }
103
+ },
104
+ {
105
+ "name": "uint32_fill_exact_above_float24",
106
+ "attrs": { "value": 16777217 },
107
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 3] } } },
108
+ "outputs": { "output": { "dtype": "uint32", "shape": [2, 3], "tolerance": 0 } }
109
+ },
110
+ {
111
+ "name": "ort_float_ones_4x3x2",
112
+ "attrs": { "value": 1 },
113
+ "provenance": {
114
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
115
+ "test": "ConstantOfShape.Float_Ones"
116
+ },
117
+ "inputs": { "input": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [4, 3, 2] } } },
118
+ "outputs": { "output": { "dtype": "float32", "shape": [4, 3, 2], "tolerance": 0 } }
119
+ },
120
+ {
121
+ "name": "ort_default_value_float_zeros_2x6",
122
+ "provenance": {
123
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
124
+ "test": "ConstantOfShape.DefaultValue"
125
+ },
126
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 6] } } },
127
+ "outputs": { "output": { "dtype": "float32", "shape": [2, 6], "tolerance": 0 } }
128
+ },
129
+ {
130
+ "name": "ort_type_test_float16_bits_value",
131
+ "attrs": { "value": 2.980232238769531e-7 },
132
+ "provenance": {
133
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
134
+ "test": "ConstantOfShape.TypeTests",
135
+ "notes": "FLOAT16 typed value from raw bits 5, represented as its numeric half value."
136
+ },
137
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 6] } } },
138
+ "outputs": { "output": { "dtype": "float16", "shape": [2, 6], "tolerance": 0 } }
139
+ },
140
+ {
141
+ "name": "ort_type_test_uint32_2x6",
142
+ "attrs": { "value": 32 },
143
+ "provenance": {
144
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
145
+ "test": "ConstantOfShape.TypeTests",
146
+ "notes": "UINT32 typed value."
147
+ },
148
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 6] } } },
149
+ "outputs": { "output": { "dtype": "uint32", "shape": [2, 6], "tolerance": 0 } }
150
+ },
151
+ {
152
+ "name": "ort_type_test_int32_exact_above_float24",
153
+ "attrs": { "value": 20000001 },
154
+ "provenance": {
155
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
156
+ "test": "ConstantOfShape.TypeTests",
157
+ "notes": "INT32 typed value variant extended above f32's exact integer range."
158
+ },
159
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 3] } } },
160
+ "outputs": { "output": { "dtype": "int32", "shape": [2, 3], "tolerance": 0 } }
161
+ },
162
+ {
163
+ "name": "ort_type_test_int16_2x6",
164
+ "attrs": { "value": 16 },
165
+ "provenance": {
166
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
167
+ "test": "ConstantOfShape.TypeTests",
168
+ "notes": "INT16 typed value from ORT's ConstantOfShape TypeTests."
169
+ },
170
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 6] } } },
171
+ "outputs": { "output": { "dtype": "int16", "shape": [2, 6], "tolerance": 0 } }
172
+ },
173
+ {
174
+ "name": "ort_type_test_int16_min_fill",
175
+ "attrs": { "value": -32768 },
176
+ "provenance": {
177
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
178
+ "test": "ConstantOfShape.TypeTests",
179
+ "notes": "Signed int16 sentinel extension of ORT's typed ConstantOfShape TypeTests."
180
+ },
181
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 3] } } },
182
+ "outputs": {
183
+ "output": {
184
+ "dtype": "int16",
185
+ "shape": [2, 3],
186
+ "data": { "kind": "values", "values": [-32768, -32768, -32768, -32768, -32768, -32768] },
187
+ "tolerance": 0
188
+ }
189
+ }
190
+ },
191
+ {
192
+ "name": "ort_type_test_uint32_large_exact",
193
+ "attrs": { "value": 4000000001 },
194
+ "provenance": {
195
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
196
+ "test": "ConstantOfShape.TypeTests",
197
+ "notes": "UINT32 typed value variant extended above f32's exact integer range."
198
+ },
199
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 3] } } },
200
+ "outputs": { "output": { "dtype": "uint32", "shape": [2, 3], "tolerance": 0 } }
201
+ },
202
+ {
203
+ "name": "ort_type_test_int8_min_fill",
204
+ "attrs": { "value": -128 },
205
+ "provenance": {
206
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
207
+ "test": "ConstantOfShape.TypeTests",
208
+ "notes": "Exercises the same typed TensorProto value path as ORT's int8 TypeTests with a signed edge value."
209
+ },
210
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 6] } } },
211
+ "outputs": { "output": { "dtype": "int8", "shape": [2, 6], "tolerance": 0 } }
212
+ },
213
+ {
214
+ "name": "ort_type_test_uint8_high_fill",
215
+ "attrs": { "value": 250 },
216
+ "provenance": {
217
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
218
+ "test": "ConstantOfShape.TypeTests",
219
+ "notes": "Exercises the same typed TensorProto value path as ORT's uint8 TypeTests with a high logical byte value."
220
+ },
221
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 6] } } },
222
+ "outputs": { "output": { "dtype": "uint8", "shape": [2, 6], "tolerance": 0 } }
223
+ },
224
+ {
225
+ "name": "bool_true_fill",
226
+ "attrs": { "value": 1 },
227
+ "provenance": {
228
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc",
229
+ "test": "ConstantOfShape.TypeTests",
230
+ "notes": "ORT source notes bool was skipped only because its C++ test harness cannot use vector<bool> as a contiguous buffer."
231
+ },
232
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 3] } } },
233
+ "outputs": {
234
+ "output": {
235
+ "dtype": "bool",
236
+ "shape": [2, 3],
237
+ "data": { "kind": "values", "values": [1, 1, 1, 1, 1, 1] },
238
+ "tolerance": 0
239
+ }
240
+ }
241
+ },
242
+ {
243
+ "name": "onnx_backend_constantofshape_float_ones",
244
+ "inputs": { "input": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [4, 3, 2] } } },
245
+ "outputs": { "output": { "dtype": "float32", "shape": [4, 3, 2] } },
246
+ "provenance": {
247
+ "source": "cmake/external/onnx/onnx/backend/test/data/node/test_constantofshape_float_ones",
248
+ "notes": "ONNX int64 metadata/index tensors use framework int32/uint32 slots where representable."
249
+ }
250
+ },
251
+ {
252
+ "name": "onnx_backend_constantofshape_int_shape_zero",
253
+ "inputs": { "input": { "dtype": "uint32", "shape": [1], "data": { "kind": "values", "values": [0] } } },
254
+ "outputs": { "output": { "dtype": "int32", "shape": [0] } },
255
+ "provenance": {
256
+ "source": "cmake/external/onnx/onnx/backend/test/data/node/test_constantofshape_int_shape_zero",
257
+ "notes": "ONNX int64 metadata/index tensors use framework int32/uint32 slots where representable. ONNX tensor-valued value attribute represented as scalar framework value attr."
258
+ },
259
+ "attrs": { "value": 0 }
260
+ },
261
+ {
262
+ "name": "onnx_backend_constantofshape_int_zeros",
263
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [10, 6] } } },
264
+ "outputs": { "output": { "dtype": "int32", "shape": [10, 6] } },
265
+ "provenance": {
266
+ "source": "cmake/external/onnx/onnx/backend/test/data/node/test_constantofshape_int_zeros",
267
+ "notes": "ONNX int64 metadata/index tensors use framework int32/uint32 slots where representable. ONNX tensor-valued value attribute represented as scalar framework value attr."
268
+ },
269
+ "attrs": { "value": 0 }
270
+ },
271
+ {
272
+ "name": "rank8_output_scalar_fill",
273
+ "attrs": { "value": 3.5 },
274
+ "provenance": {
275
+ "source": "onnx spec: ConstantOfShape output rank = len(shape input), unbounded",
276
+ "notes": "Fills a rank-8 tensor with the scalar float32 value 3.5."
277
+ },
278
+ "inputs": {
279
+ "input": { "dtype": "uint32", "shape": [8], "data": { "kind": "values", "values": [2, 1, 2, 1, 2, 1, 2, 1] } }
280
+ },
281
+ "outputs": { "output": { "dtype": "float32", "shape": [2, 1, 2, 1, 2, 1, 2, 1], "tolerance": 0 } }
282
+ },
283
+ {
284
+ "name": "rank8_output_oddnumel_fill",
285
+ "attrs": { "value": -1.25 },
286
+ "provenance": {
287
+ "source": "onnx spec: ConstantOfShape arbitrary output rank",
288
+ "notes": "Rank-8 float32 fill with numel 18 (%4 != 0 -> would target the fill_float SCALAR fallback). Distinct from the vec4 case so the fix is pinned on BOTH the vec4 and the scalar fill paths. ORT CPU computes it; GPU throws because every variant gates ranks.output <= 7."
289
+ },
290
+ "inputs": {
291
+ "input": { "dtype": "uint32", "shape": [8], "data": { "kind": "values", "values": [2, 1, 3, 1, 1, 3, 1, 1] } }
292
+ },
293
+ "outputs": { "output": { "dtype": "float32", "shape": [2, 1, 3, 1, 1, 3, 1, 1], "tolerance": 0 } }
294
+ },
295
+ {
296
+ "name": "f16_oddnumel_scalar_fill",
297
+ "attrs": { "value": -2.5 },
298
+ "provenance": {
299
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc (TypeTests float16)",
300
+ "notes": "A 15-element float16 output exercises the scalar fill path because its element count is not divisible by four. The value is exactly representable in float16."
301
+ },
302
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [3, 5] } } },
303
+ "outputs": { "output": { "dtype": "float16", "shape": [3, 5], "tolerance": 0.001 } }
304
+ },
305
+ {
306
+ "name": "u32_oddnumel_scalar_fill",
307
+ "attrs": { "value": 7 },
308
+ "provenance": {
309
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc (TypeTests uint32)",
310
+ "notes": "Clean coverage: uint32 output with numel 15 (%4 != 0) selects the scalar branch of fill_integer. Existing uint32 cases are vec4-aligned, so this pins the scalar integer fill path."
311
+ },
312
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [3, 5] } } },
313
+ "outputs": { "output": { "dtype": "uint32", "shape": [3, 5], "tolerance": 0 } }
314
+ },
315
+ {
316
+ "name": "int32_vec4_fill_16m_2dfold_correctness",
317
+ "attrs": { "value": 123456789 },
318
+ "provenance": {
319
+ "source": "onnx spec: ConstantOfShape flat memset; 2D dispatch-fold guard",
320
+ "notes": "Vec4 int32 fill with numel 67108864 selects fill_integer's vectorized branch. numel/4 = 16777216 > 65535*256, so gid.y carries the high bits. Verifies the fold index+guard writes every element including the gid.y>0 region. Every element must equal 123456789."
321
+ },
322
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [8192, 8192] } } },
323
+ "outputs": {
324
+ "output": {
325
+ "dtype": "int32",
326
+ "shape": [8192, 8192],
327
+ "data": { "kind": "constant", "value": 123456789 },
328
+ "tolerance": 0
329
+ }
330
+ }
331
+ },
332
+ {
333
+ "name": "i32_vec4_min_int32_fill_exact",
334
+ "attrs": { "value": -2147483648 },
335
+ "provenance": {
336
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc (TypeTests int32) extended to INT32_MIN",
337
+ "notes": "Numel 8 selects fill_integer's vectorized branch. The full-width signed sentinel verifies the value is specialized as i32 with no f32 round-trip. Every element must equal -2147483648."
338
+ },
339
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 4] } } },
340
+ "outputs": {
341
+ "output": {
342
+ "dtype": "int32",
343
+ "shape": [2, 4],
344
+ "data": {
345
+ "kind": "values",
346
+ "values": [-2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648]
347
+ },
348
+ "tolerance": 0
349
+ }
350
+ }
351
+ },
352
+ {
353
+ "name": "u32_vec4_max_uint32_fill_exact",
354
+ "attrs": { "value": 4294967295 },
355
+ "provenance": {
356
+ "source": "onnxruntime/test/providers/cpu/generator/constant_of_shape_test.cc (TypeTests uint32) extended to UINT32_MAX",
357
+ "notes": "Numel 8 selects fill_integer's vectorized branch. The full-width unsigned sentinel verifies the value is specialized as u32 with no f32 round-trip (which would wrap 4294967295 to 0). Every element must equal 4294967295."
358
+ },
359
+ "inputs": { "input": { "dtype": "uint32", "shape": [2], "data": { "kind": "values", "values": [2, 4] } } },
360
+ "outputs": {
361
+ "output": {
362
+ "dtype": "uint32",
363
+ "shape": [2, 4],
364
+ "data": {
365
+ "kind": "values",
366
+ "values": [4294967295, 4294967295, 4294967295, 4294967295, 4294967295, 4294967295, 4294967295, 4294967295]
367
+ },
368
+ "tolerance": 0
369
+ }
370
+ }
371
+ },
372
+ {
373
+ "name": "i32_vec4_dim1_first_zero_sized_output",
374
+ "attrs": { "value": -17 },
375
+ "provenance": {
376
+ "source": "onnx spec: ConstantOfShape with a zero extent -> empty output; array<T,0> compile-crash class",
377
+ "notes": "shape [0,5,3] -> numel 0, dtypes.T==i32. Verifies the i32 vec4/scalar fill path does not crash on a leading-zero empty output. Existing zero_sized_output_fill covers f32 with a middle zero."
378
+ },
379
+ "inputs": { "input": { "dtype": "uint32", "shape": [3], "data": { "kind": "values", "values": [0, 5, 3] } } },
380
+ "outputs": { "output": { "dtype": "int32", "shape": [0, 5, 3], "tolerance": 0 } }
381
+ }
382
+ ]
383
+ }