llvm-project/mlir/test/python/dialects/linalg/opdsl/shape_maps_iteration.py
Stella Laurenzo 9f3f6d7bd8 Move MLIR python sources to mlir/python.
* NFC but has some fixes for CMake glitches discovered along the way (things not cleaning properly, co-mingled depends).
* Includes previously unsubmitted fix in D98681 and a TODO to fix it more appropriately in a smaller followup.

Differential Revision: https://reviews.llvm.org/D101493
2021-05-03 18:36:48 +00:00

44 lines
1.6 KiB
Python

# RUN: %PYTHON -m mlir.dialects.linalg.opdsl.dump_oplib --file %s | FileCheck %s
from mlir.dialects.linalg.opdsl.lang import *
# Verify that simple case with iteration order defined lexically and reduction
# dims auto discovered emits the right shape, indexing maps and iterator types.
# CHECK: ---
# CHECK-LABEL: matmul
# CHECK: shape: affine_map<()[s0, s1, s2] -> (s0, s2)>
# CHECK: shape: affine_map<()[s0, s1, s2] -> (s2, s1)>
# CHECK: shape: affine_map<()[s0, s1, s2] -> (s0, s1)>
# CHECK: static_indexing_maps:
# CHECK-NEXT: - affine_map<(d0, d1, d2)[s0, s1, s2] -> (d0, d2)>
# CHECK-NEXT: - affine_map<(d0, d1, d2)[s0, s1, s2] -> (d2, d1)>
# CHECK-NEXT: - affine_map<(d0, d1, d2)[s0, s1, s2] -> (d0, d1)>
# CHECK: iterator_types:
# CHECK-NEXT: - parallel
# CHECK-NEXT: - parallel
# CHECK-NEXT: - reduction
@linalg_structured_op
def matmul(A=TensorDef(T, S.M, S.K),
B=TensorDef(T, S.K, S.N),
C=TensorDef(U, S.M, S.N, output=True)):
C[D.m, D.n] += cast(U, A[D.m, D.k]) * cast(U, B[D.k, D.n])
# Verifies that assignment to a scalar (represented as [None]) is represented
# correctly.
# CHECK: ---
# CHECK-LABEL: dot
# CHECK: shape: affine_map<()[s0] -> (s0)>
# CHECK: shape: affine_map<()[s0] -> (s0)>
# CHECK: shape: affine_map<()[s0] -> ()>
# CHECK: static_indexing_maps:
# CHECK-NEXT: - affine_map<(d0)[s0] -> (d0)>
# CHECK-NEXT: - affine_map<(d0)[s0] -> (d0)>
# CHECK-NEXT: - affine_map<(d0)[s0] -> ()>
# CHECK: iterator_types:
# CHECK-NEXT: - reduction
@linalg_structured_op
def dot(A=TensorDef(T, S.M), B=TensorDef(T, S.M), C=TensorDef(U, output=True)):
C[None] += cast(U, A[D.m]) * cast(U, B[D.m])