-
Notifications
You must be signed in to change notification settings - Fork 14
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
Mark all TTIR and TTNN ops as pure #1481
Conversation
161fc96
to
704c7dc
Compare
Can you update
->
|
704c7dc
to
4b52f8e
Compare
@sasha, I've removed the comment and redundant |
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.
Almost all of our ops are Pure, but not all. In my opinion the best solution would be introducing new class just below TTIR_Op
, something like TTIR_PureOp
where all other classes would 'extend' that new class, and ops that aren't pure would be defined on the TTIR_Op
class. Analogous for the TTNN dialect.
@@ -38,6 +39,6 @@ def TTIR_Dialect : Dialect { | |||
//===----------------------------------------------------------------------===// | |||
|
|||
class TTIR_Op<string mnemonic, list<Trait> traits = []> : | |||
Op<TTIR_Dialect, mnemonic, traits>; | |||
Op<TTIR_Dialect, mnemonic, !listconcat(traits, [Pure])>; |
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.
Should Pure
trait be the top-level trait? I'm thinking about alloc
and dealloc
. Every dealloc
will trivially be removed since it doesn't produce the result.
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.
Good point, we probably should adopt MemAlloc
and MemFree
traits for those respectively.
@@ -45,6 +46,6 @@ def TTNN_Dialect : Dialect { | |||
//===----------------------------------------------------------------------===// | |||
|
|||
class TTNN_Op<string mnemonic, list<Trait> traits = []> : | |||
Op<TTNN_Dialect, mnemonic, !listconcat(traits, [TTNN_OpModelInterface, TTNN_WorkaroundInterface])>; | |||
Op<TTNN_Dialect, mnemonic, !listconcat(traits, [Pure, TTNN_OpModelInterface, TTNN_WorkaroundInterface])>; |
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.
Same as above.
@LPanosTT, could you please address @azecevicTT's comments? I know the comment is after the merge, but it is still a valid concern, and we should address it sooner rather than later. |
@azecevicTT apologies for not responding earlier, but I agree with both you and nick. We may aswell be more precise in modelling memory effects if we’re going to in the first place |
@nsmithtt @LPanosTT I think we have an even bigger problem because of DPS. Take this example:
Semantically |
I believe we need to revert this and consider the proper solution. DPS ops are not considered pure by default. |
This is an ill formed program if the intention is to do what you stated. DPS uses SSA form for exactly this reason, if you don't use the result of the op then it should rightfully erase it. The correct way to express this semantically in ttir (i.e. DPS) is: return %1 : tensor<128x64xbf16> See this section of the bufferization doc https://mlir.llvm.org/docs/Bufferization/#destination-passing-style. Relevant paragraph:
So it follows, in your example, returning |
@nsmithtt Thanks for the clarification, it makes more sense now. There are even some examples here https://mlir.llvm.org/docs/Dialects/TensorOps with DPS + Pure. We still need to address the cases of alloc and dealloc (and maybe some other ops), but majority of ops should still stay Pure. |
Pure
attribute to all TTIR and TTNN ops since they are pure SSA ops.RemoveDeadValues
pass can now trim dead code off of TTIR and TTNN modules effectively.