-
Notifications
You must be signed in to change notification settings - Fork 338
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
Handle out-of-bound value for Gather alike operation #3077
Conversation
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Chen Tong <[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.
You could do a common function
generateDynBoundCheck0ToUb(rewriter, op, index, ub, message)
where you extract the message you want from the op, can append message, and generate the needed code.
" indices of GatherOp is less than the lower bound"); | ||
create.math.slt(index.getValue(), zeroIE.getValue()); | ||
Value outBound = | ||
create.math.ori(compareUpperBound, compareLowerBound); |
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 add SCFBuilder
to create object, and then you can use
void ifThenElse(mlir::Value cond, SCFThenElseBodyFn thenFn,
SCFThenElseBodyFn elseFn = nullptr) const;
to be in line with current practices.
// The modification of index could be put into IfOp to save | ||
// some condition check, but the code will become complicated. | ||
index = index.selectOrSelf(index < zeroIE, zeroIE); | ||
index = index.selectOrSelf(index >= axisDim, zeroIE); |
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 not capping at 0
on the lower side and axisDim
on the upper size?
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.
No particular reason. Just feel 0 is a safer choice.
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.
Modified
rewriter.create<cf::AssertOp>(loc, compareUpperBound, | ||
nodeNameStr + | ||
" indices of GatherOp is larger than the upper bound"); | ||
|
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.
Since index is already an IndexExpr, and that we have the dim of axis in the loop bounds, you could use index express all the way through as it has overloaded operators.
IndexExpr operator==(IndexExpr const b) const;
IndexExpr operator==(int64_t const b) const;
IndexExpr operator!=(IndexExpr const b) const;
IndexExpr operator!=(int64_t const b) const;
IndexExpr operator<=(IndexExpr const b) const;
IndexExpr operator<=(int64_t const b) const;
IndexExpr operator<(IndexExpr const b) const;
IndexExpr operator<(int64_t const b) const;
IndexExpr operator>=(IndexExpr const b) const;
IndexExpr operator>=(int64_t const b) const;
IndexExpr operator>(IndexExpr const b) const;
IndexExpr operator>(int64_t const b) const;
IndexExpr operator&(IndexExpr const b) const;
IndexExpr operator|(IndexExpr const b) const;
IndexExpr operator!() const;
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
Rewrite most of the code:
|
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, thanks for the updates
create.krnl.printf(msg, indexVal, true); | ||
msg = "The out-of-bound index is replaced with zero.\n"; | ||
create.krnl.printf(msg); | ||
thenBuilder.create<scf::YieldOp>(thenLoc); |
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 believe the yield is already generated by the SCF IfTHenElse; moreover, the else parameter defaults to nullptr, so that could also be skipped.
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
@Jenkins test this please |
@jenkins-droid test this please |
Jenkins Linux amd64 Build #16324 [push] Handle out-of-bound valu... started at 10:58 |
Jenkins Linux s390x Build #16326 [push] Handle out-of-bound valu... started at 11:58 |
Jenkins Linux ppc64le Build #15307 [push] Handle out-of-bound valu... started at 12:08 |
Jenkins Linux amd64 Build #16324 [push] Handle out-of-bound valu... passed after 1 hr 22 min |
Jenkins Linux s390x Build #16326 [push] Handle out-of-bound valu... passed after 1 hr 41 min |
Jenkins Linux ppc64le Build #15307 [push] Handle out-of-bound valu... passed after 4 hr 22 min |
Current situation: when a value of indices is out-of-bound, the execution is halted with assertion error.
This PR provides some improvements: