Skip to content

Commit 10cff75

Browse files
committed
[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 llvm#61842 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D147765
1 parent ff0aabf commit 10cff75

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: mlir-opt %s -affine-super-vectorizer-test -vectorize-affine-loop-nest -split-input-file 2>&1 | FileCheck %s
2+
3+
func.func @unparallel_loop_reduction_unsupported(%in: memref<256x512xf32>, %out: memref<256xf32>) {
4+
// CHECK: Outermost loop cannot be parallel
5+
%cst = arith.constant 1.000000e+00 : f32
6+
%final_red = affine.for %j = 0 to 512 iter_args(%red_iter = %cst) -> (f32) {
7+
%add = arith.addf %red_iter, %red_iter : f32
8+
affine.yield %add : f32
9+
}
10+
return
11+
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct VectorizerTestPass
9292
void testComposeMaps(llvm::raw_ostream &outs);
9393

9494
/// Test for 'vectorizeAffineLoopNest' utility.
95-
void testVecAffineLoopNest();
95+
void testVecAffineLoopNest(llvm::raw_ostream &outs);
9696
};
9797

9898
} // namespace
@@ -226,7 +226,7 @@ void VectorizerTestPass::testComposeMaps(llvm::raw_ostream &outs) {
226226
}
227227

228228
/// Test for 'vectorizeAffineLoopNest' utility.
229-
void VectorizerTestPass::testVecAffineLoopNest() {
229+
void VectorizerTestPass::testVecAffineLoopNest(llvm::raw_ostream &outs) {
230230
std::vector<SmallVector<AffineForOp, 2>> loops;
231231
gatherLoops(getOperation(), loops);
232232

@@ -239,6 +239,13 @@ void VectorizerTestPass::testVecAffineLoopNest() {
239239
VectorizationStrategy strategy;
240240
strategy.vectorSizes.push_back(4 /*vectorization factor*/);
241241
strategy.loopToVectorDim[outermostLoop] = 0;
242+
243+
ReductionLoopMap reductionLoops;
244+
SmallVector<LoopReduction, 2> reductions;
245+
if (!isLoopParallel(outermostLoop, &reductions)) {
246+
outs << "Outermost loop cannot be parallel\n";
247+
return;
248+
}
242249
std::vector<SmallVector<AffineForOp, 2>> loopsToVectorize;
243250
loopsToVectorize.push_back({outermostLoop});
244251
(void)vectorizeAffineLoopNest(loopsToVectorize, strategy);
@@ -273,7 +280,7 @@ void VectorizerTestPass::runOnOperation() {
273280
}
274281

275282
if (clTestVecAffineLoopNest)
276-
testVecAffineLoopNest();
283+
testVecAffineLoopNest(outs);
277284

278285
if (!outs.str().empty()) {
279286
emitRemark(UnknownLoc::get(&getContext()), outs.str());

0 commit comments

Comments
 (0)