Repository navigation
[spirv] Port over cooperative matrix support - #5607
Conversation
This commit moves cooperative matrix support to the Linalg on tensor path. A few improvements are done along the way to have a better pipeline structure: * Cooperative matrix support previoulsy were scattered across various passes; now they are scoped into the same pass for better isolation. * Now the handling of cooperative matrix is at a more proper layer. Cooperative matrix is at a large vector semantics level. We try to lower vector transfer read/write/arthmetic ops when we are still at that level with the necessary high-level information; not trying to left them "fall through" to the final converting to SPIR-V stage. * Now the lowering is more progressive. This commit leverages new constructs like unrealized_conversion_cast recently added in core to bridge the gap and makes SPIR-V lowering more modular and progressive: cooperative matrix part is first handled, with the rest latter converted and those cast ops cancelled out. Upstream SPIR-V support is expected to grow more towards this direction. The majority of the code in the new VectorToCooperativeMatrixPass.cpp file is moved from ConvertToSPIRVPass.cpp, with modifications to properly use type conversion integrated into dialect conversion framework.
|
There are some TODO assigned to @ThomasRaoux so I think it's better to wait for his LGTM. |
MaheshRavishankar
left a comment
There was a problem hiding this comment.
I am fine with moving this around, but we should just move this to core. The issue here is that the co-operative matrix has its own types and load-store instructions. So the vector transfer-reads and transfer-writes become problematic. THe best way to handle this is to update the Vector to Co-operative matrix lowering in core to not require the pre-analysis pass done here. For this we are first missing a "spv.cast" operation that converts from the default spv.array type to the co-operative matrix type.
- Lower the
vector.contractusingspv.cast->spv.cooperativeMatrixMulOp->spv.cast. - Then you have a
spv.load->spv.castthat should be converted tospv.loadcooperativematrix(and same for the store).
This then requires no state and this pass can be dropped. Would be better for SPIR-V lowering in general.
This refactoring by itself is good, but deleting this pass completely is even better (we have code cleanup as part of our OKRs this quarter)
Yes right. The existing analysis is hacky. @ThomasRaoux is pushing for a more generic cooperative matrix ish representation in gpu dialect so that we can share between cuda and spirv land. After that's landed we can go from vector to gpu counterparts and then convert to spirv will be simple. Expected this part to be simplified in the future; right now doing this to unblock deprecating the buffer path. |
This commit moves cooperative matrix support to the Linalg on tensor path. A few improvements are done along the way to have a better pipeline structure: * Cooperative matrix support previously were scattered across various passes; now they are scoped into the same pass for better isolation. * Now the handling of cooperative matrix is at a more proper layer. Cooperative matrix is at a large vector semantics level. We try to lower vector transfer read/write/arithmetic ops when we are still at that level with the necessary high-level information; not trying to left them "fall through" to the final converting to SPIR-V stage. * Now the lowering is more progressive. This commit leverages new constructs like unrealized_conversion_cast recently added in core to bridge the gap and makes SPIR-V lowering more modular and progressive: cooperative matrix part is first handled, with the rest latter converted and those cast ops cancelled out. Upstream SPIR-V support is expected to grow more towards this direction. The majority of the code in the new VectorToCooperativeMatrixPass.cpp file is moved from ConvertToSPIRVPass.cpp, with modifications to properly use type conversion integrated into dialect conversion framework.
This commit moves cooperative matrix support to the Linalg on tensor path. A few improvements are done along the way to have a better pipeline structure: * Cooperative matrix support previously were scattered across various passes; now they are scoped into the same pass for better isolation. * Now the handling of cooperative matrix is at a more proper layer. Cooperative matrix is at a large vector semantics level. We try to lower vector transfer read/write/arithmetic ops when we are still at that level with the necessary high-level information; not trying to left them "fall through" to the final converting to SPIR-V stage. * Now the lowering is more progressive. This commit leverages new constructs like unrealized_conversion_cast recently added in core to bridge the gap and makes SPIR-V lowering more modular and progressive: cooperative matrix part is first handled, with the rest latter converted and those cast ops cancelled out. Upstream SPIR-V support is expected to grow more towards this direction. The majority of the code in the new VectorToCooperativeMatrixPass.cpp file is moved from ConvertToSPIRVPass.cpp, with modifications to properly use type conversion integrated into dialect conversion framework.
This commit moves cooperative matrix support to the Linalg on
tensor path. A few improvements are done along the way to have
a better pipeline structure:
various passes; now they are scoped into the same pass for
better isolation.
layer. Cooperative matrix is at a large vector semantics level.
We try to lower vector transfer read/write/arthmetic ops when
we are still at that level with the necessary high-level
information; not trying to left them "fall through" to the
final converting to SPIR-V stage.
new constructs like unrealized_conversion_cast recently added
in core to bridge the gap and makes SPIR-V lowering more modular
and progressive: cooperative matrix part is first handled, with
the rest latter converted and those cast ops cancelled out.
Upstream SPIR-V support is expected to grow more towards this
direction.
The majority of the code in the new VectorToCooperativeMatrixPass.cpp
file is moved from ConvertToSPIRVPass.cpp, with modifications to
properly use type conversion integrated into dialect conversion
framework.