[Mlir-commits] [mlir] [mlir] Add ContractionOpInterface utility functions for vector matrix multiplication (PR #68945)
Jerry Wu
llvmlistbot at llvm.org
Mon Oct 16 10:25:01 PDT 2023
================
@@ -240,4 +240,134 @@ TEST(isRowMajorBatchMatmul, FirstInputSwapped) {
EXPECT_THAT(maps, Not(Truly(isRowMajorBatchMatmul)));
}
+TEST(isVecmat, Simple) {
+ MLIRContext context;
+
+ AffineExpr k, n;
+ bindDims(&context, k, n);
+ auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
+ auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k, n}, &context));
+ auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
+ auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
+
+ EXPECT_THAT(maps, Truly(isVecmat));
+}
+
+TEST(isVecmat, BindingSwapped) {
+ MLIRContext context;
+
+ AffineExpr k, n;
+ bindDims(&context, k, n); // bind in different order
+ auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
+ auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k, n}, &context));
+ auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
+ auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
+
+ EXPECT_THAT(maps, Truly(isVecmat));
+}
+
+TEST(isVecmat, WrongDimOrderMatrix) {
+ MLIRContext context;
+
+ AffineExpr k, n;
+ bindDims(&context, k, n);
+ auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
+ auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {n, k}, &context));
+ auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
+ auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
+
+ EXPECT_THAT(maps, Not(Truly(isVecmat)));
+}
+
+TEST(isMatvec, Simple) {
+ MLIRContext context;
+
+ AffineExpr k, n;
+ bindDims(&context, k, n);
+ auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {n, k}, &context));
+ auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k}, &context));
+ auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, &context));
+ auto maps = ArrayAttr::get(&context, {mapA, mapB, mapC});
+
+ EXPECT_THAT(maps, Truly(isMatvec));
+}
+
+TEST(isMatvec, BindingSwapped) {
+ MLIRContext context;
+
+ AffineExpr k, n;
+ bindDims(&context, k, n); // bind in different order
----------------
pzread wrote:
Same here
https://github.com/llvm/llvm-project/pull/68945
More information about the Mlir-commits
mailing list