Hello,
I am trying to use the permutation_map attribute of vector.transfer_write and I am stuck with an error I don’t really understand.
Here is the culprit:
%14 = vector.transfer_write %13, %arg8[%7, %9, %c0_3, %c0_4] {in_bounds = [true, true], permutation_map = affine_map<(d0, d1) -> (d1, d0)> } : vector<8x4xf32>, tensor<?x?x4x8xf32>
It gives me the following error:
error: ‘vector.transfer_write’ op requires a permutation_map with input dims of the same rank as the source type
Looking at the code I found that “source” was a sort of misnomer (it’s not refering to the input vector but the output tensor): this error is triggered by llvm-project/mlir/lib/Dialect/Vector/VectorOps.cpp
, line 2576:
if (permutationMap.getNumInputs() != shapedType.getRank())
return op->emitOpError("requires a permutation_map with input dims of the "
"same rank as the source type");
My question is: why is this code comparing the permutation_map
dimensions and the tensor dimension? I would have expected the permutation to happen with the input vector and be lowered to (according to the rewriting pattern in mlir/lib/Dialect/Vector/VectorTransferPermutationMapRewritePatterns.cpp.cpp:143
):
%foo = vector.transpose %13 [1,0] : vector<4x8xf32>
%14 = vector.transfer_write %foo, %arg8[%7, %9, %c0_3, %c0_4] {in_bounds = [true, true] , permutation_map = affine_map<(d0, d1) -> (d0, d1)>} : vector<4x8xf32>, tensor<?x?x4x8xf32>
I would also expect that new permutation_map to be dropped at some point because it’s just an identity map.
Which would not require me to have to use a 4-dimension permutation_map.
I guess I am wrong with my assumptions and it’s important to keep a permutation_map with as many input dims as the output tensor, but I don’t fully understand why? I also tried to give the vector.transfer_write a 4-dims permutation map (i.e. (d0,d1,d2,d3) → (d0,d1,d3,d2)) but it fails with:
mlir::Attribute mlir::ArrayAttr::operator(unsigned int) const: Assertion `idx < size() && “index out of bounds”’ failed.
Because I imagine it’s trying to read too far into the input vector.
Can someone help me understand this?
Thanks
EDIT: After reading the code of VectorTransferPermutationMapRewritePatterns, I found out that doing (d0,d1,d2,d3) → (d3,d2) is working fine. I’m still not sure why I need 4 dimensions as input though.