Xenova HF Staff commited on
Commit
441d3bb
·
verified ·
1 Parent(s): 52513d8

sync 4385228f788d

Browse files
README.md CHANGED
@@ -18,15 +18,15 @@ See the [ONNX `Log` spec](https://onnx.ai/onnx/operators/onnx__Log.html) for the
18
 
19
  ## Inputs
20
 
21
- | Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence |
22
- | --- | --- | --- | --- | --- | --- | --- |
23
- | `x` | `input` | `T` | — | — | Values whose natural logarithms are computed elementwise. | required |
24
 
25
  ## Outputs
26
 
27
- | Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence |
28
- | --- | --- | --- | --- | --- | --- | --- |
29
- | `y` | `output` | `T` | same as `x` | same as `x` | The natural log of the input tensor, computed elementwise. | required |
30
 
31
  ## Type constraints
32
 
@@ -36,29 +36,33 @@ See the [ONNX `Log` spec](https://onnx.ai/onnx/operators/onnx__Log.html) for the
36
 
37
  ## Files
38
 
39
- - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)
40
- - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
41
- - [`test.json`](build/webgpu/test.json) — correctness cases
42
- - [`bench.json`](build/webgpu/bench.json) — benchmark cases
43
- - [`unary-scalar.wgsl.jinja`](build/webgpu/unary-scalar.wgsl.jinja)
44
- - [`unary-vec4.wgsl.jinja`](build/webgpu/unary-vec4.wgsl.jinja)
45
 
46
  ## Use with `@huggingface/kernels`
47
 
48
  ```sh
49
- npm install --save-exact @huggingface/kernels@0.0.1-preview.3
50
  ```
51
 
 
 
52
  Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
53
 
54
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
55
  It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
56
 
57
- Replace each `*Data` placeholder with a typed array containing the corresponding input data.
58
-
59
  ```js
60
  import { getKernel } from "@huggingface/kernels";
61
 
62
  const kernel = await getKernel("webgpu-kernels/ai.onnx.Log", { version: 1 });
63
- const { y } = await kernel({ x: { data: xData, shape: [2] } });
 
 
 
 
64
  ```
 
18
 
19
  ## Inputs
20
 
21
+ | Name | Logical dtype | Rank | Shape | Description | Presence |
22
+ | --- | --- | --- | --- | --- | --- |
23
+ | `input` | `T` | — | — | Values whose natural logarithms are computed elementwise. | required |
24
 
25
  ## Outputs
26
 
27
+ | Name | Logical dtype | Rank | Shape | Description | Presence |
28
+ | --- | --- | --- | --- | --- | --- |
29
+ | `output` | `T` | same as `input` | same as `input` | The natural log of the input tensor, computed elementwise. | required |
30
 
31
  ## Type constraints
32
 
 
36
 
37
  ## Files
38
 
39
+ - [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Log/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)
40
+ - [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Log/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)
41
+ - [`test.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Log/blob/v1/build/webgpu/test.json) — correctness cases
42
+ - [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Log/blob/v1/build/webgpu/bench.json) — benchmark cases
43
+ - [`unary-scalar.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Log/blob/v1/build/webgpu/unary-scalar.wgsl.jinja)
44
+ - [`unary-vec4.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.Log/blob/v1/build/webgpu/unary-vec4.wgsl.jinja)
45
 
46
  ## Use with `@huggingface/kernels`
47
 
48
  ```sh
49
+ npm install --save-exact @huggingface/kernels@0.0.1-preview.4
50
  ```
51
 
52
+ Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
53
+
54
  Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
55
 
56
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
57
  It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
58
 
 
 
59
  ```js
60
  import { getKernel } from "@huggingface/kernels";
61
 
62
  const kernel = await getKernel("webgpu-kernels/ai.onnx.Log", { version: 1 });
63
+
64
+ const inputData = Float32Array.of(1, 10);
65
+
66
+ const { output } = await kernel({ input: { data: inputData, shape: [2] } });
67
+ console.log({ output });
68
  ```
build/webgpu/bench.json CHANGED
@@ -6,9 +6,9 @@
6
  "preset": "smoke",
7
  "vars": { "dtype": "float32", "count": 1048576 },
8
  "inputs": {
9
- "x": { "shape": [1048576], "dtype": "float32", "dist": "uniform", "seed": 910, "scale": 1, "offset": 1 }
10
  },
11
- "outputs": { "y": { "shape": [1048576], "dtype": "float32" } },
12
  "bench": {
13
  "primary": true,
14
  "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }]
@@ -19,9 +19,9 @@
19
  "preset": "smoke",
20
  "vars": { "dtype": "float32", "count": 8388608 },
21
  "inputs": {
22
- "x": { "shape": [8388608], "dtype": "float32", "seed": 7011, "dist": "uniform", "scale": 1, "offset": 1 }
23
  },
24
- "outputs": { "y": { "shape": [8388608], "dtype": "float32" } },
25
  "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
26
  },
27
  {
@@ -29,9 +29,9 @@
29
  "preset": "smoke",
30
  "vars": { "dtype": "float16", "count": 8388608 },
31
  "inputs": {
32
- "x": { "shape": [8388608], "dtype": "float16", "seed": 7012, "dist": "uniform", "scale": 1, "offset": 1 }
33
  },
34
- "outputs": { "y": { "shape": [8388608], "dtype": "float16" } },
35
  "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
36
  },
37
  {
@@ -39,9 +39,9 @@
39
  "preset": "edge",
40
  "vars": { "dtype": "float32", "count": 1048577 },
41
  "inputs": {
42
- "x": { "shape": [1048577], "dtype": "float32", "dist": "uniform", "seed": 7031, "scale": 1, "offset": 1 }
43
  },
44
- "outputs": { "y": { "shape": [1048577], "dtype": "float32" } },
45
  "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
46
  }
47
  ]
 
6
  "preset": "smoke",
7
  "vars": { "dtype": "float32", "count": 1048576 },
8
  "inputs": {
9
+ "input": { "shape": [1048576], "dtype": "float32", "dist": "uniform", "seed": 910, "scale": 1, "offset": 1 }
10
  },
11
+ "outputs": { "output": { "shape": [1048576], "dtype": "float32" } },
12
  "bench": {
13
  "primary": true,
14
  "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }]
 
19
  "preset": "smoke",
20
  "vars": { "dtype": "float32", "count": 8388608 },
21
  "inputs": {
22
+ "input": { "shape": [8388608], "dtype": "float32", "seed": 7011, "dist": "uniform", "scale": 1, "offset": 1 }
23
  },
24
+ "outputs": { "output": { "shape": [8388608], "dtype": "float32" } },
25
  "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
26
  },
27
  {
 
29
  "preset": "smoke",
30
  "vars": { "dtype": "float16", "count": 8388608 },
31
  "inputs": {
32
+ "input": { "shape": [8388608], "dtype": "float16", "seed": 7012, "dist": "uniform", "scale": 1, "offset": 1 }
33
  },
34
+ "outputs": { "output": { "shape": [8388608], "dtype": "float16" } },
35
  "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
36
  },
37
  {
 
39
  "preset": "edge",
40
  "vars": { "dtype": "float32", "count": 1048577 },
41
  "inputs": {
42
+ "input": { "shape": [1048577], "dtype": "float32", "dist": "uniform", "seed": 7031, "scale": 1, "offset": 1 }
43
  },
44
+ "outputs": { "output": { "shape": [1048577], "dtype": "float32" } },
45
  "bench": { "metrics": [{ "type": "bandwidth", "value": "args.count * dtypeBytes(args.dtype) * 2" }] }
46
  }
47
  ]
build/webgpu/manifest.json CHANGED
@@ -1,100 +1 @@
1
- {
2
- "domain": "ai.onnx",
3
- "name": "Log",
4
- "sinceVersion": 13,
5
- "inputs": { "x": { "onnx": "input", "dtype": "T" } },
6
- "outputs": { "y": { "onnx": "output", "dtype": "T", "rank": "ranks.x", "shape": "shapes.x" } },
7
- "typeConstraints": { "T": ["float32", "float16"] },
8
- "tunables": { "WORKGROUP_SIZE": { "default": 256 } },
9
- "variants": [
10
- {
11
- "id": "same_layout_vec4",
12
- "priority": 20,
13
- "when": ["numel(shapes.x) > 0", "numel(shapes.x) % 4 == 0", "numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)"],
14
- "derive": { "scalar": "dtypes.T", "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },
15
- "passes": [
16
- {
17
- "id": "main",
18
- "name": "Log.Vec4",
19
- "shader": "unary-vec4.wgsl.jinja",
20
- "derive": { "vec4PerThread": "4 if numel(shapes.y) * dtypeBytes(tensorDtypes.y) <= 16777216 else 1" },
21
- "bindings": ["x", "y", "params_unary"],
22
- "dispatch": {
23
- "x": "min(ceilDiv((ceilDiv(numel(shapes.y) / 4, 4 if numel(shapes.y) * dtypeBytes(tensorDtypes.y) <= 16777216 else 1)), (tunables.WORKGROUP_SIZE)), 65535)",
24
- "y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.y) / 4, 4 if numel(shapes.y) * dtypeBytes(tensorDtypes.y) <= 16777216 else 1)), (tunables.WORKGROUP_SIZE)), 65535)",
25
- "z": 1
26
- }
27
- }
28
- ]
29
- },
30
- {
31
- "id": "scalar",
32
- "when": ["numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)"],
33
- "derive": { "scalar": "dtypes.T" },
34
- "passes": [
35
- {
36
- "id": "main",
37
- "name": "Log",
38
- "shader": "unary-scalar.wgsl.jinja",
39
- "derive": { "itemsPerInvocation": 4 },
40
- "bindings": ["x_scalar", "y_scalar", "params_2_unary"],
41
- "dispatch": {
42
- "x": "min(ceilDiv((ceilDiv(numel(shapes.y), 4)), (tunables.WORKGROUP_SIZE)), 65535)",
43
- "y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.y), 4)), (tunables.WORKGROUP_SIZE)), 65535)",
44
- "z": 1
45
- }
46
- }
47
- ]
48
- },
49
- {
50
- "id": "same_layout_vec4_tail",
51
- "priority": 19,
52
- "when": ["numel(shapes.x) > 4", "numel(shapes.x) % 4 != 0", "numel(shapes.x) == numel(shapes.y)", "f16Ok(dtypes.T)", "ceilDiv(numel(shapes.y), 4) >= ceilDiv(tunables.MIN_TAIL_ELEMENTS | default(0), 4)"],
53
- "derive": { "scalar": "dtypes.T", "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },
54
- "passes": [
55
- {
56
- "id": "bulk",
57
- "name": "Log.Vec4Bulk",
58
- "shader": "unary-vec4.wgsl.jinja",
59
- "derive": {
60
- "vec4PerThread": "tunables.TAIL_VEC4_PER_THREAD | default(4 if numel(shapes.y) * dtypeBytes(tensorDtypes.y) <= 16777216 else 1)"
61
- },
62
- "bindings": ["x", "y", "params_unary_tail"],
63
- "dispatch": {
64
- "x": "min(ceilDiv((ceilDiv(floor(numel(shapes.y) / 4), vec4PerThread)), (tunables.WORKGROUP_SIZE)), 65535)",
65
- "y": "ceilDiv(ceilDiv((ceilDiv(floor(numel(shapes.y) / 4), vec4PerThread)), (tunables.WORKGROUP_SIZE)), 65535)",
66
- "z": 1
67
- }
68
- },
69
- {
70
- "id": "tail",
71
- "name": "Log.Tail",
72
- "shader": "unary-scalar.wgsl.jinja",
73
- "derive": { "itemsPerInvocation": 4, "tailOnly": true },
74
- "bindings": ["x_scalar", "y_scalar", "params_2_unary_tail"],
75
- "dispatch": {
76
- "x": "min(ceilDiv((1), (tunables.WORKGROUP_SIZE)), 65535)",
77
- "y": "ceilDiv(ceilDiv((1), (tunables.WORKGROUP_SIZE)), 65535)",
78
- "z": 1
79
- }
80
- }
81
- ]
82
- }
83
- ],
84
- "bindings": {
85
- "x": { "buffer": "read-only-storage", "elementType": "$vectorScalar" },
86
- "y": { "buffer": "storage", "elementType": "$vectorScalar" },
87
- "params_unary": { "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.y) / 4" }], "name": "params" },
88
- "x_scalar": { "buffer": "read-only-storage", "name": "x", "elementType": "$scalar" },
89
- "y_scalar": { "buffer": "storage", "name": "y", "elementType": "$scalar" },
90
- "params_2_unary": { "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.y)" }] },
91
- "params_unary_tail": {
92
- "struct": [{ "name": "count", "type": "u32", "value": "floor(numel(shapes.y) / 4)" }],
93
- "name": "params"
94
- },
95
- "params_2_unary_tail": {
96
- "name": "params",
97
- "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.y)" }]
98
- }
99
- }
100
- }
 
1
+ {"domain":"ai.onnx","name":"Log","sinceVersion":13,"inputs":{"input":{"dtype":"T"}},"outputs":{"output":{"dtype":"T","rank":"ranks.input","shape":"shapes.input"}},"typeConstraints":{"T":["float32","float16"]},"tunables":{"WORKGROUP_SIZE":{"default":256}},"variants":[{"id":"same_layout_vec4","priority":20,"when":["numel(shapes.input) > 0","numel(shapes.input) % 4 == 0","numel(shapes.input) == numel(shapes.output)","f16Ok(dtypes.T)"],"derive":{"scalar":"dtypes.T","vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\""},"passes":[{"id":"main","name":"Log.Vec4","shader":"unary-vec4.wgsl.jinja","derive":{"vec4PerThread":"4 if numel(shapes.output) * dtypeBytes(tensorDtypes.output) <= 16777216 else 1"},"bindings":["x","y","params_unary"],"dispatch":{"x":"min(ceilDiv((ceilDiv(numel(shapes.output) / 4, 4 if numel(shapes.output) * dtypeBytes(tensorDtypes.output) <= 16777216 else 1)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(numel(shapes.output) / 4, 4 if numel(shapes.output) * dtypeBytes(tensorDtypes.output) <= 16777216 else 1)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]},{"id":"scalar","when":["numel(shapes.input) == numel(shapes.output)","f16Ok(dtypes.T)"],"derive":{"scalar":"dtypes.T"},"passes":[{"id":"main","name":"Log","shader":"unary-scalar.wgsl.jinja","derive":{"itemsPerInvocation":4},"bindings":["x_scalar","y_scalar","params_2_unary"],"dispatch":{"x":"min(ceilDiv((ceilDiv(numel(shapes.output), 4)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(numel(shapes.output), 4)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]},{"id":"same_layout_vec4_tail","priority":19,"when":["numel(shapes.input) > 4","numel(shapes.input) % 4 != 0","numel(shapes.input) == numel(shapes.output)","f16Ok(dtypes.T)","ceilDiv(numel(shapes.output), 4) >= ceilDiv(tunables.MIN_TAIL_ELEMENTS | default(0), 4)"],"derive":{"scalar":"dtypes.T","vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\""},"passes":[{"id":"bulk","name":"Log.Vec4Bulk","shader":"unary-vec4.wgsl.jinja","derive":{"vec4PerThread":"tunables.TAIL_VEC4_PER_THREAD | default(4 if numel(shapes.output) * dtypeBytes(tensorDtypes.output) <= 16777216 else 1)"},"bindings":["x","y","params_unary_tail"],"dispatch":{"x":"min(ceilDiv((ceilDiv(floor(numel(shapes.output) / 4), vec4PerThread)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(floor(numel(shapes.output) / 4), vec4PerThread)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}},{"id":"tail","name":"Log.Tail","shader":"unary-scalar.wgsl.jinja","derive":{"itemsPerInvocation":4,"tailOnly":true},"bindings":["x_scalar","y_scalar","params_2_unary_tail"],"dispatch":{"x":"min(ceilDiv((1), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((1), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]}],"bindings":{"x":{"arg":"input","buffer":"read-only-storage","elementType":"$vectorScalar"},"y":{"arg":"output","buffer":"storage","elementType":"$vectorScalar"},"params_unary":{"struct":[{"name":"count","type":"u32","value":"numel(shapes.output) / 4"}],"name":"params"},"x_scalar":{"name":"x","arg":"input","buffer":"read-only-storage","elementType":"$scalar"},"y_scalar":{"name":"y","arg":"output","buffer":"storage","elementType":"$scalar"},"params_2_unary":{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.output)"}]},"params_unary_tail":{"struct":[{"name":"count","type":"u32","value":"floor(numel(shapes.output) / 4)"}],"name":"params"},"params_2_unary_tail":{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.output)"}]}}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/webgpu/metadata.json CHANGED
@@ -1,26 +1 @@
1
- {
2
- "name": "ai.onnx.Log",
3
- "id": "_ai_onnx_log_webgpu_afad687",
4
- "version": 1,
5
- "license": "Apache-2.0",
6
- "backend": { "type": "webgpu" },
7
- "digest": {
8
- "algorithm": "sha256",
9
- "files": {
10
- "bench.json": "rBR41F3ZZnKOmPZu2RyG+Ubcy0fLTaNUQEFGa6BXdL0=",
11
- "manifest.json": "4Dx521zW+AZ+rwVx85A0c/+MBT2cA2gyxMxbkMuMZz0=",
12
- "test.json": "NbHcFJZksvqv48iHLQdE9fxVRS0odNEI2kCy4+zZasI=",
13
- "unary-scalar.wgsl.jinja": "+elBMyt3MYSUjruxXxILNFIUBDD1Ylu87D4u35DMYWc=",
14
- "unary-vec4.wgsl.jinja": "BQhFAbvwHqL+drcd3PhKTJS1YvHmoplS2+5PCfYFcrY="
15
- }
16
- },
17
- "provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },
18
- "webgpu": {
19
- "manifestSpec": "2.1",
20
- "variants": {
21
- "same_layout_vec4": ["unary-vec4.wgsl.jinja"],
22
- "scalar": ["unary-scalar.wgsl.jinja"],
23
- "same_layout_vec4_tail": ["unary-scalar.wgsl.jinja", "unary-vec4.wgsl.jinja"]
24
- }
25
- }
26
- }
 
1
+ {"name":"ai.onnx.Log","id":"_ai_onnx_log_webgpu_c7b5822","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"YbiOxAZMkRUhDGoP60P7gY9FPnf387prF9HC67WK40g=","manifest.json":"9srpjgKLBRIjHB8/IXGib2TqopO8TqAqrEaJ15Zls5Y=","test.json":"9FQtdaDwsqDWLTxHBxOXzC/WWrLNbf+mleNnjG5IJe8=","unary-scalar.wgsl.jinja":"Vxa/FumYXM5Mi3dAsDAFKTi79EqOcHQotluTulFB7dw=","unary-vec4.wgsl.jinja":"07UFM9+E1trgd8JOA2DOTBiHUEeQs3hU7y68c/no6Nk="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/webgpu/test.json CHANGED
@@ -2,24 +2,24 @@
2
  "cases": [
3
  {
4
  "name": "vector_positive",
5
- "inputs": { "x": { "dtype": "float32", "shape": [32], "data": { "kind": "constant", "value": 2.5 } } },
6
- "outputs": { "y": { "dtype": "float32", "shape": [32], "tolerance": 0.000001 } }
7
  },
8
  {
9
  "name": "rank0_scalar_positive",
10
- "inputs": { "x": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [4.0] } } },
11
- "outputs": { "y": { "dtype": "float32", "shape": [], "tolerance": 0.000001 } }
12
  },
13
  {
14
  "name": "domain_edges_zero_negative_inf",
15
  "inputs": {
16
- "x": {
17
  "dtype": "float32",
18
  "shape": [6],
19
  "data": { "kind": "values", "values": [0.0, -1.0, -5.0, "Infinity", "NaN", 1.0] }
20
  }
21
  },
22
- "outputs": { "y": { "dtype": "float32", "shape": [6], "tolerance": 0.000001, "allowNaN": true } }
23
  },
24
  {
25
  "name": "f32_positive_subnormal_inputs_finite_logs_vec4_gpu_gap",
@@ -33,9 +33,13 @@
33
  "notes": "Positive subnormal inputs are inside Log's domain and should produce finite large negative values; flushing them to zero produces -Infinity."
34
  },
35
  "inputs": {
36
- "x": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-39, 1e-38] } }
 
 
 
 
37
  },
38
- "outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 0.000001 } }
39
  },
40
  {
41
  "name": "f32_positive_subnormal_inputs_finite_logs_scalar_gpu_gap",
@@ -49,27 +53,31 @@
49
  "notes": "Unaligned scalar-path positive subnormal inputs exercise finite Log results."
50
  },
51
  "inputs": {
52
- "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-38] } }
53
  },
54
- "outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.000001 } }
55
  },
56
  {
57
  "name": "f16_positive_values",
58
  "inputs": {
59
- "x": { "dtype": "float16", "shape": [5], "data": { "kind": "values", "values": [0.25, 0.5, 1.0, 2.0, 8.0] } }
 
 
 
 
60
  },
61
- "outputs": { "y": { "dtype": "float16", "shape": [5], "tolerance": 0.002 } }
62
  },
63
  {
64
  "name": "subnormal_positive_f32",
65
  "inputs": {
66
- "x": {
67
  "dtype": "float32",
68
  "shape": [4],
69
  "data": { "kind": "values", "values": [1.17549435e-38, 1e-37, 1e-20, 1e-10] }
70
  }
71
  },
72
- "outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 0.00001 } }
73
  },
74
  {
75
  "name": "positive_subnormal_values_gpu_gap",
@@ -83,9 +91,13 @@
83
  "notes": "Positive subnormal inputs are valid for Log; flushing them to zero turns finite logs into -Infinity."
84
  },
85
  "inputs": {
86
- "x": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-39, 1e-38] } }
 
 
 
 
87
  },
88
- "outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 0.00001 } }
89
  },
90
  {
91
  "name": "positive_subnormal_values_scalar_gpu_gap",
@@ -99,9 +111,9 @@
99
  "notes": "On the scalar path, positive subnormal inputs are valid and must produce finite logarithms."
100
  },
101
  "inputs": {
102
- "x": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-39] } }
103
  },
104
- "outputs": { "y": { "dtype": "float32", "shape": [3], "tolerance": 0.00001 } }
105
  },
106
  {
107
  "name": "ort_float_2x2",
@@ -110,9 +122,9 @@
110
  "test": "MathOpTest.Log"
111
  },
112
  "inputs": {
113
- "x": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [1.0, 2.0, 5.0, 10.0] } }
114
  },
115
- "outputs": { "y": { "dtype": "float32", "shape": [2, 2], "tolerance": 0.000001 } }
116
  },
117
  {
118
  "name": "ort_float16_2x2_projection",
@@ -122,9 +134,9 @@
122
  "notes": "Float16 projection of ORT's float Log node values."
123
  },
124
  "inputs": {
125
- "x": { "dtype": "float16", "shape": [2, 2], "data": { "kind": "values", "values": [1.0, 2.0, 5.0, 10.0] } }
126
  },
127
- "outputs": { "y": { "dtype": "float16", "shape": [2, 2], "tolerance": 0.002 } }
128
  },
129
  {
130
  "name": "signed_zero_negative_infinity_domain",
@@ -134,14 +146,14 @@
134
  "notes": "Additional node-level domain boundary: log(+/-0) is -Infinity, negative finite and -Infinity inputs produce NaN, and log(+Infinity) is +Infinity."
135
  },
136
  "inputs": {
137
- "x": {
138
  "dtype": "float32",
139
  "shape": [7],
140
  "data": { "kind": "values", "values": [0.0, 0.0, -1.0, "-Infinity", 1.0, "Infinity", "NaN"] }
141
  }
142
  },
143
  "outputs": {
144
- "y": {
145
  "dtype": "float32",
146
  "shape": [7],
147
  "tolerance": 0,
@@ -153,14 +165,14 @@
153
  {
154
  "name": "onnx_backend_example",
155
  "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_log_example" },
156
- "inputs": { "x": { "dtype": "float32", "shape": [2], "data": { "kind": "values", "values": [1.0, 10.0] } } },
157
- "outputs": { "y": { "dtype": "float32", "shape": [2], "tolerance": 0.000001 } }
158
  },
159
  {
160
  "name": "onnx_backend_log",
161
  "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_log" },
162
  "inputs": {
163
- "x": {
164
  "dtype": "float32",
165
  "shape": [3, 4, 5],
166
  "data": {
@@ -169,37 +181,41 @@
169
  }
170
  }
171
  },
172
- "outputs": { "y": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0.00001, "allowNaN": true } }
173
  },
174
  {
175
  "name": "onnx_backend_log_example",
176
  "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_log_example" },
177
- "inputs": { "x": { "dtype": "float32", "shape": [2], "data": { "kind": "values", "values": [1.0, 10.0] } } },
178
- "outputs": { "y": { "dtype": "float32", "shape": [2], "tolerance": 0.00001 } }
179
  },
180
  {
181
  "name": "empty_input_zero_dim",
182
- "inputs": { "x": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } } },
183
- "outputs": { "y": { "dtype": "float32", "shape": [0], "tolerance": 0 } }
184
  },
185
  {
186
  "name": "f16_domain_edges_scalar_path",
187
  "inputs": {
188
- "x": {
189
  "dtype": "float16",
190
  "shape": [5],
191
  "data": { "kind": "values", "values": [0.0, -1.0, "-Infinity", "Infinity", 1.0] }
192
  }
193
  },
194
- "outputs": { "y": { "dtype": "float16", "shape": [5], "allowNaN": true } },
195
  "tolerance": 0.001
196
  },
197
  {
198
  "name": "f16_domain_edges_vec4_path",
199
  "inputs": {
200
- "x": { "dtype": "float16", "shape": [4], "data": { "kind": "values", "values": [0.0, -2.0, "Infinity", 1.0] } }
 
 
 
 
201
  },
202
- "outputs": { "y": { "dtype": "float16", "shape": [4], "allowNaN": true } },
203
  "tolerance": 0.001
204
  }
205
  ]
 
2
  "cases": [
3
  {
4
  "name": "vector_positive",
5
+ "inputs": { "input": { "dtype": "float32", "shape": [32], "data": { "kind": "constant", "value": 2.5 } } },
6
+ "outputs": { "output": { "dtype": "float32", "shape": [32], "tolerance": 0.000001 } }
7
  },
8
  {
9
  "name": "rank0_scalar_positive",
10
+ "inputs": { "input": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [4.0] } } },
11
+ "outputs": { "output": { "dtype": "float32", "shape": [], "tolerance": 0.000001 } }
12
  },
13
  {
14
  "name": "domain_edges_zero_negative_inf",
15
  "inputs": {
16
+ "input": {
17
  "dtype": "float32",
18
  "shape": [6],
19
  "data": { "kind": "values", "values": [0.0, -1.0, -5.0, "Infinity", "NaN", 1.0] }
20
  }
21
  },
22
+ "outputs": { "output": { "dtype": "float32", "shape": [6], "tolerance": 0.000001, "allowNaN": true } }
23
  },
24
  {
25
  "name": "f32_positive_subnormal_inputs_finite_logs_vec4_gpu_gap",
 
33
  "notes": "Positive subnormal inputs are inside Log's domain and should produce finite large negative values; flushing them to zero produces -Infinity."
34
  },
35
  "inputs": {
36
+ "input": {
37
+ "dtype": "float32",
38
+ "shape": [4],
39
+ "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-39, 1e-38] }
40
+ }
41
  },
42
+ "outputs": { "output": { "dtype": "float32", "shape": [4], "tolerance": 0.000001 } }
43
  },
44
  {
45
  "name": "f32_positive_subnormal_inputs_finite_logs_scalar_gpu_gap",
 
53
  "notes": "Unaligned scalar-path positive subnormal inputs exercise finite Log results."
54
  },
55
  "inputs": {
56
+ "input": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-38] } }
57
  },
58
+ "outputs": { "output": { "dtype": "float32", "shape": [3], "tolerance": 0.000001 } }
59
  },
60
  {
61
  "name": "f16_positive_values",
62
  "inputs": {
63
+ "input": {
64
+ "dtype": "float16",
65
+ "shape": [5],
66
+ "data": { "kind": "values", "values": [0.25, 0.5, 1.0, 2.0, 8.0] }
67
+ }
68
  },
69
+ "outputs": { "output": { "dtype": "float16", "shape": [5], "tolerance": 0.002 } }
70
  },
71
  {
72
  "name": "subnormal_positive_f32",
73
  "inputs": {
74
+ "input": {
75
  "dtype": "float32",
76
  "shape": [4],
77
  "data": { "kind": "values", "values": [1.17549435e-38, 1e-37, 1e-20, 1e-10] }
78
  }
79
  },
80
+ "outputs": { "output": { "dtype": "float32", "shape": [4], "tolerance": 0.00001 } }
81
  },
82
  {
83
  "name": "positive_subnormal_values_gpu_gap",
 
91
  "notes": "Positive subnormal inputs are valid for Log; flushing them to zero turns finite logs into -Infinity."
92
  },
93
  "inputs": {
94
+ "input": {
95
+ "dtype": "float32",
96
+ "shape": [4],
97
+ "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-39, 1e-38] }
98
+ }
99
  },
100
+ "outputs": { "output": { "dtype": "float32", "shape": [4], "tolerance": 0.00001 } }
101
  },
102
  {
103
  "name": "positive_subnormal_values_scalar_gpu_gap",
 
111
  "notes": "On the scalar path, positive subnormal inputs are valid and must produce finite logarithms."
112
  },
113
  "inputs": {
114
+ "input": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [1e-45, 1e-40, 1e-39] } }
115
  },
116
+ "outputs": { "output": { "dtype": "float32", "shape": [3], "tolerance": 0.00001 } }
117
  },
118
  {
119
  "name": "ort_float_2x2",
 
122
  "test": "MathOpTest.Log"
123
  },
124
  "inputs": {
125
+ "input": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [1.0, 2.0, 5.0, 10.0] } }
126
  },
127
+ "outputs": { "output": { "dtype": "float32", "shape": [2, 2], "tolerance": 0.000001 } }
128
  },
129
  {
130
  "name": "ort_float16_2x2_projection",
 
134
  "notes": "Float16 projection of ORT's float Log node values."
135
  },
136
  "inputs": {
137
+ "input": { "dtype": "float16", "shape": [2, 2], "data": { "kind": "values", "values": [1.0, 2.0, 5.0, 10.0] } }
138
  },
139
+ "outputs": { "output": { "dtype": "float16", "shape": [2, 2], "tolerance": 0.002 } }
140
  },
141
  {
142
  "name": "signed_zero_negative_infinity_domain",
 
146
  "notes": "Additional node-level domain boundary: log(+/-0) is -Infinity, negative finite and -Infinity inputs produce NaN, and log(+Infinity) is +Infinity."
147
  },
148
  "inputs": {
149
+ "input": {
150
  "dtype": "float32",
151
  "shape": [7],
152
  "data": { "kind": "values", "values": [0.0, 0.0, -1.0, "-Infinity", 1.0, "Infinity", "NaN"] }
153
  }
154
  },
155
  "outputs": {
156
+ "output": {
157
  "dtype": "float32",
158
  "shape": [7],
159
  "tolerance": 0,
 
165
  {
166
  "name": "onnx_backend_example",
167
  "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_log_example" },
168
+ "inputs": { "input": { "dtype": "float32", "shape": [2], "data": { "kind": "values", "values": [1.0, 10.0] } } },
169
+ "outputs": { "output": { "dtype": "float32", "shape": [2], "tolerance": 0.000001 } }
170
  },
171
  {
172
  "name": "onnx_backend_log",
173
  "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_log" },
174
  "inputs": {
175
+ "input": {
176
  "dtype": "float32",
177
  "shape": [3, 4, 5],
178
  "data": {
 
181
  }
182
  }
183
  },
184
+ "outputs": { "output": { "dtype": "float32", "shape": [3, 4, 5], "tolerance": 0.00001, "allowNaN": true } }
185
  },
186
  {
187
  "name": "onnx_backend_log_example",
188
  "provenance": { "source": "cmake/external/onnx/onnx/backend/test/data/node/test_log_example" },
189
+ "inputs": { "input": { "dtype": "float32", "shape": [2], "data": { "kind": "values", "values": [1.0, 10.0] } } },
190
+ "outputs": { "output": { "dtype": "float32", "shape": [2], "tolerance": 0.00001 } }
191
  },
192
  {
193
  "name": "empty_input_zero_dim",
194
+ "inputs": { "input": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } } },
195
+ "outputs": { "output": { "dtype": "float32", "shape": [0], "tolerance": 0 } }
196
  },
197
  {
198
  "name": "f16_domain_edges_scalar_path",
199
  "inputs": {
200
+ "input": {
201
  "dtype": "float16",
202
  "shape": [5],
203
  "data": { "kind": "values", "values": [0.0, -1.0, "-Infinity", "Infinity", 1.0] }
204
  }
205
  },
206
+ "outputs": { "output": { "dtype": "float16", "shape": [5], "allowNaN": true } },
207
  "tolerance": 0.001
208
  },
209
  {
210
  "name": "f16_domain_edges_vec4_path",
211
  "inputs": {
212
+ "input": {
213
+ "dtype": "float16",
214
+ "shape": [4],
215
+ "data": { "kind": "values", "values": [0.0, -2.0, "Infinity", 1.0] }
216
+ }
217
  },
218
+ "outputs": { "output": { "dtype": "float16", "shape": [4], "allowNaN": true } },
219
  "tolerance": 0.001
220
  }
221
  ]
build/webgpu/unary-scalar.wgsl.jinja CHANGED
@@ -20,24 +20,20 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
20
  let end = min(begin + {{ itemsPerInvocation }}u, params.count);
21
  {% endif %}
22
  for (var i = begin; i < end; i = i + 1u) {
23
- {%- endmacro %}
24
  {% macro flat_tail_close() %}
25
  }{% endmacro %}
26
  // Scalar unary elementwise kernel: applies the selected operation, with the
27
  // numerical helpers it uses, to each element.
28
  {{ env.wgsl.resourceDeclarations }}
29
 
30
- {% set unaryDomainGuard = device.adapterInfo.architecture == "" or device.adapterInfo.architecture == "apple" %}
31
- {% macro emit_log_safe(guarded) %}
32
- {% if guarded %}
33
  fn negative_infinity() -> f32 {
34
  var bits = 0xff800000u;
35
  return bitcast<f32>(bits);
36
  }
37
 
38
- {% endif %}
39
  fn log_safe(x: f32) -> f32 {
40
- {% if guarded %}
41
  // A no-NaN compilation path can return a finite value for out-of-domain
42
  // operands. Preserve IEEE domain behavior from the loaded bits: both
43
  // signed zeros map to -Inf; negative finite values, -Inf, and input NaNs map
@@ -52,11 +48,11 @@ fn log_safe(x: f32) -> f32 {
52
  if ((bits & 0x80000000u) != 0u || input_nan) {
53
  return bitcast<f32>(bits | 0x7fc00000u);
54
  }
55
- {% endif %}
56
  return log(x);
57
  }
58
  {% endmacro %}
59
- {{ emit_log_safe(unaryDomainGuard) }}
 
60
  {{ flat_tail_open() }}
61
  y[i] = {{ scalar }}(log_safe(f32(x[i])));
62
  {{ flat_tail_close() }}
 
20
  let end = min(begin + {{ itemsPerInvocation }}u, params.count);
21
  {% endif %}
22
  for (var i = begin; i < end; i = i + 1u) {
23
+ {% endmacro %}
24
  {% macro flat_tail_close() %}
25
  }{% endmacro %}
26
  // Scalar unary elementwise kernel: applies the selected operation, with the
27
  // numerical helpers it uses, to each element.
28
  {{ env.wgsl.resourceDeclarations }}
29
 
30
+ {% macro emit_log_safe() %}
 
 
31
  fn negative_infinity() -> f32 {
32
  var bits = 0xff800000u;
33
  return bitcast<f32>(bits);
34
  }
35
 
 
36
  fn log_safe(x: f32) -> f32 {
 
37
  // A no-NaN compilation path can return a finite value for out-of-domain
38
  // operands. Preserve IEEE domain behavior from the loaded bits: both
39
  // signed zeros map to -Inf; negative finite values, -Inf, and input NaNs map
 
48
  if ((bits & 0x80000000u) != 0u || input_nan) {
49
  return bitcast<f32>(bits | 0x7fc00000u);
50
  }
 
51
  return log(x);
52
  }
53
  {% endmacro %}
54
+ {{ emit_log_safe() }}
55
+
56
  {{ flat_tail_open() }}
57
  y[i] = {{ scalar }}(log_safe(f32(x[i])));
58
  {{ flat_tail_close() }}
build/webgpu/unary-vec4.wgsl.jinja CHANGED
@@ -1,18 +1,17 @@
 
 
 
1
  // Loads and stores vec4<T> while evaluating the selected unary operation per
2
  // component.
3
  {{ env.wgsl.resourceDeclarations }}
4
 
5
- {% set unaryDomainGuard = device.adapterInfo.architecture == "" or device.adapterInfo.architecture == "apple" %}
6
- {% macro emit_log_safe(guarded) %}
7
- {% if guarded %}
8
  fn negative_infinity() -> f32 {
9
  var bits = 0xff800000u;
10
  return bitcast<f32>(bits);
11
  }
12
 
13
- {% endif %}
14
  fn log_safe(x: f32) -> f32 {
15
- {% if guarded %}
16
  // A no-NaN compilation path can return a finite value for out-of-domain
17
  // operands. Preserve IEEE domain behavior from the loaded bits: both
18
  // signed zeros map to -Inf; negative finite values, -Inf, and input NaNs map
@@ -27,21 +26,22 @@ fn log_safe(x: f32) -> f32 {
27
  if ((bits & 0x80000000u) != 0u || input_nan) {
28
  return bitcast<f32>(bits | 0x7fc00000u);
29
  }
30
- {% endif %}
31
  return log(x);
32
  }
33
  {% endmacro %}
34
- {{ emit_log_safe(unaryDomainGuard) }}
35
- {% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}
 
36
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
37
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
38
  // per-axis workgroup fold width.
39
- {% if bound == "" %}
40
- let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};{% else %}
41
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
 
42
  if ({{ name }} >= {{ bound }}) {
43
  return;
44
- }{% endif %}{% endmacro %}
 
 
45
  {% if vec4PerThread > 1 %}
46
  const ITEMS: u32 = {{ vec4PerThread }}u;
47
 
@@ -70,8 +70,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
70
  {% endif %}
71
  let xv = x[i];
72
  let fv = vec4<f32>(xv);
73
- y[i] = {{ vectorScalar }}(vec4<f32>(
74
- log_safe(fv.x), log_safe(fv.y), log_safe(fv.z), log_safe(fv.w)));
75
  {% if vec4PerThread > 1 %}
76
  }
77
  {% endif %}
 
1
+ {% macro unary_vec4_map(fn, value="fv") -%}
2
+ vec4<f32>({{ fn }}({{ value }}.x), {{ fn }}({{ value }}.y), {{ fn }}({{ value }}.z), {{ fn }}({{ value }}.w))
3
+ {%- endmacro %}
4
  // Loads and stores vec4<T> while evaluating the selected unary operation per
5
  // component.
6
  {{ env.wgsl.resourceDeclarations }}
7
 
8
+ {% macro emit_log_safe() %}
 
 
9
  fn negative_infinity() -> f32 {
10
  var bits = 0xff800000u;
11
  return bitcast<f32>(bits);
12
  }
13
 
 
14
  fn log_safe(x: f32) -> f32 {
 
15
  // A no-NaN compilation path can return a finite value for out-of-domain
16
  // operands. Preserve IEEE domain behavior from the loaded bits: both
17
  // signed zeros map to -Inf; negative finite values, -Inf, and input NaNs map
 
26
  if ((bits & 0x80000000u) != 0u || input_nan) {
27
  return bitcast<f32>(bits | 0x7fc00000u);
28
  }
 
29
  return log(x);
30
  }
31
  {% endmacro %}
32
+ {{ emit_log_safe() }}
33
+
34
+ {% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %}
35
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
36
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
37
  // per-axis workgroup fold width.
 
 
38
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
39
+ {% if bound != "" %}
40
  if ({{ name }} >= {{ bound }}) {
41
  return;
42
+ }
43
+ {% endif %}
44
+ {% endmacro %}
45
  {% if vec4PerThread > 1 %}
46
  const ITEMS: u32 = {{ vec4PerThread }}u;
47
 
 
70
  {% endif %}
71
  let xv = x[i];
72
  let fv = vec4<f32>(xv);
73
+ y[i] = {{ vectorScalar }}({{ unary_vec4_map("log_safe") }});
 
74
  {% if vec4PerThread > 1 %}
75
  }
76
  {% endif %}