xref: /llvm-project/mlir/unittests/Dialect/Utils/StructuredOpsUtilsTest.cpp (revision 8a80e331506e3e3db390ed0b482c7cbe216f7afc)
1db011775SGeoffrey Martin-Noble //===- StructuredOpsUtilsTest.cpp - StructuredOpsUtils unit tests ---------===//
2db011775SGeoffrey Martin-Noble //
3db011775SGeoffrey Martin-Noble // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4db011775SGeoffrey Martin-Noble // See https://llvm.org/LICENSE.txt for license information.
5db011775SGeoffrey Martin-Noble // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6db011775SGeoffrey Martin-Noble //
7db011775SGeoffrey Martin-Noble //===----------------------------------------------------------------------===//
8db011775SGeoffrey Martin-Noble 
9db011775SGeoffrey Martin-Noble #include "mlir/Dialect/Utils/StructuredOpsUtils.h"
10db011775SGeoffrey Martin-Noble #include "mlir/IR/AffineExpr.h"
11db011775SGeoffrey Martin-Noble #include "mlir/IR/AffineMap.h"
12db011775SGeoffrey Martin-Noble #include "gmock/gmock.h"
13db011775SGeoffrey Martin-Noble #include "gtest/gtest.h"
14db011775SGeoffrey Martin-Noble 
15db011775SGeoffrey Martin-Noble using namespace mlir;
16db011775SGeoffrey Martin-Noble using testing::Not;
17db011775SGeoffrey Martin-Noble using testing::Truly;
18db011775SGeoffrey Martin-Noble 
19db011775SGeoffrey Martin-Noble namespace {
20db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,Simple)21db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, Simple) {
22db011775SGeoffrey Martin-Noble   MLIRContext context;
23db011775SGeoffrey Martin-Noble 
24db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
25db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
26db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
27db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
28db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
29db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
30db011775SGeoffrey Martin-Noble 
31db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isRowMajorMatmul));
32db011775SGeoffrey Martin-Noble }
33db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,BindingShifted)34db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, BindingShifted) {
35db011775SGeoffrey Martin-Noble   MLIRContext context;
36db011775SGeoffrey Martin-Noble 
37db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
38db011775SGeoffrey Martin-Noble   bindDims(&context, k, m, n); // bind in different order
39db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
40db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
41db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
42db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
43db011775SGeoffrey Martin-Noble 
44db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isRowMajorMatmul));
45db011775SGeoffrey Martin-Noble }
46db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,BindingSwapped)47db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, BindingSwapped) {
48db011775SGeoffrey Martin-Noble   MLIRContext context;
49db011775SGeoffrey Martin-Noble 
50db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
51db011775SGeoffrey Martin-Noble   bindDims(&context, k, n, m); // bind in different order
52db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
53db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
54db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
55db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
56db011775SGeoffrey Martin-Noble 
57db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isRowMajorMatmul));
58db011775SGeoffrey Martin-Noble }
59db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,ColumnMajor)60db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, ColumnMajor) {
61db011775SGeoffrey Martin-Noble   MLIRContext context;
62db011775SGeoffrey Martin-Noble 
63db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
64db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
65db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
66db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
67db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
68db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
69db011775SGeoffrey Martin-Noble 
70db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isRowMajorMatmul)));
71db011775SGeoffrey Martin-Noble }
72db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,FirstInputSwapped)73db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, FirstInputSwapped) {
74db011775SGeoffrey Martin-Noble   MLIRContext context;
75db011775SGeoffrey Martin-Noble 
76db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
77db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
78db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {k, m}, &context));
79db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
80db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
81db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
82db011775SGeoffrey Martin-Noble 
83db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isRowMajorMatmul)));
84db011775SGeoffrey Martin-Noble }
85db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,TooFewMaps)86db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, TooFewMaps) {
87db011775SGeoffrey Martin-Noble   MLIRContext context;
88db011775SGeoffrey Martin-Noble 
89db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
90db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
91db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
92db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
93db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB});
94db011775SGeoffrey Martin-Noble 
95db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isRowMajorMatmul)));
96db011775SGeoffrey Martin-Noble }
97db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,TooManyMaps)98db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, TooManyMaps) {
99db011775SGeoffrey Martin-Noble   MLIRContext context;
100db011775SGeoffrey Martin-Noble 
101db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
102db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
103db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
104db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
105db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
106db011775SGeoffrey Martin-Noble   auto mapD = AffineMapAttr::get(AffineMap::get(3, 0, {k, m}, &context));
107db011775SGeoffrey Martin-Noble 
108db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC, mapD});
109db011775SGeoffrey Martin-Noble 
110db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isRowMajorMatmul)));
111db011775SGeoffrey Martin-Noble }
112db011775SGeoffrey Martin-Noble 
TEST(isRowMajorMatmul,TooFewOutputs)113db011775SGeoffrey Martin-Noble TEST(isRowMajorMatmul, TooFewOutputs) {
114db011775SGeoffrey Martin-Noble   MLIRContext context;
115db011775SGeoffrey Martin-Noble 
116db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
117db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
118db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m}, &context));
119db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
120db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
121db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
122db011775SGeoffrey Martin-Noble 
123db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isRowMajorMatmul)));
124db011775SGeoffrey Martin-Noble }
125db011775SGeoffrey Martin-Noble 
TEST(isColumnMajorMatmul,Simple)126db011775SGeoffrey Martin-Noble TEST(isColumnMajorMatmul, Simple) {
127db011775SGeoffrey Martin-Noble   MLIRContext context;
128db011775SGeoffrey Martin-Noble 
129db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
130db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
131db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
132db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
133db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
134db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
135db011775SGeoffrey Martin-Noble 
136db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isColumnMajorMatmul));
137db011775SGeoffrey Martin-Noble }
138db011775SGeoffrey Martin-Noble 
TEST(isColumnMajorMatmul,BindingShifted)139db011775SGeoffrey Martin-Noble TEST(isColumnMajorMatmul, BindingShifted) {
140db011775SGeoffrey Martin-Noble   MLIRContext context;
141db011775SGeoffrey Martin-Noble 
142db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
143db011775SGeoffrey Martin-Noble   bindDims(&context, k, m, n); // bind in different order
144db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
145db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
146db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
147db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
148db011775SGeoffrey Martin-Noble 
149db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isColumnMajorMatmul));
150db011775SGeoffrey Martin-Noble }
151db011775SGeoffrey Martin-Noble 
TEST(isColumnMajorMatmul,BindingSwapped)152db011775SGeoffrey Martin-Noble TEST(isColumnMajorMatmul, BindingSwapped) {
153db011775SGeoffrey Martin-Noble   MLIRContext context;
154db011775SGeoffrey Martin-Noble 
155db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
156db011775SGeoffrey Martin-Noble   bindDims(&context, k, n, m); // bind in different order
157db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
158db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
159db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
160db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
161db011775SGeoffrey Martin-Noble 
162db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isColumnMajorMatmul));
163db011775SGeoffrey Martin-Noble }
164db011775SGeoffrey Martin-Noble 
TEST(isColumnMajorMatmul,RowMajor)165db011775SGeoffrey Martin-Noble TEST(isColumnMajorMatmul, RowMajor) {
166db011775SGeoffrey Martin-Noble   MLIRContext context;
167db011775SGeoffrey Martin-Noble 
168db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
169db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
170db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
171db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
172db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
173db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
174db011775SGeoffrey Martin-Noble 
175db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isColumnMajorMatmul)));
176db011775SGeoffrey Martin-Noble }
177db011775SGeoffrey Martin-Noble 
TEST(isColumnMajorMatmul,FirstInputSwapped)178db011775SGeoffrey Martin-Noble TEST(isColumnMajorMatmul, FirstInputSwapped) {
179db011775SGeoffrey Martin-Noble   MLIRContext context;
180db011775SGeoffrey Martin-Noble 
181db011775SGeoffrey Martin-Noble   AffineExpr m, n, k;
182db011775SGeoffrey Martin-Noble   bindDims(&context, m, n, k);
183db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {n, k}, &context));
184db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
185db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
186db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
187db011775SGeoffrey Martin-Noble 
188db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isColumnMajorMatmul)));
189db011775SGeoffrey Martin-Noble }
190db011775SGeoffrey Martin-Noble 
TEST(isRowMajorBatchMatmul,Simple)191db011775SGeoffrey Martin-Noble TEST(isRowMajorBatchMatmul, Simple) {
192db011775SGeoffrey Martin-Noble   MLIRContext context;
193db011775SGeoffrey Martin-Noble 
194db011775SGeoffrey Martin-Noble   AffineExpr batch, m, n, k;
195db011775SGeoffrey Martin-Noble   bindDims(&context, batch, m, n, k);
196db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(4, 0, {batch, m, k}, &context));
197db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(4, 0, {batch, k, n}, &context));
198db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(4, 0, {batch, m, n}, &context));
199db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
200db011775SGeoffrey Martin-Noble 
201db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isRowMajorBatchMatmul));
202db011775SGeoffrey Martin-Noble }
203db011775SGeoffrey Martin-Noble 
TEST(isRowMajorBatchMatmul,BindingShifted)204db011775SGeoffrey Martin-Noble TEST(isRowMajorBatchMatmul, BindingShifted) {
205db011775SGeoffrey Martin-Noble   MLIRContext context;
206db011775SGeoffrey Martin-Noble 
207db011775SGeoffrey Martin-Noble   AffineExpr batch, m, n, k;
208db011775SGeoffrey Martin-Noble   bindDims(&context, k, batch, m, n); // bind in different order
209db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(4, 0, {batch, m, k}, &context));
210db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(4, 0, {batch, k, n}, &context));
211db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(4, 0, {batch, m, n}, &context));
212db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
213db011775SGeoffrey Martin-Noble 
214db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isRowMajorBatchMatmul));
215db011775SGeoffrey Martin-Noble }
216db011775SGeoffrey Martin-Noble 
TEST(isRowMajorBatchMatmul,BindingSwapped)217db011775SGeoffrey Martin-Noble TEST(isRowMajorBatchMatmul, BindingSwapped) {
218db011775SGeoffrey Martin-Noble   MLIRContext context;
219db011775SGeoffrey Martin-Noble 
220db011775SGeoffrey Martin-Noble   AffineExpr batch, m, n, k;
221db011775SGeoffrey Martin-Noble   bindDims(&context, batch, k, n, m); // bind in different order
222db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(4, 0, {batch, m, k}, &context));
223db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(4, 0, {batch, k, n}, &context));
224db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(4, 0, {batch, m, n}, &context));
225db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
226db011775SGeoffrey Martin-Noble 
227db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Truly(isRowMajorBatchMatmul));
228db011775SGeoffrey Martin-Noble }
229db011775SGeoffrey Martin-Noble 
TEST(isRowMajorBatchMatmul,FirstInputSwapped)230db011775SGeoffrey Martin-Noble TEST(isRowMajorBatchMatmul, FirstInputSwapped) {
231db011775SGeoffrey Martin-Noble   MLIRContext context;
232db011775SGeoffrey Martin-Noble 
233db011775SGeoffrey Martin-Noble   AffineExpr batch, m, n, k;
234db011775SGeoffrey Martin-Noble   bindDims(&context, batch, m, n, k);
235db011775SGeoffrey Martin-Noble   auto mapA = AffineMapAttr::get(AffineMap::get(4, 0, {batch, k, m}, &context));
236db011775SGeoffrey Martin-Noble   auto mapB = AffineMapAttr::get(AffineMap::get(4, 0, {batch, k, n}, &context));
237db011775SGeoffrey Martin-Noble   auto mapC = AffineMapAttr::get(AffineMap::get(4, 0, {batch, m, n}, &context));
238db011775SGeoffrey Martin-Noble   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
239db011775SGeoffrey Martin-Noble 
240db011775SGeoffrey Martin-Noble   EXPECT_THAT(maps, Not(Truly(isRowMajorBatchMatmul)));
241db011775SGeoffrey Martin-Noble }
242db011775SGeoffrey Martin-Noble 
TEST(isVecmat,Simple)2439f495098SNatashaKnk TEST(isVecmat, Simple) {
2449f495098SNatashaKnk   MLIRContext context;
2459f495098SNatashaKnk 
2469f495098SNatashaKnk   AffineExpr k, n;
2479f495098SNatashaKnk   bindDims(&context, k, n);
2489f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
2499f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k, n}, &context));
2509f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
2519f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
2529f495098SNatashaKnk 
2539f495098SNatashaKnk   EXPECT_THAT(maps, Truly(isVecmat));
2549f495098SNatashaKnk }
2559f495098SNatashaKnk 
TEST(isVecmat,BindingSwapped)2569f495098SNatashaKnk TEST(isVecmat, BindingSwapped) {
2579f495098SNatashaKnk   MLIRContext context;
2589f495098SNatashaKnk 
2599f495098SNatashaKnk   AffineExpr k, n;
2609f495098SNatashaKnk   bindDims(&context, n, k); // bind in different order
2619f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
2629f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k, n}, &context));
2639f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
2649f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
2659f495098SNatashaKnk 
2669f495098SNatashaKnk   EXPECT_THAT(maps, Truly(isVecmat));
2679f495098SNatashaKnk }
2689f495098SNatashaKnk 
TEST(isVecmat,WrongDimOrderMatrix)2699f495098SNatashaKnk TEST(isVecmat, WrongDimOrderMatrix) {
2709f495098SNatashaKnk   MLIRContext context;
2719f495098SNatashaKnk 
2729f495098SNatashaKnk   AffineExpr k, n;
2739f495098SNatashaKnk   bindDims(&context, k, n);
2749f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
2759f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {n, k}, &context));
2769f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
2779f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
2789f495098SNatashaKnk 
2799f495098SNatashaKnk   EXPECT_THAT(maps, Not(Truly(isVecmat)));
2809f495098SNatashaKnk }
2819f495098SNatashaKnk 
TEST(isMatvec,Simple)2829f495098SNatashaKnk TEST(isMatvec, Simple) {
2839f495098SNatashaKnk   MLIRContext context;
2849f495098SNatashaKnk 
2859f495098SNatashaKnk   AffineExpr k, n;
2869f495098SNatashaKnk   bindDims(&context, k, n);
2879f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {n, k}, &context));
2889f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
2899f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
2909f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
2919f495098SNatashaKnk 
2929f495098SNatashaKnk   EXPECT_THAT(maps, Truly(isMatvec));
2939f495098SNatashaKnk }
2949f495098SNatashaKnk 
TEST(isMatvec,BindingSwapped)2959f495098SNatashaKnk TEST(isMatvec, BindingSwapped) {
2969f495098SNatashaKnk   MLIRContext context;
2979f495098SNatashaKnk 
2989f495098SNatashaKnk   AffineExpr k, n;
2999f495098SNatashaKnk   bindDims(&context, n, k); // bind in different order
3009f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {n, k}, &context));
3019f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
3029f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
3039f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
3049f495098SNatashaKnk 
3059f495098SNatashaKnk   EXPECT_THAT(maps, Truly(isMatvec));
3069f495098SNatashaKnk }
3079f495098SNatashaKnk 
TEST(isMatvec,WrongDimOrderMatrix)3089f495098SNatashaKnk TEST(isMatvec, WrongDimOrderMatrix) {
3099f495098SNatashaKnk   MLIRContext context;
3109f495098SNatashaKnk 
3119f495098SNatashaKnk   AffineExpr k, n;
3129f495098SNatashaKnk   bindDims(&context, k, n);
3139f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k, n}, &context));
3149f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
3159f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
3169f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
3179f495098SNatashaKnk 
3189f495098SNatashaKnk   EXPECT_THAT(maps, Not(Truly(isMatvec)));
3199f495098SNatashaKnk }
3209f495098SNatashaKnk 
TEST(isBatchMatvec,Simple)3219f495098SNatashaKnk TEST(isBatchMatvec, Simple) {
3229f495098SNatashaKnk   MLIRContext context;
3239f495098SNatashaKnk 
3249f495098SNatashaKnk   AffineExpr batch, k, n;
3259f495098SNatashaKnk   bindDims(&context, batch, k, n);
3269f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n, k}, &context));
3279f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k}, &context));
3289f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n}, &context));
3299f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
3309f495098SNatashaKnk 
3319f495098SNatashaKnk   EXPECT_THAT(maps, Truly(isBatchMatvec));
3329f495098SNatashaKnk }
3339f495098SNatashaKnk 
TEST(isBatchMatvec,BindingSwapped)3349f495098SNatashaKnk TEST(isBatchMatvec, BindingSwapped) {
3359f495098SNatashaKnk   MLIRContext context;
3369f495098SNatashaKnk 
3379f495098SNatashaKnk   AffineExpr batch, k, n;
3389f495098SNatashaKnk   bindDims(&context, batch, n, k); // bind in different order
3399f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n, k}, &context));
3409f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k}, &context));
3419f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n}, &context));
3429f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
3439f495098SNatashaKnk 
3449f495098SNatashaKnk   EXPECT_THAT(maps, Truly(isBatchMatvec));
3459f495098SNatashaKnk }
3469f495098SNatashaKnk 
TEST(isBatchMatvec,Matmul)3479f495098SNatashaKnk TEST(isBatchMatvec, Matmul) {
3489f495098SNatashaKnk   MLIRContext context;
3499f495098SNatashaKnk 
3509f495098SNatashaKnk   AffineExpr m, n, k;
3519f495098SNatashaKnk   bindDims(&context, m, n, k);
3529f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
3539f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
3549f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
3559f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
3569f495098SNatashaKnk 
3579f495098SNatashaKnk   EXPECT_THAT(maps, Not(Truly(isBatchMatvec)));
3589f495098SNatashaKnk }
3599f495098SNatashaKnk 
TEST(isBatchMatvec,WrongDimOrderMatrix)3609f495098SNatashaKnk TEST(isBatchMatvec, WrongDimOrderMatrix) {
3619f495098SNatashaKnk   MLIRContext context;
3629f495098SNatashaKnk 
3639f495098SNatashaKnk   AffineExpr batch, k, n;
3649f495098SNatashaKnk   bindDims(&context, batch, k, n);
3659f495098SNatashaKnk   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k, n}, &context));
3669f495098SNatashaKnk   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k}, &context));
3679f495098SNatashaKnk   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n}, &context));
3689f495098SNatashaKnk   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
3699f495098SNatashaKnk 
3709f495098SNatashaKnk   EXPECT_THAT(maps, Not(Truly(isBatchMatvec)));
3719f495098SNatashaKnk }
3729f495098SNatashaKnk 
TEST(isBatchVecmat,Simple)373*8a80e331Sbjacob TEST(isBatchVecmat, Simple) {
374*8a80e331Sbjacob   MLIRContext context;
375*8a80e331Sbjacob 
376*8a80e331Sbjacob   AffineExpr batch, k, n;
377*8a80e331Sbjacob   bindDims(&context, batch, k, n);
378*8a80e331Sbjacob   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k}, &context));
379*8a80e331Sbjacob   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k, n}, &context));
380*8a80e331Sbjacob   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n}, &context));
381*8a80e331Sbjacob   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
382*8a80e331Sbjacob 
383*8a80e331Sbjacob   EXPECT_THAT(maps, Truly(isBatchVecmat));
384*8a80e331Sbjacob }
385*8a80e331Sbjacob 
TEST(isBatchVecmat,BindingSwapped)386*8a80e331Sbjacob TEST(isBatchVecmat, BindingSwapped) {
387*8a80e331Sbjacob   MLIRContext context;
388*8a80e331Sbjacob 
389*8a80e331Sbjacob   AffineExpr batch, k, n;
390*8a80e331Sbjacob   bindDims(&context, batch, n, k); // bind in different order
391*8a80e331Sbjacob   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k}, &context));
392*8a80e331Sbjacob   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k, n}, &context));
393*8a80e331Sbjacob   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n}, &context));
394*8a80e331Sbjacob   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
395*8a80e331Sbjacob 
396*8a80e331Sbjacob   EXPECT_THAT(maps, Truly(isBatchVecmat));
397*8a80e331Sbjacob }
398*8a80e331Sbjacob 
TEST(isBatchVecmat,Matmul)399*8a80e331Sbjacob TEST(isBatchVecmat, Matmul) {
400*8a80e331Sbjacob   MLIRContext context;
401*8a80e331Sbjacob 
402*8a80e331Sbjacob   AffineExpr m, n, k;
403*8a80e331Sbjacob   bindDims(&context, m, n, k);
404*8a80e331Sbjacob   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, &context));
405*8a80e331Sbjacob   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, &context));
406*8a80e331Sbjacob   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, &context));
407*8a80e331Sbjacob   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
408*8a80e331Sbjacob 
409*8a80e331Sbjacob   EXPECT_THAT(maps, Not(Truly(isBatchVecmat)));
410*8a80e331Sbjacob }
411*8a80e331Sbjacob 
TEST(isBatchVecmat,WrongDimOrderMatrix)412*8a80e331Sbjacob TEST(isBatchVecmat, WrongDimOrderMatrix) {
413*8a80e331Sbjacob   MLIRContext context;
414*8a80e331Sbjacob 
415*8a80e331Sbjacob   AffineExpr batch, k, n;
416*8a80e331Sbjacob   bindDims(&context, batch, k, n);
417*8a80e331Sbjacob   auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {batch, k}, &context));
418*8a80e331Sbjacob   auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n, k}, &context));
419*8a80e331Sbjacob   auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {batch, n}, &context));
420*8a80e331Sbjacob   auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
421*8a80e331Sbjacob 
422*8a80e331Sbjacob   EXPECT_THAT(maps, Not(Truly(isBatchVecmat)));
423*8a80e331Sbjacob }
424*8a80e331Sbjacob 
425db011775SGeoffrey Martin-Noble } // namespace
426