ai.onnx.BitCast / build /webgpu /manifest.json
Xenova's picture
Xenova HF Staff
sync 2e7068faf55e
9d0cf92 verified
Raw
History Blame
4.91 kB
{
"domain": "ai.onnx",
"name": "BitCast",
"sinceVersion": 26,
"description": "Reinterprets the raw bit pattern of a tensor as a different data type without any value conversion. The target type must have the same bit-width as the input type, and the output tensor has the same shape as the input.",
"inputs": [{ "role": "input", "dtype": "T", "description": "Input tensor to be bitwise reinterpreted." }],
"outputs": [
{
"role": "output",
"dtype": "U",
"rank": "ranks.input",
"description": "Output tensor with the same shape as the input, reinterpreted as the target type.",
"shape": "shapes.input"
}
],
"attributes": {},
"attributeDescriptions": {
"to": "Required TensorProto DataType enum integer naming the output dtype; the target type must have the same bit-width as the input type."
},
"attributeConstraints": { "to": { "required": true } },
"typeConstraints": {
"T": ["float32", "int8", "int32", "uint8", "uint32"],
"U": ["float32", "int8", "int32", "uint8", "uint32"]
},
"args": {
"input": { "kind": "tensor", "semantic": "input", "role": "input" },
"output": { "kind": "tensor", "semantic": "output", "role": "output" }
},
"tunables": { "WORKGROUP_SIZE": 256 },
"derive": {
"deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)",
"bitcastShapeOk": "ranks.input >= 0 and ranks.output == ranks.input and numel(shapes.input) == numel(shapes.output)",
"bitcastTypeOk": "attrs.to == onnxDtypeCode(logicalDtypes.U) and (((tensorDtypes.input == \"int8\" or tensorDtypes.input == \"uint8\") and (tensorDtypes.output == \"int8\" or tensorDtypes.output == \"uint8\")) or (tensorDtypes.input != \"int8\" and tensorDtypes.input != \"uint8\" and tensorDtypes.output != \"int8\" and tensorDtypes.output != \"uint8\"))",
"bitcastWorkgroupSize": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)",
"bitcastDispatchFits": "ceilDiv(ceilDiv(numel(shapes.output), bitcastWorkgroupSize), device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension",
"bitcastBaseOk": "bitcastShapeOk and bitcastTypeOk and bitcastDispatchFits"
},
"constants": {
"inScalar": "dtypes.T",
"outScalar": "dtypes.U",
"inputIsInt8": "tensorDtypes.input == \"int8\"",
"inputIsUint8": "tensorDtypes.input == \"uint8\"",
"outputIsInt8": "tensorDtypes.output == \"int8\"",
"outputIsUint8": "tensorDtypes.output == \"uint8\""
},
"bindingSets": {
"vec4Slots": [
{
"name": "input",
"arg": "input",
"semantic": "input",
"buffer": { "type": "read-only-storage" },
"elementType": "$inVec4"
},
{
"name": "output",
"arg": "output",
"semantic": "output",
"buffer": { "type": "storage" },
"elementType": "$outVec4"
},
{
"name": "params",
"semantic": "kernel.params",
"buffer": { "type": "uniform" },
"struct": {
"name": "Params",
"fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.output) / 4" }]
}
}
],
"scalarSlots": [
{
"name": "input",
"arg": "input",
"semantic": "input",
"buffer": { "type": "read-only-storage" },
"elementType": "$inScalar"
},
{
"name": "output",
"arg": "output",
"semantic": "output",
"buffer": { "type": "storage" },
"elementType": "$outScalar"
},
{
"name": "params",
"semantic": "kernel.params",
"buffer": { "type": "uniform" },
"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] }
}
]
},
"variants": [
{
"id": "slot32_vec4",
"priority": 20,
"when": ["numel(shapes.input) % 4 == 0", "bitcastBaseOk"],
"constants": { "inVec4": "\"vec4<\" ~ dtypes.T ~ \">\"", "outVec4": "\"vec4<\" ~ dtypes.U ~ \">\"" },
"passes": [
{
"id": "main",
"name": "BitCast.vec4",
"source": {
"shader": "bitcast.wgsl.jinja",
"inputs": { "vectorized": true, "workgroupSize": "bitcastWorkgroupSize" }
},
"bindings": "vec4Slots",
"dispatch": { "threads": "numel(shapes.output) / 4", "workgroupSize": "bitcastWorkgroupSize" }
}
]
},
{
"id": "slot32",
"when": ["bitcastBaseOk"],
"passes": [
{
"id": "main",
"name": "BitCast",
"source": { "shader": "bitcast.wgsl.jinja", "inputs": { "workgroupSize": "bitcastWorkgroupSize" } },
"bindings": "scalarSlots",
"dispatch": { "threads": "numel(shapes.output)", "workgroupSize": "bitcastWorkgroupSize" }
}
]
}
]
}