Abstract
This RFC proposes adding first-class support for the TOSA Extended Instruction Set 001000.1 to MLIR’s SPIR-V dialect for use within spirv.ARM.Graph operations (corresponding to OpGraphARM in SPV_ARM_graph) and typed with !spirv.arm.tensor<...> (corresponding to OpTypeTensorARM in SPV_ARM_tensor). The change enables semantically faithful modeling of TOSA extended instructions inside SPIR-V graph operations, completing the connection between the existing SPV_ARM_graph/SPV_ARM_tensor support in MLIR and the Khronos SPIR-V TOSA specification.
Motivation
- MLIR already supports the
SPV_ARM_graphexecution model and theSPV_ARM_tensortype system in the SPIR-V dialect. - The TOSA extended instruction set (001000.1) is designed to express ML/TOSA semantics in SPIR-V, intended to be invoked inside
spirv.ARM.Graph(corresponding toOpGraphARM) over!spirv.arm.tensor<...>(corresponding toOpTypeTensorARM) values. - Without modeling the TOSA extended instructions in MLIR, we cannot represent TOSA ops directly and semantically in SPIR-V graphs.
This RFC enables: structured spirv.Tosa.* ops in MLIR, schema-checked typing via !spirv.arm.tensor, and graph-scoped verification.
Prior Art / Background
SPV_ARM_graphandSPV_ARM_tensorare already available in MLIR’s SPIR-V dialect.- SPIR-V supports extended instruction sets via
OpExtInstImport/OpExtInst. - The TOSA 001000.1 extended set enumerates ML ops (e.g., pooling, elementwise, shape ops) to be used in graph contexts.
Proposed Changes (High-Level)
- Register the TOSA Extended Instruction Set in the SPIR-V dialect.
- Add a new enumerant to
SPIRVExtendedInstructionSetcorresponding toTOSA 001000.1. - Dialect plumbing for import/serialization/deserialization of the TOSA set.
- Add a new enumerant to
- Add
spirv.Tosa.*operations that model each TOSA extended instruction.- Each op lowers to
OpExtInsttargeting the TOSA set with the appropriate opcode. - Ops are graph-scoped and must appear only within
spirv.ARM.Graphregions.
- Each op lowers to
- Type Integration with
SPV_ARM_tensor.- All
spirv.Tosa.*ops operate on/result in!spirv.arm.tensor<...>types. - Verifiers enforce tensor shape/rank/element-type constraints aligned with the TOSA spec.
- All
Detailed Design
Dialect and Enumeration Extensions
- Extend
SPIRVExtendedInstructionSetwith an entry for TOSA 001000.1. - Provide a stable symbolic name, e.g.,
TOSA.001000.1. - Teach the serializer/deserializer to import/export the TOSA set via
OpExtInstImport.
New spirv.Tosa.* Ops
- One MLIR op per TOSA extended instruction.
- Each op takes operands that map directly to the operands defined in the TOSA extended instruction set.
- Values that correspond to TOSA “attributes” (e.g., strides, padding, kernel size) are passed as
spirv.Constantresults or other SSA values, not as MLIR op attributes. - Operand/result types are restricted to
!spirv.arm.tensor<...>where applicable.
Verification Rules
- Context:
spirv.Tosa.*ops must reside inside aspirv.ARM.Graphregion. - Typing: All tensor operands/results must be
!spirv.arm.tensor<...>; shapes and element types obey TOSA constraints. - Attributes/Immediates: Immediate scalars (e.g., integers) must follow the TOSA specification and are verified at build/parse time.
Assembly/Disassembly
- Print/parse
spirv.Tosa.*with clear positional operands, mirroring existing SPIR-V dialect style. - Round-trip to/from SPIR-V binary: use MLIR’s SPIR-V target serialization/deserialization infrastructure.
- Ensure conformance with the Khronos specification via
spirv-val.
Testing Strategy
- Dialect Tests: Parser/printer, verifier, and builder coverage for each
spirv.Tosa.*op; negative tests for context/type violations. - Round-Trip Tests: MLIR ↔ SPIR-V binary round-trips using MLIR’s SPIR-V serialization/deserialization, validated with
spirv-val.
Backward Compatibility & Migration
- No impact on existing users of
SPV_ARM_graph/SPV_ARM_tensor. - New functionality is additive; existing pipelines remain valid.
Future Work
- Conversion Pass: Introduce a lowering pipeline from MLIR TOSA dialect ops to
spirv.Tosa.*ops insidespirv.ARM.Graph. This RFC only introduces the ops and dialect support; conversion can be staged later. - Verifier Enhancements: Add richer shape/padding/dilation consistency checks.
Implementation Plan
- Add TOSA extended set enumerant to
SPIRVExtendedInstructionSetand implement import/export plumbing. - Introduce all
spirv.Tosa.*ops covering the complete TOSA 001000.1 extended instruction set. - Verification and tests: parser/printer, verifier coverage, round-trip serialization/deserialization.