You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a lowering of vector.interleave to vector.shuffle #17346
In llvm integrate #17330 we have to locally revert llvm/llvm-project#89131 because it causes vector.interleave to be created instead of vector.shuffle, and some GPU codegen backends expected vector.shuffle and are not handling vector.interleave.
llvm/llvm-project#89131 is good in itself though, as vector.interleave is more constrained than general vector.shuffle. We just need a lowering pattern from vector.interleave to vector.shuffle to be inserted into codegen pipelines. Then we will be able to drop the local revert of llvm/llvm-project#89131.
I was thinking vector-to-vector, rewriting vector.interleave to vector.shuffle. This way, only a single pattern is needed, not backend-specific, and by construction we know current backends are happy with vector.shuffle since that is what they currently get. It can go in this existing file:
Then also a IREE-side change to insert that new pattern into codegen pipelines; and also IREE-side, remembering to drop the revert of llvm/llvm-project#89131 at the following LLVM integrate.
no no, a file is there but it only contains an unrelated UnrollInterleaveOp pattern. The pattern that we need here does not exist yet, it needs to be created.
@kuhar@qedawkins , does this look like what we discussed? llvm/llvm-project#91800
Then I'm looking on the IREE side where to put this in the SPIRV pipeline. Maybe around
Correct me if otherwise, but I was thinking it had to happen before unrolling to <= 4 elements? Unless interleave implements the unrolling interface already.
My hope would be that unrolling could break it down to source vectors in some cases already, but I haven't checked if it support the unrolling interface.
I have updated the PR with that, thanks for the tip!
Nice, that looks great to me. In terms of the IREE side, I think some combination of adding the vector.interleave n-d -> 1-d here:
@kuhar@qedawkins I am just trying to fix the immediate issue that is forcing us to carry a local LLVM revert here. This issue only seems to involve 1D vectors as far as I have seen so far.
I'm guessing we'll still need to do something on the IREE side because in addition to the requirement that all vectors must be 1-d, on SPIR-V they must also be <= 4 elements wide, and the unrolling that goes to <= 4 elements happens in IREE right now. So I'm thinking VectorToSPIRV will be too late.
but that sounds like solving a more general problem than my immediate concern of flattening our llvm integration. The upstream change that we have to carry a local revert of isn't changing the number of elements in a vector, or the rank of a vector. It's just changing vector.shuffle-on-1d-vector to vector.interleave-on-1d-vector.
Activity
kuhar commentedon May 10, 2024
Is this an mlir issue or iree issue? To me it sound like this should go to vector-to-spirv and vector-to-llvm?
bjacob commentedon May 10, 2024
I was thinking vector-to-vector, rewriting
vector.interleavetovector.shuffle. This way, only a single pattern is needed, not backend-specific, and by construction we know current backends are happy withvector.shufflesince that is what they currently get. It can go in this existing file:https://github.com/llvm/llvm-project/blob/3bde7983986d8ce637f6bb506860859249787751/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp#L4
Then also a IREE-side change to insert that new pattern into codegen pipelines; and also IREE-side, remembering to drop the revert of llvm/llvm-project#89131 at the following LLVM integrate.
kuhar commentedon May 10, 2024
Oh OK, so this pattern is already there, just need to add add it to iree pipelines. Makes sense.
bjacob commentedon May 10, 2024
no no, a file is there but it only contains an unrelated
UnrollInterleaveOppattern. The pattern that we need here does not exist yet, it needs to be created.kuhar commentedon May 10, 2024
On the spir-v side, I don't think there's any better lowering we could use anyway, spir-v has its own shuffle ops.
Integrate both llvm-project@2083e97e (+1 ↩️, +1 🍒) and torch-mlir@bce…
bjacob commentedon May 10, 2024
@kuhar @qedawkins , does this look like what we discussed? llvm/llvm-project#91800
Then I'm looking on the IREE side where to put this in the SPIRV pipeline. Maybe around
iree/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp
Lines 298 to 511 in a3b7e12
kuhar commentedon May 10, 2024
Can we put it upstream in https://github.com/llvm/llvm-project/blob/e9f53e4095d8a8600b5c5d445c73e2d5a6f45abb/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp#L812 ?
kuhar commentedon May 10, 2024
Otherwise here also seems fine:
iree/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp
Line 480 in a3b7e12
qedawkins commentedon May 10, 2024
Nice, that looks great to me. In terms of the IREE side, I think some combination of adding the
vector.interleave n-d -> 1-dhere:iree/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp
Line 330 in a3b7e12
And then the interleave to shuffle can either go in the same place, or somewhere near here:
iree/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp
Line 391 in a3b7e12
Basically after decomposing to 1d and before unrolling to 1/2/3/4 vector elements.
qedawkins commentedon May 10, 2024
Correct me if otherwise, but I was thinking it had to happen before unrolling to <= 4 elements? Unless interleave implements the unrolling interface already.
kuhar commentedon May 10, 2024
My hope would be that unrolling could break it down to source vectors in some cases already, but I haven't checked if it support the unrolling interface.
kuhar commentedon May 10, 2024
This is also a good option if it doesn't support unrolling.
bjacob commentedon May 10, 2024
I have updated the PR with that, thanks for the tip!
@kuhar @qedawkins I am just trying to fix the immediate issue that is forcing us to carry a local LLVM revert here. This issue only seems to involve 1D vectors as far as I have seen so far.
qedawkins commentedon May 10, 2024
Makes sense, then I would say any point before here is likely to work:
iree/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp
Line 416 in a3b7e12
bjacob commentedon May 10, 2024
So should the upstream PR do it in VectorToSPIRV.cpp#L812 or not?
If it should do that upstream, then nothing needs to be done on the IREE side, right?
qedawkins commentedon May 10, 2024
I'm guessing we'll still need to do something on the IREE side because in addition to the requirement that all vectors must be
1-d, on SPIR-V they must also be <= 4 elements wide, and the unrolling that goes to <= 4 elements happens in IREE right now. So I'm thinking VectorToSPIRV will be too late.bjacob commentedon May 10, 2024
but that sounds like solving a more general problem than my immediate concern of flattening our llvm integration. The upstream change that we have to carry a local revert of isn't changing the number of elements in a vector, or the rank of a vector. It's just changing vector.shuffle-on-1d-vector to vector.interleave-on-1d-vector.
[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, enab…
[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, enab…
Integrate both llvm-project@2083e97e (+1 ↩️, +1 🍒) and torch-mlir@bce…
Integrate both llvm-project@2083e97e (+1 ↩️, +1 🍒) and torch-mlir@bce…
[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, enab…
[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, enab…