Skip to content

[mlir][affine] Check the input vector sizes to be greater than 0 #65293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 2, 2023

Conversation

Lewuathe
Copy link
Member

@Lewuathe Lewuathe commented Sep 5, 2023

In the process of vectorization of the affine loop, the 0 vector size causes the crash with building the invalid AffineForOp. We can catch the case beforehand propagating to the assertion.

See: #64262

@Lewuathe Lewuathe requested a review from a team as a code owner September 5, 2023 05:41
@llvmbot
Copy link
Member

llvmbot commented Sep 27, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-affine

Changes

In the process of vectorization of the affine loop, the 0 vector size causes the crash with building the invalid AffineForOp. We can catch the case beforehand propagating to the assertion.

See: #64262


Full diff: https://github.com/llvm/llvm-project/pull/65293.diff

3 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Affine/Passes.td (+2-1)
  • (modified) mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp (+5)
  • (added) mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir (+9)
diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td b/mlir/include/mlir/Dialect/Affine/Passes.td
index 891a6661ca87be7..1036e93a0392409 100644
--- a/mlir/include/mlir/Dialect/Affine/Passes.td
+++ b/mlir/include/mlir/Dialect/Affine/Passes.td
@@ -349,7 +349,8 @@ def AffineVectorize : Pass<"affine-super-vectorize", "func::FuncOp"> {
   let dependentDialects = ["vector::VectorDialect"];
   let options = [
     ListOption<"vectorSizes", "virtual-vector-size", "int64_t",
-               "Specify an n-D virtual vector size for vectorization">,
+               "Specify an n-D virtual vector size for vectorization. "
+               "This must be greater than zero.">,
     // Optionally, the fixed mapping from loop to fastest varying MemRef
     // dimension for all the MemRefs within a loop pattern:
     //   the index represents the loop depth, the value represents the k^th
diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 85c2602aa266d67..a1d9c7b56c4e154 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,6 +1732,11 @@ void Vectorize::runOnOperation() {
     return signalPassFailure();
   }
 
+  if (llvm::any_of(vectorSizes, [](int64_t size) { return size <= 0; })) {
+    f.emitError("Vectorization factor must be greater than zero.");
+    return signalPassFailure();
+  }
+
   DenseSet<Operation *> parallelLoops;
   ReductionLoopMap reductionLoops;
 
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
new file mode 100644
index 000000000000000..396cc933e25bcf4
--- /dev/null
+++ b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
@@ -0,0 +1,9 @@
+// RUN: mlir-opt %s -verify-diagnostics --affine-super-vectorize=virtual-vector-size=0
+
+// expected-error@+1 {{Vectorization factor must be greater than zero}} 
+func.func @with_zero_vector_size(%arg0: memref<21x12x12xi1>) {
+  affine.for %arg1 = 0 to 84 step 4294967295 {
+  }
+  return
+}
+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants