Skip to content
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

[DLPack][runtime] Update DLPack to v0.7 #13177

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

cconvey
Copy link
Contributor

@cconvey cconvey commented Oct 23, 2022

[DLPack][runtime] Update DLPack to v0.7

  • 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.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 23, 2022

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

@cconvey
Copy link
Contributor Author

cconvey commented Oct 23, 2022

CC: @areusch @tqchen @kparzysz-quic

@cconvey cconvey changed the title [DLPack] Update DLPack to v0.7 [DLPack][runtime] Update DLPack to v0.7 Oct 23, 2022
Copy link
Contributor

@kparzysz-quic kparzysz-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Thanks.

@cconvey cconvey force-pushed the use-dlpack-v0.7 branch 2 times, most recently from 6aac36f to ebf0cde Compare October 24, 2022 13:43
@cconvey
Copy link
Contributor Author

cconvey commented Oct 24, 2022

@tvm-bot rerun

@cconvey cconvey force-pushed the use-dlpack-v0.7 branch 3 times, most recently from 0ce1349 to 3914140 Compare October 27, 2022 20:22
@cconvey cconvey force-pushed the use-dlpack-v0.7 branch 6 times, most recently from 5267bbc to 965a51d Compare October 30, 2022 19:05
@cconvey
Copy link
Contributor Author

cconvey commented Oct 31, 2022

@tvm-bot rerun

@cconvey
Copy link
Contributor Author

cconvey commented Oct 31, 2022

FYI CC: @Lunderberg @csullivan

Copy link
Contributor

@csullivan csullivan left a 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.

Comment on lines +202 to +220
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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +103 to +104
* meant to work as C code. So the unspecified storage type
* could be a latent bug when compiled as C.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +29 to +33
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;

Copy link
Contributor

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.

Copy link
Contributor Author

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`.
@cconvey
Copy link
Contributor Author

cconvey commented Oct 31, 2022

@tvm-bot rerun

@csullivan csullivan merged commit 9cdc97f into apache:main Nov 1, 2022
@csullivan
Copy link
Contributor

It's great to have DLPack updated, thank you for working through the issues @cconvey! This is now merged.

@cconvey cconvey deleted the use-dlpack-v0.7 branch November 1, 2022 14:08
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
- 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`.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
- 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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants