[Mlir-commits] [mlir] 10cff75 - [mlir][affine] Vectorizer test notifies the case with the unparallel loop with reduction

Kai Sasaki llvmlistbot at llvm.org
Fri Apr 7 00:02:07 PDT 2023


Author: Kai Sasaki
Date: 2023-04-07T15:56:34+09:00
New Revision: 10cff75f12b270d856a4ff36e76a1b8441d6e2ff

URL: https://github.com/llvm/llvm-project/commit/10cff75f12b270d856a4ff36e76a1b8441d6e2ff
DIFF: https://github.com/llvm/llvm-project/commit/10cff75f12b270d856a4ff36e76a1b8441d6e2ff.diff

LOG: [mlir][affine] Vectorizer test notifies the case with the unparallel loop with reduction

Vectorizer test does not support unparallel loop since no parallel reduction is available. We can emit the informational message instead of crashing the cli in such a case.
Fixes https://github.com/llvm/llvm-project/issues/61842

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D147765

Added: 
    mlir/test/Dialect/Affine/SuperVectorize/vectorize_unsupported.mlir

Modified: 
    mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/Dialect/Affine/SuperVectorize/vectorize_unsupported.mlir b/mlir/test/Dialect/Affine/SuperVectorize/vectorize_unsupported.mlir
new file mode 100644
index 0000000000000..c117bfc82ca07
--- /dev/null
+++ b/mlir/test/Dialect/Affine/SuperVectorize/vectorize_unsupported.mlir
@@ -0,0 +1,11 @@
+// RUN: mlir-opt %s -affine-super-vectorizer-test  -vectorize-affine-loop-nest -split-input-file 2>&1 |  FileCheck %s
+
+func.func @unparallel_loop_reduction_unsupported(%in: memref<256x512xf32>, %out: memref<256xf32>) {
+ // CHECK: Outermost loop cannot be parallel
+ %cst = arith.constant 1.000000e+00 : f32
+ %final_red = affine.for %j = 0 to 512 iter_args(%red_iter = %cst) -> (f32) {
+   %add = arith.addf %red_iter, %red_iter : f32
+   affine.yield %add : f32
+ }
+ return
+}

diff  --git a/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp b/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
index b31dd3f7d866f..5ff4e55a1e96c 100644
--- a/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
@@ -92,7 +92,7 @@ struct VectorizerTestPass
   void testComposeMaps(llvm::raw_ostream &outs);
 
   /// Test for 'vectorizeAffineLoopNest' utility.
-  void testVecAffineLoopNest();
+  void testVecAffineLoopNest(llvm::raw_ostream &outs);
 };
 
 } // namespace
@@ -226,7 +226,7 @@ void VectorizerTestPass::testComposeMaps(llvm::raw_ostream &outs) {
 }
 
 /// Test for 'vectorizeAffineLoopNest' utility.
-void VectorizerTestPass::testVecAffineLoopNest() {
+void VectorizerTestPass::testVecAffineLoopNest(llvm::raw_ostream &outs) {
   std::vector<SmallVector<AffineForOp, 2>> loops;
   gatherLoops(getOperation(), loops);
 
@@ -239,6 +239,13 @@ void VectorizerTestPass::testVecAffineLoopNest() {
   VectorizationStrategy strategy;
   strategy.vectorSizes.push_back(4 /*vectorization factor*/);
   strategy.loopToVectorDim[outermostLoop] = 0;
+
+  ReductionLoopMap reductionLoops;
+  SmallVector<LoopReduction, 2> reductions;
+  if (!isLoopParallel(outermostLoop, &reductions)) {
+    outs << "Outermost loop cannot be parallel\n";
+    return;
+  }
   std::vector<SmallVector<AffineForOp, 2>> loopsToVectorize;
   loopsToVectorize.push_back({outermostLoop});
   (void)vectorizeAffineLoopNest(loopsToVectorize, strategy);
@@ -273,7 +280,7 @@ void VectorizerTestPass::runOnOperation() {
   }
 
   if (clTestVecAffineLoopNest)
-    testVecAffineLoopNest();
+    testVecAffineLoopNest(outs);
 
   if (!outs.str().empty()) {
     emitRemark(UnknownLoc::get(&getContext()), outs.str());


        


More information about the Mlir-commits mailing list