{ "domain": "ai.onnx", "name": "Less", "sinceVersion": 13, "description": "Performs an elementwise `less-than` comparison between tensors `A` and `B` with NumPy-style multidirectional broadcasting, producing a boolean result tensor `C`. Each output element is `true` where the corresponding element of `A` is strictly less than that of `B`.", "inputs": [ { "role": "A", "dtype": "T", "description": "First input operand for the less-than comparison." }, { "role": "B", "dtype": "T", "description": "Second input operand for the less-than comparison." } ], "outputs": [ { "role": "C", "dtype": "B", "rank": "max(ranks.A, ranks.B)", "description": "Boolean result tensor; true where A < B.", "shape": "broadcastShape(shapes.A, shapes.B)" } ], "typeConstraints": { "T": ["float32", "float16", "int32", "int16", "uint32", "int8", "uint8"], "B": ["bool"] }, "args": { "a": { "kind": "tensor", "semantic": "A", "role": "input" }, "b": { "kind": "tensor", "semantic": "B", "role": "input" }, "c": { "kind": "tensor", "semantic": "C", "role": "output" } }, "tunables": { "WORKGROUP_SIZE": 256 }, "variants": [ { "id": "same_shape_vec4", "priority": 20, "when": ["sameShape(shapes.A, shapes.C)", "sameShape(shapes.B, shapes.C)", "numel(shapes.C) > 0", "numel(shapes.C) % 4 == 0", "f16Ok(dtypes.T)"], "constants": { "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"", "usesF16": "dtypes.T == \"f16\"" }, "passes": [ { "id": "main", "name": "Less.vec4", "source": { "shader": "compare-vec4.wgsl.jinja", "inputs": { "op": "\"less\"" } }, "bindings": [ { "name": "a", "arg": "a", "semantic": "A", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "b", "arg": "b", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "$vectorScalar" }, { "name": "c", "arg": "c", "semantic": "C", "buffer": { "type": "storage" }, "elementType": "vec4" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C) / 4" }] } } ], "dispatch": { "threads": "numel(shapes.C) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" } } ] }, { "id": "broadcast_vec4", "when": ["ranks.A <= ranks.C", "ranks.B <= ranks.C", "ranks.C >= 1", "dim(shapes.C, ranks.C - 1) % 4 == 0", "numel(shapes.C) % 4 == 0", "numel(shapes.C) >= 4", "f16Ok(dtypes.T)"], "constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" }, "passes": [ { "id": "main", "name": "Less", "source": { "shader": "compare-broadcast-vec4.wgsl.jinja", "inputs": { "aShape": "shapes.A", "bShape": "shapes.B", "cShape": "shapes.C", "aRank": "ranks.A", "bRank": "ranks.B", "cRank": "ranks.C", "op": "\"less\"" } }, "bindings": [ { "name": "a", "arg": "a", "semantic": "A", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "b", "arg": "b", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "c", "arg": "c", "semantic": "C", "buffer": { "type": "storage" }, "elementType": "vec4" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C) / 4" }] } } ], "dispatch": { "gridStride": "numel(shapes.C) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" } } ], "priority": 10 }, { "id": "broadcast", "when": ["ranks.A <= ranks.C", "ranks.B <= ranks.C", "f16Ok(dtypes.T)"], "constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" }, "passes": [ { "id": "main", "name": "Less", "source": { "shader": "compare-broadcast.wgsl.jinja", "inputs": { "aShape": "shapes.A", "bShape": "shapes.B", "cShape": "shapes.C", "aRank": "ranks.A", "bRank": "ranks.B", "cRank": "ranks.C", "op": "\"less\"", "itemsPerInvocation": 4 } }, "bindings": [ { "name": "a", "arg": "a", "semantic": "A", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "b", "arg": "b", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "c", "arg": "c", "semantic": "C", "buffer": { "type": "storage" }, "elementType": "u32" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C)" }] } } ], "dispatch": { "threads": "ceilDiv(numel(shapes.C), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" } } ] }, { "id": "same_shape_scalar_x4", "priority": 15, "when": ["sameShape(shapes.A, shapes.C)", "sameShape(shapes.B, shapes.C)", "numel(shapes.C) > 0", "numel(shapes.C) % 4 != 0", "ranks.A <= ranks.C", "ranks.B <= ranks.C", "f16Ok(dtypes.T)"], "constants": { "scalar": "dtypes.T", "usesF16": "dtypes.T == \"f16\"" }, "passes": [ { "id": "main", "name": "Less", "source": { "shader": "compare-broadcast.wgsl.jinja", "inputs": { "aShape": "shapes.A", "bShape": "shapes.B", "cShape": "shapes.C", "aRank": "ranks.A", "bRank": "ranks.B", "cRank": "ranks.C", "op": "\"less\"", "itemsPerInvocation": 4 } }, "bindings": [ { "name": "a", "arg": "a", "semantic": "A", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "b", "arg": "b", "semantic": "B", "buffer": { "type": "read-only-storage" }, "elementType": "$scalar" }, { "name": "c", "arg": "c", "semantic": "C", "buffer": { "type": "storage" }, "elementType": "u32" }, { "name": "params", "semantic": "kernel.params", "buffer": { "type": "uniform" }, "struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.C)" }] } } ], "dispatch": { "threads": "ceilDiv(numel(shapes.C), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" } } ] } ] }