sync 6fdf6301e2bb
Browse files- README.md +3 -3
- build/webgpu/manifest.json +12 -9
- build/webgpu/metadata.json +5 -5
- build/webgpu/test.json +36 -2
README.md
CHANGED
|
@@ -40,21 +40,21 @@ Default values (overridable per request):
|
|
| 40 |
|
| 41 |
| Variable | Allowed dtypes |
|
| 42 |
| --- | --- |
|
| 43 |
-
| `T` | `float32`, `float16`, `int32`, `uint32`, `int16`, `int8`, `uint8`, `bool` |
|
| 44 |
|
| 45 |
## Files
|
| 46 |
|
| 47 |
- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)
|
| 48 |
- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
|
| 49 |
- [`test.json`](build/webgpu/test.json) — correctness cases
|
| 50 |
-
- [`bench.json`](build/webgpu/bench.json) — benchmark
|
| 51 |
- [`datamove-elementwise-copy.wgsl.jinja`](build/webgpu/datamove-elementwise-copy.wgsl.jinja)
|
| 52 |
- [`datamove-flat-copy.wgsl.jinja`](build/webgpu/datamove-flat-copy.wgsl.jinja)
|
| 53 |
|
| 54 |
## Use with `@huggingface/kernels`
|
| 55 |
|
| 56 |
```sh
|
| 57 |
-
npm install --save-exact @huggingface/kernels@0.0.1-preview.
|
| 58 |
```
|
| 59 |
|
| 60 |
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
|
|
|
|
| 40 |
|
| 41 |
| Variable | Allowed dtypes |
|
| 42 |
| --- | --- |
|
| 43 |
+
| `T` | `float32`, `float16`, `int32`, `uint32`, `int16`, `int8`, `uint8`, `bool`, `int64` |
|
| 44 |
|
| 45 |
## Files
|
| 46 |
|
| 47 |
- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)
|
| 48 |
- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
|
| 49 |
- [`test.json`](build/webgpu/test.json) — correctness cases
|
| 50 |
+
- [`bench.json`](build/webgpu/bench.json) — benchmark cases
|
| 51 |
- [`datamove-elementwise-copy.wgsl.jinja`](build/webgpu/datamove-elementwise-copy.wgsl.jinja)
|
| 52 |
- [`datamove-flat-copy.wgsl.jinja`](build/webgpu/datamove-flat-copy.wgsl.jinja)
|
| 53 |
|
| 54 |
## Use with `@huggingface/kernels`
|
| 55 |
|
| 56 |
```sh
|
| 57 |
+
npm install --save-exact @huggingface/kernels@0.0.1-preview.3
|
| 58 |
```
|
| 59 |
|
| 60 |
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
|
build/webgpu/manifest.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
| 11 |
}
|
| 12 |
},
|
| 13 |
"attributes": { "axis": { "default": 1 } },
|
| 14 |
-
"typeConstraints": { "T": ["float32", "float16", "int32", "uint32", "int16", "int8", "uint8", "bool"] },
|
| 15 |
"tunables": { "WORKGROUP_SIZE": { "default": 256 } },
|
| 16 |
"derive": {
|
| 17 |
"axisInRange": "attrs.axis == floor(attrs.axis) and attrs.axis >= 0 - ranks.input and attrs.axis <= ranks.input",
|
|
@@ -20,22 +20,25 @@
|
|
| 20 |
"baseContract": "flattenShapeOk and f16Ok(dtypes.T)"
|
| 21 |
},
|
| 22 |
"when": ["baseContract"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
"variants": [
|
| 24 |
{
|
| 25 |
"id": "copy_vec4",
|
| 26 |
"priority": 20,
|
| 27 |
-
"when": ["numel(shapes.input) > 0", "numel(shapes.input) % 4 == 0"],
|
| 28 |
"derive": { "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },
|
| 29 |
"passes": [
|
| 30 |
{
|
| 31 |
"id": "main",
|
| 32 |
-
"name": "Flatten.
|
| 33 |
"shader": "datamove-flat-copy.wgsl.jinja",
|
| 34 |
"derive": { "count": "numel(shapes.output) / 4" },
|
| 35 |
-
"bindings": [
|
| 36 |
-
{ "arg": "input", "name": "src", "elementType": "$vectorScalar" },
|
| 37 |
-
{ "arg": "output", "name": "dst", "elementType": "$vectorScalar" }
|
| 38 |
-
],
|
| 39 |
"dispatch": {
|
| 40 |
"x": "min(ceilDiv((numel(shapes.output) / 4), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))",
|
| 41 |
"y": 1,
|
|
@@ -54,8 +57,8 @@
|
|
| 54 |
"name": "Flatten",
|
| 55 |
"shader": "datamove-elementwise-copy.wgsl.jinja",
|
| 56 |
"bindings": [
|
| 57 |
-
|
| 58 |
-
|
| 59 |
{ "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] }
|
| 60 |
],
|
| 61 |
"dispatch": {
|
|
|
|
| 11 |
}
|
| 12 |
},
|
| 13 |
"attributes": { "axis": { "default": 1 } },
|
| 14 |
+
"typeConstraints": { "T": ["float32", "float16", "int32", "uint32", "int16", "int8", "uint8", "bool", "int64"] },
|
| 15 |
"tunables": { "WORKGROUP_SIZE": { "default": 256 } },
|
| 16 |
"derive": {
|
| 17 |
"axisInRange": "attrs.axis == floor(attrs.axis) and attrs.axis >= 0 - ranks.input and attrs.axis <= ranks.input",
|
|
|
|
| 20 |
"baseContract": "flattenShapeOk and f16Ok(dtypes.T)"
|
| 21 |
},
|
| 22 |
"when": ["baseContract"],
|
| 23 |
+
"bindings": {
|
| 24 |
+
"src": { "arg": "input", "elementType": "$vectorScalar" },
|
| 25 |
+
"dst": { "arg": "output", "elementType": "$vectorScalar" },
|
| 26 |
+
"x": { "arg": "input", "elementType": "$scalar" },
|
| 27 |
+
"y": { "arg": "output", "elementType": "$scalar" }
|
| 28 |
+
},
|
| 29 |
"variants": [
|
| 30 |
{
|
| 31 |
"id": "copy_vec4",
|
| 32 |
"priority": 20,
|
| 33 |
+
"when": ["dtypes.T != \"vec2<u32>\"", "numel(shapes.input) > 0", "numel(shapes.input) % 4 == 0"],
|
| 34 |
"derive": { "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },
|
| 35 |
"passes": [
|
| 36 |
{
|
| 37 |
"id": "main",
|
| 38 |
+
"name": "Flatten.CopyVec4",
|
| 39 |
"shader": "datamove-flat-copy.wgsl.jinja",
|
| 40 |
"derive": { "count": "numel(shapes.output) / 4" },
|
| 41 |
+
"bindings": ["src", "dst"],
|
|
|
|
|
|
|
|
|
|
| 42 |
"dispatch": {
|
| 43 |
"x": "min(ceilDiv((numel(shapes.output) / 4), (tunables.WORKGROUP_SIZE)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))",
|
| 44 |
"y": 1,
|
|
|
|
| 57 |
"name": "Flatten",
|
| 58 |
"shader": "datamove-elementwise-copy.wgsl.jinja",
|
| 59 |
"bindings": [
|
| 60 |
+
"x",
|
| 61 |
+
"y",
|
| 62 |
{ "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] }
|
| 63 |
],
|
| 64 |
"dispatch": {
|
build/webgpu/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "ai.onnx.Flatten",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"backend": { "type": "webgpu" },
|
|
@@ -10,13 +10,13 @@
|
|
| 10 |
"bench.json": "FS0xOpUC7d41FBW9+EvJwtD83YRoeO1BAurg5W301vk=",
|
| 11 |
"datamove-elementwise-copy.wgsl.jinja": "Q1WuZCqcDf9b6cbT4rLilpeWj6327t/bSFmKr6IVBoQ=",
|
| 12 |
"datamove-flat-copy.wgsl.jinja": "g9d62mer2bmHfbScqX5CIT5Zq/Pdinac0W2dH0CD+5s=",
|
| 13 |
-
"manifest.json": "
|
| 14 |
-
"test.json": "
|
| 15 |
}
|
| 16 |
},
|
| 17 |
-
"provenance": { "kernel": { "sha": "
|
| 18 |
"webgpu": {
|
| 19 |
-
"manifestSpec": "2.
|
| 20 |
"variants": { "copy_vec4": ["datamove-flat-copy.wgsl.jinja"], "copy": ["datamove-elementwise-copy.wgsl.jinja"] }
|
| 21 |
}
|
| 22 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"name": "ai.onnx.Flatten",
|
| 3 |
+
"id": "_ai_onnx_flatten_webgpu_936cbae",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"backend": { "type": "webgpu" },
|
|
|
|
| 10 |
"bench.json": "FS0xOpUC7d41FBW9+EvJwtD83YRoeO1BAurg5W301vk=",
|
| 11 |
"datamove-elementwise-copy.wgsl.jinja": "Q1WuZCqcDf9b6cbT4rLilpeWj6327t/bSFmKr6IVBoQ=",
|
| 12 |
"datamove-flat-copy.wgsl.jinja": "g9d62mer2bmHfbScqX5CIT5Zq/Pdinac0W2dH0CD+5s=",
|
| 13 |
+
"manifest.json": "/YeGbtGrjf86H8Uxr1jAAnxslJD4exIAAwdQ171AjLg=",
|
| 14 |
+
"test.json": "qj89lMwG1H8/e5SHvKBoU+4HkM9lBxtwGqZZ8wFyooI="
|
| 15 |
}
|
| 16 |
},
|
| 17 |
+
"provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },
|
| 18 |
"webgpu": {
|
| 19 |
+
"manifestSpec": "2.1",
|
| 20 |
"variants": { "copy_vec4": ["datamove-flat-copy.wgsl.jinja"], "copy": ["datamove-elementwise-copy.wgsl.jinja"] }
|
| 21 |
}
|
| 22 |
}
|
build/webgpu/test.json
CHANGED
|
@@ -219,7 +219,7 @@
|
|
| 219 |
"provenance": {
|
| 220 |
"source": "onnxruntime/test/providers/cpu/nn/flatten_op_test.cc",
|
| 221 |
"test": "FlattenOpModelTest.Flatten_broadcast",
|
| 222 |
-
"notes": "
|
| 223 |
},
|
| 224 |
"attrs": { "axis": 0 },
|
| 225 |
"inputs": {
|
|
@@ -376,7 +376,7 @@
|
|
| 376 |
{
|
| 377 |
"name": "scalar_copy_dispatch_clamp",
|
| 378 |
"provenance": {
|
| 379 |
-
"notes": "
|
| 380 |
},
|
| 381 |
"attrs": { "axis": 1 },
|
| 382 |
"tunables": { "WORKGROUP_SIZE": 4 },
|
|
@@ -414,6 +414,40 @@
|
|
| 414 |
}
|
| 415 |
},
|
| 416 |
"outputs": { "output": { "dtype": "float16", "shape": [2, 3], "tolerance": 0 } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
}
|
| 418 |
]
|
| 419 |
}
|
|
|
|
| 219 |
"provenance": {
|
| 220 |
"source": "onnxruntime/test/providers/cpu/nn/flatten_op_test.cc",
|
| 221 |
"test": "FlattenOpModelTest.Flatten_broadcast",
|
| 222 |
+
"notes": "Flatten with axis=0 turns a rank-1, 4-element vector into a [1,4] row tensor, projected from ONNX Runtime's Flatten_broadcast model test where the output feeds a following broadcast Mul."
|
| 223 |
},
|
| 224 |
"attrs": { "axis": 0 },
|
| 225 |
"inputs": {
|
|
|
|
| 376 |
{
|
| 377 |
"name": "scalar_copy_dispatch_clamp",
|
| 378 |
"provenance": {
|
| 379 |
+
"notes": "Flatten with axis=1 turns a 262,141-element vector into a [262141, 1] tensor; the count is one more than 65,535 groups of four, past the WebGPU per-dimension workgroup limit, and every element must be copied exactly once."
|
| 380 |
},
|
| 381 |
"attrs": { "axis": 1 },
|
| 382 |
"tunables": { "WORKGROUP_SIZE": 4 },
|
|
|
|
| 414 |
}
|
| 415 |
},
|
| 416 |
"outputs": { "output": { "dtype": "float16", "shape": [2, 3], "tolerance": 0 } }
|
| 417 |
+
},
|
| 418 |
+
{
|
| 419 |
+
"name": "int64_full_range_int16_copy_boundaries",
|
| 420 |
+
"attrs": { "axis": 1 },
|
| 421 |
+
"inputs": {
|
| 422 |
+
"input": {
|
| 423 |
+
"dtype": "int64",
|
| 424 |
+
"shape": [2, 2],
|
| 425 |
+
"data": {
|
| 426 |
+
"kind": "cycle",
|
| 427 |
+
"values": ["0", "4294967296", "8589934593", "-4294967297", "9223372036854775807", "-9223372036854775808", "9223372036854775806", "-1"]
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
},
|
| 431 |
+
"outputs": { "output": { "dtype": "int64", "shape": [2, 2], "tolerance": 0, "relTolerance": 0 } },
|
| 432 |
+
"tolerance": 0,
|
| 433 |
+
"relTolerance": 0
|
| 434 |
+
},
|
| 435 |
+
{
|
| 436 |
+
"name": "int64_full_range_rank3_to_2d",
|
| 437 |
+
"attrs": { "axis": 1 },
|
| 438 |
+
"inputs": {
|
| 439 |
+
"input": {
|
| 440 |
+
"dtype": "int64",
|
| 441 |
+
"shape": [2, 3, 4],
|
| 442 |
+
"data": {
|
| 443 |
+
"kind": "cycle",
|
| 444 |
+
"values": ["4294967296", "8589934593", "-4294967297", "9223372036854775807", "-9223372036854775808", "9223372036854775806", "-1", "0"]
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
},
|
| 448 |
+
"outputs": { "output": { "dtype": "int64", "shape": [2, 12], "tolerance": 0, "relTolerance": 0 } },
|
| 449 |
+
"tolerance": 0,
|
| 450 |
+
"relTolerance": 0
|
| 451 |
}
|
| 452 |
]
|
| 453 |
}
|