Add a lowering of `vector.interleave` to `vector.shuffle`
bjacob opened this issue · comments
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.
Is this an mlir issue or iree issue? To me it sound like this should go to vector-to-spirv and vector-to-llvm?
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.
Oh OK, so this pattern is already there, just need to add add it to iree pipelines. Makes sense.
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.
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.
@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
Otherwise here also seems fine:
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:
And then the interleave to shuffle can either go in the same place, or somewhere near here:
Basically after decomposing to 1d and before unrolling to 1/2/3/4 vector elements.
Otherwise here also seems fine:
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.
Basically after decomposing to 1d and before unrolling to 1/2/3/4 vector elements.
This is also a good option if it doesn't support unrolling.
Can we put it upstream in https://github.com/llvm/llvm-project/blob/e9f53e4095d8a8600b5c5d445c73e2d5a6f45abb/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp#L812 ?
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.
Makes sense, then I would say any point before here is likely to work:
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?
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.