Skip to content

[mlir][Linalg] Change linalg.transpose to use the output indexing map as identity. #77951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,9 +1773,9 @@ ArrayAttr TransposeOp::getIndexingMaps() {
Builder builder(getContext());
int64_t rank = getInit().getType().getRank();
return builder.getAffineMapArrayAttr(
{builder.getMultiDimIdentityMap(rank),
AffineMap::getPermutationMap(
llvm::to_vector_of<unsigned>(getPermutation()), getContext())});
{inversePermutation(AffineMap::getPermutationMap(
llvm::to_vector_of<unsigned>(getPermutation()), getContext())),
builder.getMultiDimIdentityMap(rank)});
}

void TransposeOp::getEffects(
Expand Down
16 changes: 8 additions & 8 deletions mlir/test/Dialect/Linalg/vectorization.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,16 @@ module attributes {transform.with_named_sequence} {
// CHECK: #[[MAP:.*]] = affine_map<(d0, d1) -> (d1, d0)>
// CHECK: func @test_masked_vectorize_linalg_transpose
func.func @test_masked_vectorize_linalg_transpose(%arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>) -> tensor<?x?xf32> {
// CHECK: %[[C0:.*]] = arith.constant 0 : index
// CHECK: %[[D0:.*]] = tensor.dim %arg0, %[[C0]]
// CHECK: %[[C1:.*]] = arith.constant 1 : index
// CHECK: %[[D1:.*]] = tensor.dim %arg0, %[[C1]]
// CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index
// CHECK-DAG: %[[D0:.*]] = tensor.dim %arg0, %[[C0]]
// CHECK-DAG: %[[C1:.*]] = arith.constant 1 : index
// CHECK-DAG: %[[D1:.*]] = tensor.dim %arg0, %[[C1]]
// CHECK: %[[MASK0:.*]] = vector.create_mask %[[D0]], %[[D1]]
// CHECK: %[[LOAD:.*]] = vector.mask %[[MASK0]] { vector.transfer_read %arg0{{.+}} }
// CHECK-SAME: vector<2x4xi1> -> vector<2x4xf32>
// CHECK: %[[LOAD:.*]] = vector.mask %[[MASK0]] { vector.transfer_read %arg0{{.+}} permutation_map = #[[MAP]]{{.+}} }
// CHECK-SAME: vector<4x2xi1> -> vector<2x4xf32>
// CHECK: %[[MASK1:.*]] = vector.create_mask %[[D1]], %[[D0]]
// CHECK: %[[WRITE:.*]] = vector.mask %[[MASK1]] { vector.transfer_write %[[LOAD]], %arg1{{.+}} permutation_map = #[[MAP]]{{.+}} }
// CHECK-SAME: vector<4x2xi1> -> tensor<?x?xf32>
// CHECK: %[[WRITE:.*]] = vector.mask %[[MASK1]] { vector.transfer_write %[[LOAD]], %arg1{{.+}} }
// CHECK-SAME: vector<2x4xi1> -> tensor<?x?xf32>
// CHECK: return %[[WRITE]]
%0 = linalg.transpose ins(%arg0 : tensor<?x?xf32>) outs(%arg1 : tensor<?x?xf32>) permutation = [1, 0]
return %0 : tensor<?x?xf32>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ module attributes {transform.with_named_sequence} {
// CHECK-DAG: %[[C32:.*]] = arith.constant 32 : index
// CHECK-DAG: %[[C64:.*]] = arith.constant 64 : index

// CHECK: scf.for %[[I:.*]] = %[[C0]] to %[[C16]] step %[[C1]] {
// CHECK: scf.for %[[J:.*]] = %[[C0]] to %[[C32]] step %[[C1]] {
// CHECK: scf.for %[[K:.*]] = %[[C0]] to %[[C64]] step %[[C1]] {
// CHECK: %[[ELEM:.*]] = memref.load %[[IN]][%[[I]], %[[J]], %[[K]]]
// CHECK: memref.store %[[ELEM]], %[[OUT]][%[[J]], %[[K]], %[[I]]]
// CHECK: scf.for %[[I:.*]] = %[[C0]] to %[[C32]] step %[[C1]] {
// CHECK: scf.for %[[J:.*]] = %[[C0]] to %[[C64]] step %[[C1]] {
// CHECK: scf.for %[[K:.*]] = %[[C0]] to %[[C16]] step %[[C1]] {
// CHECK: %[[ELEM:.*]] = memref.load %[[IN]][%[[K]], %[[I]], %[[J]]]
// CHECK: memref.store %[[ELEM]], %[[OUT]][%[[I]], %[[J]], %[[K]]]

// -----

Expand Down