-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[RELAY][Fix] i64 indices #5235
[RELAY][Fix] i64 indices #5235
Conversation
@hzfan can you followup? |
@tqchen ok, I will follow up. |
318fea3
to
c79dc79
Compare
0b16f80
to
e941d98
Compare
e941d98
to
112bdec
Compare
return relay.Function([x], y) | ||
|
||
orig = before() | ||
fuse0(tvm.IRModule.from_expr(orig)) |
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 used?
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.
Can I just remove this? @kazum
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.
Maybe yes, I just copied the lines from other tests in the same file.
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.
Removed. Thanks @kazum .
return relay.Function([x], y) | ||
|
||
orig = before() | ||
fuse0(tvm.IRModule.from_expr(orig)) |
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.
not used?
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.
Removed.
src/te/schedule/operation_inline.cc
Outdated
@@ -63,7 +63,9 @@ class OperationInliner final : public StmtExprMutator { | |||
} else { | |||
Map<Var, PrimExpr> vmap; | |||
for (size_t i = 0; i < args_.size(); ++i) { | |||
vmap.Set(args_[i], op->indices[i]); | |||
// indices into `operation_` must be in the range of its output shape, | |||
// so we can safely cast the indices without worrying about overflow |
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 dont understand this comment, can you try to clarify it?
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.
Sure. An example is
a_i32 = tvm.tir.const(2, “int32”)
b_i64 = tvm.tir.const(2 ** 32, “int64”)
a0 = te.placeholder((a_i32,), “a0”)
a = te.compute((a_i32,), lambda i: a0[i])
b = te.compute((b_i64,), lambda i: a[i % 2])
When we fuse a
(denoted by operation_
in the comment) into b
, the variable i
(which is i32) in the computation of a
is replaced by i % 2
(which is i64) in b
. Since the original indexing variable i
in a
is i32, we need to cast i % 2
from i64 to i32.
By the comment, I mean i % 2
must fit in i32, because the tensor it indexes into (a
) has a shape of i32.
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 see, it makes sense that we need to cast to the original indexing type of the operator being fused into. Why though can we "safely cast the indices without worrying about overflow"? Isn't it still possible to overflow given a sufficiently large index?
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 are right. The comment is a bit misleading. I think I can change it to 'cast indices to the type of the original indexing variable'
@jwfromm please take another look and approve explicitly if everything looks good to you. |
LGTM |
* fix * resolve comments
* fix * resolve comments
* fix * resolve comments
* fix * resolve comments
Fix i64 indices issues. Tests are taken from #5219.