-
Notifications
You must be signed in to change notification settings - Fork 336
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
base: main
Are you sure you want to change the base?
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.
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;
Current situation: when a value of indices is out-of-bound, the execution is halted with assertion error.
This PR provides some improvements: