Skip to content

Instantly share code, notes, and snippets.

@pashu123
Created September 6, 2024 15:50
Show Gist options
  • Save pashu123/a5bd39860b32611fe7bf301d6a5452b9 to your computer and use it in GitHub Desktop.
Save pashu123/a5bd39860b32611fe7bf301d6a5452b9 to your computer and use it in GitHub Desktop.
func.func @matmul_fusion_test(%arg0 : tensor<?x?xf32>,
%arg1 : tensor<?x?xf32>) -> tensor<?x?xf32> {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%cst0 = arith.constant 0.0 : f32
%M = tensor.dim %arg0, %c0 : tensor<?x?xf32>
%N = tensor.dim %arg1, %c1 : tensor<?x?xf32>
%K = tensor.dim %arg0, %c1 : tensor<?x?xf32>
%empty = tensor.empty(%M, %N) : tensor<?x?xf32>
%fill = linalg.fill ins(%cst0 : f32) outs(%empty : tensor<?x?xf32>) -> tensor<?x?xf32>
%matmul = linalg.matmul
{lowering_config = #iree_codegen.lowering_config<tile_sizes = [[64, 64]]>}
ins(%arg0, %arg1 : tensor<?x?xf32>, tensor<?x?xf32>)
outs(%fill : tensor<?x?xf32>) -> tensor<?x?xf32>
%empty_user1 = tensor.empty(%M, %N) : tensor<?x?xf32>
%user1 = linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
iterator_types = ["parallel", "parallel"]}
ins(%matmul : tensor<?x?xf32>) outs(%empty_user1 : tensor<?x?xf32>) {
^bb0(%b0 : f32, %b1 : f32) :
%0 = arith.maximumf %b0, %cst0 : f32
linalg.yield %0 : f32
} -> tensor<?x?xf32>
%empty_user2 = tensor.empty(%M, %N) : tensor<?x?xf32>
%user2 = linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
iterator_types = ["parallel", "parallel"]}
ins(%matmul, %user1 : tensor<?x?xf32>, tensor<?x?xf32>) outs(%empty_user2 : tensor<?x?xf32>) {
^bb0(%b0 : f32, %b1 : f32, %b2: f32) :
%0 = arith.addf %b0, %b1 : f32
linalg.yield %0 : f32
} -> tensor<?x?xf32>
return %user2 : tensor<?x?xf32>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment