Uh oh!
There was an error while loading. Please reload this page.
[Bug] narrow thread extents to 32 bits for GPU lowering - #10969
Conversation
| """ | ||
| if isinstance(shape, Constant): | ||
| shape = list(shape.data.numpy()) | ||
| shape = [int(i) for i in shape.data.numpy()] |
There was a problem hiding this comment.
Because tvm.runtime.convert handles all integer types as int32, would this cause issues with arrays larger than 4 GB? I don't think we have many of those in practice, but I think it could then cause a similar issue.
There was a problem hiding this comment.
It's possible, although the default handler for a python list of ints would hit the same problem. In either case, I'll push a proper fix for the reduction schedule on CUDA (forcibly cast the extent to int32, since that's needed for CUDA anyway if I understand correctly).
Do you think I should wrap ints using numpy int64 to avoid this problem? I'm slightly worried it will break assumptions elsewhere.
There was a problem hiding this comment.
I guess one possible option is to change the behavior tvm.runtime.convert to check for overflow and use int64 when necessary
Lunderberg
left a comment
There was a problem hiding this comment.
LGTM!
I like the verification that the size will fit in an int32.I could imagine edge cases, such as a user declaring an dynamically-sized input buffer with int64 size, then using a schedule that chooses the number of threads based on that size. However, that feels like enough of an edge case that it isn't worth replacing CanProveLess with !CanProveGreaterEqual.
altanh
commented
Apr 12, 2022
OK, IMHO, the difference between this fix and #10983 is that:
|
altanh
commented
Apr 12, 2022
interesting, I'm confused how it does the cast when the IterVar is int32 but the extent is int64 (since then |
altanh
commented
Apr 12, 2022
Yep I think we're solving the same problem haha |
ganler
commented
Apr 12, 2022
Very great point and this is where I think your PR is better than mine as I simply assume that extend.dtype.bits <= var.dtype.bits. |
But I am not sure if |
altanh
commented
Apr 12, 2022
yeah I see those tests failures now... my operating assumption is that for the |
If that's the case, probably we should just force the thread index to be int32. i.e., removing CanProveLess. Or let's just use int64 and let the compiler complain about larger-than-int32 extends? |
altanh
commented
Apr 12, 2022
let me try just removing the CanProveLess and see if it can pass CI |
altanh
commented
Apr 12, 2022
@ganler it seems like I'm breaking some assumptions elsewhere with this change- some unit tests seem to want the thread extents to explicitly be int64. Maybe we should just go with your change if you're happy with it |
ganler
commented
Apr 12, 2022
altanh
commented
Apr 12, 2022
I'll close this PR once yours passes CI, thx for tracking down the other relevant PRs! |
Lunderberg
commented
Apr 13, 2022
I'm fine with either fix as well, and thank you for tracking it down! |
Occasionally, int64 constants get piped through lowering and end up as thread extents, which can cause a dtype mismatch with the thread IterVar (which should be int32 on GPU). This PR narrows extents to int32 for GPU lowering to avoid the mismatch.
I added a test case for a small
broadcast_to -> sumprogram that fails to compile before this fix.cc @Lunderberg@mbrookhart