-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[DLPack][runtime] Update DLPack to v0.7 #13177
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
Conversation
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment. Generated by tvm-bot |
a0a48fd to
fa9cc08
Compare
kparzysz-quic
left a comment
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.
Cool! Thanks.
fa9cc08 to
90ed6f8
Compare
6aac36f to
ebf0cde
Compare
|
@tvm-bot rerun |
0ce1349 to
3914140
Compare
5267bbc to
965a51d
Compare
|
@tvm-bot rerun |
|
FYI CC: @Lunderberg @csullivan |
csullivan
left a comment
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.
Many thanks @cconvey! Providing one suggestion that could help for future maintenance.
| kDLCPU = 1 | ||
| kDLCUDA = 2 | ||
| kDLCUDAHost = 3 | ||
| kDLOpenCL = 4 | ||
| kDLVulkan = 7 | ||
| kDLMetal = 8 | ||
| kDLVPI = 9 | ||
| kDLROCM = 10 | ||
| kDLROCMHost = 11 | ||
| kDLExtDev = 12 | ||
| kDLCUDAManaged = 13 | ||
| kDLOneAPI = 14 | ||
| kDLWebGPU = 15 | ||
| kDLHexagon = 16 | ||
| kDLAOCL = 32 | ||
| kDLSDAccel = 33 | ||
| kOpenGL = 34 | ||
| kDLMicroDev = 35 | ||
|
|
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.
Is there a way for us to initialize these from there corresponding DLDeviceType and TVMDeviceExtType enums potentially via a packed function call?
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.
Is there a way for us to initialize these from there corresponding DLDeviceType and TVMDeviceExtType enums potentially via a packed function call?
I definitely considered that idea. The main goal of the PR is to upgrade DLPack, and I felt a significant reworking of how these constants are handled belonged in a separate PR.
| * meant to work as C code. So the unspecified storage type | ||
| * could be a latent bug when compiled as C. |
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.
What "unspecified" storage type is being referred to here? I didn't understand this comment and therefore couldn't gauge its severity given the reliance of the TVM C-runtime on this header.
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.
Sorry that the comment wasn't clear!
The two header files in question, dlpack.h and include/tvm/runtime/c_runtime_api.h, are meant to be valid C as well as valid C++.
When compiled as C++, these header files force the DLDeviceType and TVMDeviceExtType enums to use int32_t as the underlying storage type. (See here and here).
This ensures that any variable of type DLDeviceType or TVMDeviceExtType is capable of storing any of the values from those two enumerations. (And, fortunately, any of the additional values that TVM assumes it can store there, such as 0 and -1.)
But when those headers are compiled as C code, those enum declarations don't have that int32_t specifier. IIUC, C11 (the newest standard version of C, I think) has no such mechanism for specifying the size of an enum.
I believe this means the compiler is permitted to pick any underlying storage type for DLDeviceType vs. TVMDeviceExtType that can accommodate the enums' respective values. So, for example, int8_t for one, uint32_t for the other.
Practically speaking, we'd expect the compiler(s) to pick the same storage type for both DLDeviceType and TVMDeviceExtType, because currently they both have only non-negative integers pretty close to 0. But the compiler could, in principle, use one underlying storage type when compiling DLPack, and another when compiling TVM, possibly leading to an ABI mismatch. So this is the latent bug to which I referred.
Another consideration is that TVM has code that assumes variables of (one of) these types can store the value -1. I think this is undefined behavior, and could potentially cause problems with code that compares / tests the values of these variables.
| static final int kDLCPU = 1, kDLCUDA = 2, kDLCUDAHost = 3, kDLOpenCL = 4, kDLVulkan = 7, | ||
| kDLMetal = 8, kDLVPI = 9, kDLROCM = 10, kDLROCMHost = 11, kDLExtDev = 12, | ||
| kDLCUDAManaged = 13, kDLOneAPI = 14, kDLWebGPU = 15, kDLHexagon = 16, | ||
| kDLAOCL = 32, kDLSDAccel = 33, kOpenGL = 34, kDLMicroDev = 35; | ||
|
|
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 we initialize these with a backed function call? If we have to hard code it somewhere, better to do it in one place than in many places and make an FFI call to lookup the values.
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 completely agree that TVM should have some mechanism to let these integers be defined in only one place. I think a proper solution would require some discussion, so I'd prefer to treat that as outside the scope of this PR.
- Update the `3rdparty/dlpack` git submodule from v0.5 to v0.7, so that the `DLDeviceType` enumeration has an explicitly-stated underlying storage type. This addresses a compiler warning generated by clang 15.0.3. - Remove `kDLHexagon` and `kDLWebGPU` from `TVMDeviceExtType`, because those enumerators are now provided by `DLDeviceType`. - Renumber the members of `TVMDeviceExtType` to reduce the chance of unnoticed collision with members of `DLDeviceType`.
965a51d to
3c9443b
Compare
|
@tvm-bot rerun |
|
It's great to have DLPack updated, thank you for working through the issues @cconvey! This is now merged. |
- Update the `3rdparty/dlpack` git submodule from v0.5 to v0.7, so that the `DLDeviceType` enumeration has an explicitly-stated underlying storage type. This addresses a compiler warning generated by clang 15.0.3. - Remove `kDLHexagon` and `kDLWebGPU` from `TVMDeviceExtType`, because those enumerators are now provided by `DLDeviceType`. - Renumber the members of `TVMDeviceExtType` to reduce the chance of unnoticed collision with members of `DLDeviceType`.
- Update the `3rdparty/dlpack` git submodule from v0.5 to v0.7, so that the `DLDeviceType` enumeration has an explicitly-stated underlying storage type. This addresses a compiler warning generated by clang 15.0.3. - Remove `kDLHexagon` and `kDLWebGPU` from `TVMDeviceExtType`, because those enumerators are now provided by `DLDeviceType`. - Renumber the members of `TVMDeviceExtType` to reduce the chance of unnoticed collision with members of `DLDeviceType`.
[DLPack][runtime] Update DLPack to v0.7
Update the
3rdparty/dlpackgit submodule from v0.5 to v0.7, so that theDLDeviceTypeenumeration has an explicitly-stated underlying storage type. This addresses a compiler warning generated by clang 15.0.3.Remove
kDLHexagonandkDLWebGPUfromTVMDeviceExtType, because those enumerators are now provided byDLDeviceType.Renumber the members of
TVMDeviceExtTypeto reduce the chance of unnoticed collision with members ofDLDeviceType.