1# RUN: %PYTHON -m mlir.dialects.linalg.opdsl.dump_oplib --file %s | FileCheck %s
2
3from mlir.dialects.linalg.opdsl.lang import *
4
5
6# Verify that simple case with iteration order defined lexically and reduction
7# dims auto discovered emits the right shape, indexing maps and iterator types.
8# CHECK: ---
9# CHECK-LABEL: matmul
10# CHECK: shape: affine_map<()[s0, s1, s2] -> (s0, s2)>
11# CHECK: shape: affine_map<()[s0, s1, s2] -> (s2, s1)>
12# CHECK: shape: affine_map<()[s0, s1, s2] -> (s0, s1)>
13# CHECK: static_indexing_maps:
14# CHECK-NEXT: - affine_map<(d0, d1, d2)[s0, s1, s2] -> (d0, d2)>
15# CHECK-NEXT: - affine_map<(d0, d1, d2)[s0, s1, s2] -> (d2, d1)>
16# CHECK-NEXT: - affine_map<(d0, d1, d2)[s0, s1, s2] -> (d0, d1)>
17# CHECK: iterator_types:
18# CHECK-NEXT: - parallel
19# CHECK-NEXT: - parallel
20# CHECK-NEXT: - reduction
21@linalg_structured_op
22def matmul(A=TensorDef(T, S.M, S.K),
23           B=TensorDef(T, S.K, S.N),
24           C=TensorDef(U, S.M, S.N, output=True)):
25  C[D.m, D.n] += cast(U, A[D.m, D.k]) * cast(U, B[D.k, D.n])
26
27
28# Verifies that assignment to a scalar (represented as [None]) is represented
29# correctly.
30# CHECK: ---
31# CHECK-LABEL: dot
32# CHECK: shape: affine_map<()[s0] -> (s0)>
33# CHECK: shape: affine_map<()[s0] -> (s0)>
34# CHECK: shape: affine_map<()[s0] -> ()>
35# CHECK: static_indexing_maps:
36# CHECK-NEXT: - affine_map<(d0)[s0] -> (d0)>
37# CHECK-NEXT: - affine_map<(d0)[s0] -> (d0)>
38# CHECK-NEXT: - affine_map<(d0)[s0] -> ()>
39# CHECK: iterator_types:
40# CHECK-NEXT: - reduction
41@linalg_structured_op
42def dot(A=TensorDef(T, S.M), B=TensorDef(T, S.M), C=TensorDef(U, output=True)):
43  C[None] += cast(U, A[D.m]) * cast(U, B[D.m])
44