-
Notifications
You must be signed in to change notification settings - Fork 653
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
Adds UnitAttribute
to root ops for tuner
#19345
Conversation
e5d92a8
to
14e9c96
Compare
Signed-off-by: nithinsubbiah <[email protected]>
Signed-off-by: nithinsubbiah <[email protected]>
Signed-off-by: nithinsubbiah <[email protected]>
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.
Nice. Can you also add a test case for the strip-compilation-info pass to make sure we don't accidentally remove it there?
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.
Why do we have changes on CPU side? Can we avoid that? My concern is that people need to think about the attribute even they do not use tuners. The other concern is how do you define root op if there is op decomposition happening?
IMO, it is a layering/pluggable issue. People should not have to interpret "root_op" attribute when it is not needed.
We have a PR in review to add tuning for one of the CPU pipelines as well.
What do you mean by 'interpret'? This is a hint for other tooling only, the compiler is not meant to use it any way. |
By 'interpret', I meant that you're exposing unnecessary information for users who are on the default path. People could start asking like (1) what does it mean? (2) should we take it into account when we decompose an operation? etc. They are new overheads for people who do not have the tooling context (and they probably don't care). If it is a hint for other tooling only, why do we need to set it in the compiler default path? I think my question is more like what is the rule of attaching "random" attribute to an operation? |
I think the discussion boils down to the question - can we have op attribute that doesn't necessarily get used in the compilation pipeline? Also given we're building out the tuner infrastructure, which supplements the compiler, this is a good example to hash out how the information exchange can happen between the two. @hanhanW Would love to hear your ideas on that |
I think this is a practical solution considering the possible alternatives:
We could put it under a flag, but flags add complexity on their own. Adding a new flag would also have to have some justification, and I think in this case the whole system is simpler by adding this unit attr by default. (Compiler flag is even more visible than an attribute and also requires documentation/explanation.)
This is a good question that I don't have a good answer for. For now, it seems like tuner is the only external tool that we deal with, and after working on it for > 6 months it seems to me like the root op identification is the only piece of information that we miss from configured executables to make the tuner work. My proposal would be to allow the attribute in this case a broader compromise (very low cost to the compiler, very high usefulness to the tuner), and carefully evaluate if we discover we need more than one attribute. |
@@ -1638,7 +1638,7 @@ func.func @pad_only() attributes {hal.executable.target = #executable_target_emb | |||
// CHECK-SAME: translation_info = #[[TRANSLATION]] | |||
// CHECK: tensor.pad {{.+}} { | |||
// CHECK: tensor.yield | |||
// CHECK-NEXT: } {lowering_config = #[[CONFIG]]} |
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.
or alternatively, only match lowering_config = #[[COFIG]]
in this test to allow for other attributes
I did not join any design discussion, so I did not put a blocker on the PR. Feel free to ignore my comments if people have considered the case in discussion. 😅 I agree that it is the practical solution, and it is very valuable to see IREE + tuner working. I think we should be careful on default behavior changes, and it is why I chime in. People could start building the components without being aware of that it could impact default path. We could spend months to recover the state or get rid of tech debts. Transform matcher is a good example. The The builtin ukernel story is successful to me because we did not mess up any other default path; we figured a way to turn it on by default in IREE. Backends that do not care ukernels do not have to deal with any ukernel context. They even don't see the ukernel attribute floating in the target configuration.
I'm +1 on putting it under a flag. I honestly think that "having some justification" is good in this case. It explains to people who do not have context about it. How about having an In the comment/documentation, you can say that there are no behavioral changes on the default path, and it is mainly used for tuner project development. What do you think? iree/compiler/src/iree/compiler/Dialect/Stream/Transforms/Passes.cpp Lines 84 to 89 in 006c5d8
|
compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR/test/root_op_attribute.mlir
Outdated
Show resolved
Hide resolved
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'd add some warning that this is only used for tuner and is not intended for any other use. Relying on root op for codegen is a bit of a footgun I think.
Signed-off-by: nithinsubbiah <[email protected]>
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.
LGTM. If this gets any more complicated in the future, I think we should guard it with a flag and/or rethink the overall approach. But in the current state, I think this is fine as-is.
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, @nithinsubbiah, for ping me to review it. Again, I'm not a blocker because I don't actively work on tuning area.
I'm not approving because I'm -1 on not guarding it over a flag in the first place. Please see the inline comment for the reason. Basically, I want the attribute to evolve in our control and I want to prevent adding overheads to other contributors and reviewers in advance.
@@ -568,4 +569,13 @@ void eraseCompilationInfo(Operation *op) { | |||
op->removeAttr(kCompilationInfoAttrName); | |||
} | |||
|
|||
//===----------------------------------------------------------------------===// | |||
// Helpers for setting `iree_codegen.root_op` attribute on root operations for |
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.
There is no iree_codegen.root_op
attribute. What you're doing is adding a unit attribute to the op. Perhaps rephrase it like "Helpers for setting attributes for tuner".
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 was going to suggest updating the checks in other lit files, then I found that the structure is quite different from LLVMCPU. In LLVMGPU we group lit tests with operation categories, and all the file names start with config_
. Maybe we can rename it to config_root_op_attribute.mlir
?
/// Sets an attribute to identify the rootOp and adds any information needed for | ||
/// the tuner from compiler. Currently, only sets a `UnitAttr`. Note that this | ||
/// attribute is not used by the compiler at any level and is only intended for | ||
/// tuner use. | ||
void setRootOpInfo(Operation *op); |
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.
It is a deeply hidden warning to me. It could be outdated soon if other IREE contributors start relying on the attribute to do transformations. We could stop them, but it is like overheads++. Because reviewers need to know the information, and the contributors waste some time on the patch.
My expectation was guarding it over a flag in the first place, so it won't evolve without controls. If we start with guarding it over a flag, people who want to use the attribute will to be aware of this information.
/// Convenience function that sets the lowering configuration on the operation | ||
/// and translation info. | ||
inline LogicalResult setOpConfigAndEntryPointFnTranslation( | ||
mlir::FunctionOpInterface entryPointFn, Operation *op, | ||
IREE::Codegen::LoweringConfigAttrInterface config, | ||
IREE::Codegen::TranslationInfoAttr translationInfo) { | ||
setRootOpInfo(op); |
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.
To be more specific -- If it were me, I'd add a flag in this file and wrap this statement with the flag.
I think adding a flag that adds the root op annotation is useful. We can leave the flag off by default, but use it when calling from the tuner. Once the tuner is done, it doesnt need to add the root op marker on the final configuration. This will limit the use case to just the tuner. Does that work @kuhar ? |
OK, I live with a new flag. Yes, the flow is like what you described. |
This just might be an indication to let the compiler know that it is being involved by the tuner. There might be other places this information would be useful. |
2ed31a0
to
9d91a9d
Compare
Signed-off-by: nithinsubbiah <[email protected]>
47498b2
to
721a9e7
Compare
Signed-off-by: nithinsubbiah <[email protected]>
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.
LGTM, just two nit. Thanks!
compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenAttrs.h
Outdated
Show resolved
Hide resolved
Signed-off-by: nithinsubbiah <[email protected]>
Tags
rootOp
with aUnitAttribute
for tuner to pick up. Please note that this attribute isn't used by the compiler at any level, it's only intended to help the tuner.