-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir][scf]: Avoid using wrong calculation loop pipelining kernel upperbound #116748
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -444,7 +444,15 @@ scf::ForOp LoopPipelinerInternal::createKernelLoop( | |||||||
loc, rewriter.getIntegerAttr(t, maxStage)); | ||||||||
Value maxStageByStep = | ||||||||
rewriter.create<arith::MulIOp>(loc, step, maxStageValue); | ||||||||
newUb = rewriter.create<arith::SubIOp>(loc, ub, maxStageByStep); | ||||||||
Value hasAtLeastOneIteration = rewriter.create<arith::CmpIOp>( | ||||||||
loc, arith::CmpIPredicate::slt, maxStageByStep, ub); | ||||||||
Value possibleNewUB = | ||||||||
rewriter.create<arith::SubIOp>(loc, ub, maxStageByStep); | ||||||||
// In case of `index` or `unsigned` type, we need to make sure that the | ||||||||
// subtraction does not result in a negative value, instead we use lb | ||||||||
// to avoid entering the kernel loop. | ||||||||
newUb = rewriter.create<arith::SelectOp>( | ||||||||
loc, hasAtLeastOneIteration, possibleNewUB, forOp.getLowerBound()); | ||||||||
Comment on lines
+447
to
+455
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this is needed, if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ThomasRaoux , actualy what we want to make sure is that maxStageByStep < ub, because if those value are from
Then: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scf.for comparison is always signed as far as I know. In what case would we have an unsigned comparison of lb and ub? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is how the scf.for gets lowered: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The induction variable/lb/ub of
So it also affects the calcualtion of
With the notion of: **Rationale:** integers of platform-specific bit widths are practical to express sizes, dimensionalities and subscripts.
So we consider There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is correct, signless means the type doesn't contain information on the whether it is signed or unsigned and the information is carried by the op. In the case of scf.for the comparison is signed in scf.for semantic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@jpienaar @marbre @ThomasRaoux Personally I can agree with both signed/unsigned but I would like us to be aligned and define it in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree we should clarify the definition of scf.for. The comparison needs to be signed or unsigned it cannot be either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ThomasRaoux @joker-eph Closing this one as now the change is not needed. |
||||||||
} | ||||||||
auto newForOp = | ||||||||
rewriter.create<scf::ForOp>(forOp.getLoc(), forOp.getLowerBound(), newUb, | ||||||||
|
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 assumes lb is 0?
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.
Actualy what we want to make sure is that
maxStageByStep < ub
, because if those value are fromunsigned
orindex
may lead to wrong answer. Please see full answer in the second thread.