Skip to content
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

[MLIR] transform.structured.convert_to_loops does not delete target op #83252

Closed
lhunloh opened this issue Feb 28, 2024 · 1 comment · Fixed by #83537
Closed

[MLIR] transform.structured.convert_to_loops does not delete target op #83252

lhunloh opened this issue Feb 28, 2024 · 1 comment · Fixed by #83537

Comments

@lhunloh
Copy link
Contributor

lhunloh commented Feb 28, 2024

Minimal example:

func.func @gemm(%arg0 : memref<?x?xf32>, %arg1 : memref<?x?xf32>,
  %arg2 : memref<?x?xf32>) {
  linalg.matmul ins(%arg0, %arg1 : memref<?x?xf32>, memref<?x?xf32>)
      outs(%arg2 : memref<?x?xf32>)
  return
}

module attributes {transform.with_named_sequence} {
  transform.named_sequence @__transform_main(%arg1 : !transform.any_op {transform.readonly}) {
    %matmul = transform.structured.match ops{["linalg.matmul"]} in %arg1
      : (!transform.any_op) -> !transform.any_op
    transform.structured.convert_to_loops %matmul : !transform.any_op
    transform.yield
  }
}

Via mlir-opt test.mlir --transform-interpreter this gets transformed into:

func.func @gemm(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>, %arg2: memref<?x?xf32>) {
   // constants abbreviated
    scf.for %arg3 = %c0_9 to %dim step %c1_10 {
      // constants abbreviated
      scf.for %arg4 = %c0_11 to %dim_4 step %c1_12 {
        // constants abbreviated
        scf.for %arg5 = %c0_13 to %dim_0 step %c1_14 {
         // constants abbreviated
          %9 = arith.mulf %2, %5 : f32
          %10 = arith.addf %8, %9 : f32
          %11 = affine.apply #map(%arg3, %arg4, %arg5)
          %12 = affine.apply #map2(%arg3, %arg4, %arg5)
          memref.store %10, %arg2[%11, %12] : memref<?x?xf32>
        }
      }
    }
    linalg.matmul ins(%arg0, %arg1 : memref<?x?xf32>, memref<?x?xf32>) outs(%arg2 : memref<?x?xf32>)
    return
}

With the (old) target linalg.matmul still standing.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 4, 2024

@llvm/issue-subscribers-mlir-linalg

Author: None (lhunloh)

Minimal example: ``` func.func @gemm(%arg0 : memref<?x?xf32>, %arg1 : memref<?x?xf32>, %arg2 : memref<?x?xf32>) { linalg.matmul ins(%arg0, %arg1 : memref<?x?xf32>, memref<?x?xf32>) outs(%arg2 : memref<?x?xf32>) return }

module attributes {transform.with_named_sequence} {
transform.named_sequence @__transform_main(%arg1 : !transform.any_op {transform.readonly}) {
%matmul = transform.structured.match ops{["linalg.matmul"]} in %arg1
: (!transform.any_op) -> !transform.any_op
transform.structured.convert_to_loops %matmul : !transform.any_op
transform.yield
}
}


Via `mlir-opt test.mlir --transform-interpreter` this gets transformed into:

func.func @gemm(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>, %arg2: memref<?x?xf32>) {
// constants abbreviated
scf.for %arg3 = %c0_9 to %dim step %c1_10 {
// constants abbreviated
scf.for %arg4 = %c0_11 to %dim_4 step %c1_12 {
// constants abbreviated
scf.for %arg5 = %c0_13 to %dim_0 step %c1_14 {
// constants abbreviated
%9 = arith.mulf %2, %5 : f32
%10 = arith.addf %8, %9 : f32
%11 = affine.apply #map(%arg3, %arg4, %arg5)
%12 = affine.apply #map2(%arg3, %arg4, %arg5)
memref.store %10, %arg2[%11, %12] : memref<?x?xf32>
}
}
}
linalg.matmul ins(%arg0, %arg1 : memref<?x?xf32>, memref<?x?xf32>) outs(%arg2 : memref<?x?xf32>)
return
}


With the (old) target `linalg.matmul` still standing.
</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants