-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[MLIR] Minor fixes to FoldTransposeBroadcast rewrite (NFC) #140083
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
Conversation
This patch contains to minor changes, which I believe were the original author's intent. * when folding `transpose(broadcast(x))` emit `broadcast(x)` instead of `broadcast(broadca(x))`. The later causes intermittent verifier failures, e.g. ``` mlir-asm-printer: 'func.func' failed to verify and will be printed in generic form "func.func"() <{function_type = (vector<4x1x1x7xi8>) -> vector<3x2x4x5x6x7xi8>, sym_name = "broadcast_transpose_mixed_example"}> ({ ^bb0(%arg0: vector<4x1x1x7xi8>): %0 = "vector.broadcast"(%arg0) : (vector<4x1x1x7xi8>) -> vector<2x3x4x5x6x7xi8> %1 = "vector.broadcast"(%0) : (vector<2x3x4x5x6x7xi8>) -> vector<3x2x4x5x6x7xi8> "func.return"(%1) : (vector<3x2x4x5x6x7xi8>) -> () }) : () -> () ``` * when checking permutation groups the variable `low` was set just once to zero, thus checking was quadratic. It looks the intent was for `low` to track the beginning of each dimension groups. (Nevertheless the check was correct).
@llvm/pr-subscribers-mlir-vector Author: Momchil Velikov (momchil-velikov) ChangesThis patch contains two minor changes, which I believe were the original author's intent.
Full diff: https://github.com/llvm/llvm-project/pull/140083.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 79bf87ccd34af..7ae43b64a5deb 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -6201,7 +6201,7 @@ class FoldTransposeBroadcast : public OpRewritePattern<vector::TransposeOp> {
bool inputIsScalar = !inputType;
if (inputIsScalar) {
rewriter.replaceOpWithNewOp<vector::BroadcastOp>(transpose, outputType,
- transpose.getVector());
+ broadcast.getSource());
return success();
}
@@ -6227,6 +6227,7 @@ class FoldTransposeBroadcast : public OpRewritePattern<vector::TransposeOp> {
transpose, "permutation not local to group");
}
}
+ low = high;
}
}
@@ -6241,7 +6242,7 @@ class FoldTransposeBroadcast : public OpRewritePattern<vector::TransposeOp> {
"not broadcastable directly to transpose output");
rewriter.replaceOpWithNewOp<vector::BroadcastOp>(transpose, outputType,
- transpose.getVector());
+ broadcast.getSource());
return success();
}
|
@llvm/pr-subscribers-mlir Author: Momchil Velikov (momchil-velikov) ChangesThis patch contains two minor changes, which I believe were the original author's intent.
Full diff: https://github.com/llvm/llvm-project/pull/140083.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 79bf87ccd34af..7ae43b64a5deb 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -6201,7 +6201,7 @@ class FoldTransposeBroadcast : public OpRewritePattern<vector::TransposeOp> {
bool inputIsScalar = !inputType;
if (inputIsScalar) {
rewriter.replaceOpWithNewOp<vector::BroadcastOp>(transpose, outputType,
- transpose.getVector());
+ broadcast.getSource());
return success();
}
@@ -6227,6 +6227,7 @@ class FoldTransposeBroadcast : public OpRewritePattern<vector::TransposeOp> {
transpose, "permutation not local to group");
}
}
+ low = high;
}
}
@@ -6241,7 +6242,7 @@ class FoldTransposeBroadcast : public OpRewritePattern<vector::TransposeOp> {
"not broadcastable directly to transpose output");
rewriter.replaceOpWithNewOp<vector::BroadcastOp>(transpose, outputType,
- transpose.getVector());
+ broadcast.getSource());
return success();
}
|
Can you provide a test that triggered the verification error? |
Yes, it from the test from the original PR #135096 |
Thanks @momchil-velikov I think you are correct. What I don't understand is why there was no verification error, every time. For example in
It was converting
to
but that
|
Yes, good catch thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. I find it worrying that this didn't create a verification error every time (as per comment above). I'll spend some time trying to figure out why not (any suggestions @joker-eph ?) maybe if you can too @momchil-velikov that'll be useful (I'm not sure I'll manage to reproduce any verification error with my setup).
nit: technically not (NFC) ?.
I can see this everytime in when running mlir-opt with the |
I guess, what do you mean by intermittent? This fixes a bug (thanks again!) I'm just not sure it would cause anything observable like intermittent compilation failure. My rough understanding is that the verifier is only called with |
I guess bad wording. I saw it with |
Ok, good. Thanks! |
Can you try building |
I've just tried this and yes, it fails. That's a useful flag, thanks for point this out @banach-space! Should there be a build in CI with this on? |
All the builders are defined here: Unfortunately, searching for I'll look into whether we can add a dedicated builder for this - but please don’t hold your breath; these things can take time. |
Let's see if I follow... we initially generate:
but the CHECK rules don't fail:
because there is another folding that is turning the two invalid Yeah, having a buildbot covering this would be awesome. |
Thanks @banach-space that might be useful, do let me know if I can help |
This patch contains two minor changes, which I believe were the original author's intent.
transpose(broadcast(x))
emitbroadcast(x)
instead ofbroadcast(broadcast(x))
. The latter causes intermittent verifier failures, e.g.low
was set just once to zero, thus checking was quadratic. It looks the intent was forlow
to track the beginning of each dimension groups. (Nevertheless the check was correct).