Skip to content

[mlir][vector] Project out anonymous bounds in ScalableValueBoundsConstraintSet #96499

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 1 commit into from
Jul 3, 2024

Conversation

MacDue
Copy link
Member

@MacDue MacDue commented Jun 24, 2024

If we don't eliminate these columns, then in some cases we fail to compute a scalable bound. Test case reduced from a real-world example.

…straintSet

If we don't eliminate these columns, then in some cases we fail to
compute a scalable bound. Test case reduced from a real-world example.
@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-vector

Author: Benjamin Maxwell (MacDue)

Changes

If we don't eliminate these columns, then in some cases we fail to compute a scalable bound. Test case reduced from a real-world example.


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

2 Files Affected:

  • (modified) mlir/lib/Dialect/Vector/IR/ScalableValueBoundsConstraintSet.cpp (+2)
  • (modified) mlir/test/Dialect/Vector/test-scalable-bounds.mlir (+28)
diff --git a/mlir/lib/Dialect/Vector/IR/ScalableValueBoundsConstraintSet.cpp b/mlir/lib/Dialect/Vector/IR/ScalableValueBoundsConstraintSet.cpp
index 9c365376c84c9..4a826f04e1f1d 100644
--- a/mlir/lib/Dialect/Vector/IR/ScalableValueBoundsConstraintSet.cpp
+++ b/mlir/lib/Dialect/Vector/IR/ScalableValueBoundsConstraintSet.cpp
@@ -8,6 +8,7 @@
 
 #include "mlir/Dialect/Vector/IR/ScalableValueBoundsConstraintSet.h"
 #include "mlir/Dialect/Vector/IR/VectorOps.h"
+
 namespace mlir::vector {
 
 FailureOr<ConstantOrScalableBound::BoundSize>
@@ -74,6 +75,7 @@ ScalableValueBoundsConstraintSet::computeScalableBound(
     return p.first != scalableCstr.getVscaleValue() && !isStartingPoint;
   };
   scalableCstr.projectOut(projectOutFn);
+  scalableCstr.projectOutAnonymous(/*except=*/pos);
   // Also project out local variables (these are not tracked by the
   // ValueBoundsConstraintSet).
   for (unsigned i = 0, e = scalableCstr.cstr.getNumLocalVars(); i < e; ++i) {
diff --git a/mlir/test/Dialect/Vector/test-scalable-bounds.mlir b/mlir/test/Dialect/Vector/test-scalable-bounds.mlir
index 673e03f05c1b8..6af904beb660b 100644
--- a/mlir/test/Dialect/Vector/test-scalable-bounds.mlir
+++ b/mlir/test/Dialect/Vector/test-scalable-bounds.mlir
@@ -215,3 +215,31 @@ func.func @unsupported_negative_mod() {
   "test.some_use"(%bound) : (index) -> ()
   return
 }
+
+// -----
+
+// CHECK: #[[$SCALABLE_BOUND_MAP_5:.*]] = affine_map<()[s0] -> (s0 * 4)>
+
+// CHECK-LABEL: @extract_slice_loop
+//       CHECK:   %[[VSCALE:.*]] = vector.vscale
+//       CHECK:   %[[SCALABLE_BOUND:.*]] = affine.apply #[[$SCALABLE_BOUND_MAP_5]]()[%[[VSCALE]]]
+//       CHECK:   "test.some_use"(%[[SCALABLE_BOUND]]) : (index) -> ()
+
+func.func @extract_slice_loop(%tensor: tensor<1x1x3x?xf32>) {
+  %vscale = vector.vscale
+  %c0 = arith.constant 0 : index
+  %c1 = arith.constant 1 : index
+  %c2 = arith.constant 2 : index
+  %c3 = arith.constant 3 : index
+  %c4 = arith.constant 4 : index
+  %cst = arith.constant 0.0 : f32
+  %c4_vscale = arith.muli %c4, %vscale : index
+  %slice = tensor.extract_slice %tensor[0, 0, 0, 0] [1, 1, 3, %c4_vscale] [1, 1, 1, 1] : tensor<1x1x3x?xf32> to tensor<1x3x?xf32>
+  %15 = scf.for %arg6 = %c0 to %c3 step %c1 iter_args(%arg = %slice) -> (tensor<1x3x?xf32>) {
+    %dim = tensor.dim %arg, %c2 : tensor<1x3x?xf32>
+    %bound = "test.reify_bound"(%dim) {type = "LB", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
+    "test.some_use"(%bound) : (index) -> ()
+    scf.yield %arg : tensor<1x3x?xf32>
+  }
+  return
+}

@MacDue MacDue requested a review from c-rhodes June 26, 2024 12:13
Copy link
Collaborator

@c-rhodes c-rhodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems ok to me but would be good to get eyes from an expert @matthias-springer

@MacDue MacDue merged commit 68a1944 into llvm:main Jul 3, 2024
11 checks passed
@MacDue MacDue deleted the bounds_fix branch July 3, 2024 09:04
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
…straintSet (llvm#96499)

If we don't eliminate these columns, then in some cases we fail to
compute a scalable bound. Test case reduced from a real-world example.
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
…straintSet (llvm#96499)

If we don't eliminate these columns, then in some cases we fail to
compute a scalable bound. Test case reduced from a real-world example.
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