-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir] [transform dialect] NamedSequenceOp build: honor arg_attrs when building #168101
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
base: main
Are you sure you want to change the base?
Conversation
Previously the builder did not attach argument attributes when calling NamedSequenceOp::build with `arg_attrs`, which makes we can not create a legal named_sequence operation by this builder. This patch ensures `arg_attrs` are stored in the op state so verification and printing show them.
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-mlir Author: None (colawithsauce) ChangesPreviously the builder did not attach argument attributes when calling NamedSequenceOp::build with This patch ensures Full diff: https://github.com/llvm/llvm-project/pull/168101.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 062606e7e10b6..415e2af491c07 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -2571,6 +2571,11 @@ void transform::NamedSequenceOp::build(OpBuilder &builder,
TypeAttr::get(FunctionType::get(builder.getContext(),
rootType, resultTypes)));
state.attributes.append(attrs.begin(), attrs.end());
+ if (!argAttrs.empty()) {
+ SmallVector<Attribute> argAttrsVec(argAttrs.begin(), argAttrs.end());
+ state.getOrAddProperties<Properties>().arg_attrs =
+ ArrayAttr::get(builder.getContext(), argAttrsVec);
+ }
state.addRegion();
buildSequenceBody(builder, state, rootType,
|
ftynse
left a comment
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.
Looks like some side effect of property transition, thanks!
|
Can this be tested? |
of course, I'll add an unit test soon. |
Now, after CMake: |
|
|
||
| StringAttr arg0Name = seqOp.getArgAttrsAttrName(); | ||
| EXPECT_TRUE(arg0Name); | ||
| } No newline at end of file |
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.
I would hope we don't need a c++ unit-test here, can this move to an IR test?
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.
this bug doesn't affect IR, because when parsing IR, this function NamedSequence::build does not invoked. It invokes versions that auto generated by TableGen.
However, for those user that writing an scheduler, they need to create an transform.named_sequence with C++
this build function addtion to versions auto genrated is to make this progress convinient.
So i am afraid to say sorry, I could not write an IR test for this case, because its only for c++
thanks for your attention.
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.
Are you saying that outside of this unit-test, this method is dead code in the codebase?
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.
I checked: this is dead-code...
I still don't think we're usually adding C++ unit-tests for covering every builders.
But also, builders are added when needed, I guess someone had a need downstream when they added this builder?
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.
I think so. This builder have no usage out of this unittest. In my AI compiler project I use it to build my own schedule sequence. But it failed to work. And then with hours of struggling I find this bug and fix it at my downstream.
Since it is dead code, I have no idea this should be fix or removed instead?
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.
We don't have an established pattern for testing this kind of code, I wonder if we should have a single file per dialect, maybe: TransformDialectODSHelperTests.cpp or something like that?
@jpienaar maybe?
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.
I don't think any of the builders are tested directly. We could test them by, e.g., having a test pass (per dialect) that simply calls the builders and FileCheck the IR generated by the pass.
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.
Yes I was thinking something similar to Mehdi here. Well in order
- Ideally builders (not automatically generated) are tested via existing passes upstream and there is use of them. No additional worked needed and builder obviously useful.
- Builder file say per dialect.
The pros and cons of builder unit test vs pass for me is, that unit test becomes its own binary (so extra linkage cost) but it doesn't bloat mlir-opt. Now, one could argue that mlir-opt is already a testing tool and so that doesn't actually matter. In which case Alex's suggestion is better.
I could see us doing a C++ unit test that looks like the Python lit tests (compile, run and check with lit). I am spoilt as I have a parallel build, but if we restrict it per dialect and only for those not covered in another way already, it's probably small set and not high cost while being very directed.
| builder.getNamedAttr(TransformDialect::kArgConsumedAttrName, | ||
| builder.getUnitAttr())})}); | ||
|
|
||
| // 检查 body argument 上有没有 transform.consumed |
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.
Please use English in comments.
|
|
||
| StringAttr arg0Name = seqOp.getArgAttrsAttrName(); | ||
| EXPECT_TRUE(arg0Name); | ||
| } No newline at end of file |
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.
Add the trailing new line (and configure your code editor not to remove it).
Previously the builder did not attach argument attributes when calling NamedSequenceOp::build with
arg_attrs, which makes we can not create a legal named_sequence operation by this builder.This patch ensures
arg_attrsare stored in the op state so verification and printing show them.