Skip to content

Instantly share code, notes, and snippets.

@pashu123
Created May 21, 2025 21:23
Show Gist options
  • Save pashu123/7b5b7be862ad49e7dbe85c8ad51ed505 to your computer and use it in GitHub Desktop.
Save pashu123/7b5b7be862ad49e7dbe85c8ad51ed505 to your computer and use it in GitHub Desktop.
#map = affine_map<(d0, d1) -> (d0, d1)>
module {
func.func @foo(%arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>) -> tensor<?x?xf32> {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%dim = tensor.dim %arg0, %c0 : tensor<?x?xf32>
%dim_0 = tensor.dim %arg1, %c1 : tensor<?x?xf32>
%cst = arith.constant 0.000000e+00 : f32
%0 = tensor.empty(%dim, %dim_0) : tensor<?x?xf32>
%1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<?x?xf32>) -> tensor<?x?xf32>
%2 = linalg.matmul ins(%arg0, %arg1 : tensor<?x?xf32>, tensor<?x?xf32>) outs(%1 : tensor<?x?xf32>) -> tensor<?x?xf32>
%3 = tensor.empty(%dim, %dim_0) : tensor<?x?xf32>
%4 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%2 : tensor<?x?xf32>) outs(%3 : tensor<?x?xf32>) {
^bb0(%in: f32, %out: f32):
%5 = arith.addf %in, %in : f32
linalg.yield %5 : f32
} -> tensor<?x?xf32>
return %4 : tensor<?x?xf32>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment