Skip to content

Instantly share code, notes, and snippets.

@cathyzhyi
Created March 19, 2024 18:41
Show Gist options
  • Save cathyzhyi/fa6018bd346721c02c6134ea5103380c to your computer and use it in GitHub Desktop.
Save cathyzhyi/fa6018bd346721c02c6134ea5103380c to your computer and use it in GitHub Desktop.
#map = affine_map<(d0, d1) -> (d0, d1)>
func.func @linalg_transpose_2d(%arg0: tensor<?x?xi32>, %dims: tensor<2xindex>, %1 : tensor<?x?xi32>) -> tensor<?x?xi32> {
%2 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%arg0 : tensor<?x?xi32>) outs(%1 : tensor<?x?xi32>) {
^bb0(%in: i32, %out: i32):
%idx0 = linalg.index 0 : index
%idx1 = linalg.index 1 : index
%indexes = tensor.from_elements %idx0, %idx1 : tensor<2xindex>
%cst0 = arith.constant 0 : index
%cst1 = arith.constant 1 : index
%dimsIdx0 = tensor.extract %dims[%cst0] : tensor<2xindex>
%dimsIdx1 = tensor.extract %dims[%cst1] : tensor<2xindex>
%outputIdx0 = tensor.extract %indexes[%dimsIdx0] : tensor<2xindex>
%outputIdx1 = tensor.extract %indexes[%dimsIdx1] : tensor<2xindex>
%3 = tensor.extract %arg0[%outputIdx0, %outputIdx1] : tensor<?x?xi32>
linalg.yield %3 : i32
} -> tensor<?x?xi32>
return %2 : tensor<?x?xi32>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment