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

Add linalg.transpose #40

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions mlir/dialects/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,20 @@ class LinalgMatvec(DialectOp):
" outs( {c_id.ssa_id} : {c_type.type} )")]


@dataclass
class LinalgTranspose(DialectOp):
inarg: List[mast.SsaId]
in_type: List[mast.Type]
init: List[mast.SsaId]
init_type: List[mast.Type]
permutation: List[int]

_syntax_ = [("linalg.transpose"
" ins( {inarg.ssa_id_list} : {in_type.type_list_no_parens} )"
amanda849 marked this conversation as resolved.
Show resolved Hide resolved
" outs( {init.ssa_id_list} : {init_type.type_list_no_parens} )"
" permutation = [ {permutation.ssa_use_list} ]")]


# Inspect current module to get all classes defined above
linalg = Dialect("linalg", ops=[m[1] for m in inspect.getmembers(
sys.modules[__name__], lambda obj: is_op(obj, __name__))])
9 changes: 9 additions & 0 deletions tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def test_matvec():
}""")


def test_transpose():
assert_roundtrip_equivalence("""module {
func.func @transpose(%arg0: memref<?x?xf16>, %arg1: memref<?x?xf16>) {
%transpose = linalg.transpose ins( %arg0 : memref<?x?xf16> ) outs( %arg1 : memref<?x?xf16> ) permutation = [ 1, 0 ]
return
}
}""")


if __name__ == "__main__":
if len(sys.argv) > 1:
exec(sys.argv[1])
Expand Down
Loading