You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/10/23 21:50:16 UTC
[GitHub] [tvm] cconvey opened a new pull request, #13177: [DLPack] Update DLPack to v0.7
cconvey opened a new pull request, #13177:
URL: https://github.com/apache/tvm/pull/13177
[DLPack] 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`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on PR #13177:
URL: https://github.com/apache/tvm/pull/13177#issuecomment-1297236999
FYI CC: @Lunderberg @csullivan
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on pull request #13177: [DLPack] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on PR #13177:
URL: https://github.com/apache/tvm/pull/13177#issuecomment-1288209154
CC: @areusch @tqchen @kparzysz-quic
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] csullivan commented on a diff in pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
csullivan commented on code in PR #13177:
URL: https://github.com/apache/tvm/pull/13177#discussion_r1009568249
##########
python/tvm/_ffi/runtime_ctypes.py:
##########
@@ -195,44 +195,73 @@ class Device(ctypes.Structure):
OpenCL. Some properties may return None depending on whether an
API exposes that particular property.
+ NOTE! The integer values in MASK2STR and STR2MASK *must* correspond
+ to the values provided by the DLDeviceType and TVMDeviceExtType enums.
"""
+ 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
+
Review Comment:
Is there a way for us to initialize these from there corresponding DLDeviceType and TVMDeviceExtType enums potentially via a packed function call?
##########
include/tvm/runtime/c_runtime_api.h:
##########
@@ -80,17 +80,74 @@ extern "C" {
/*! \brief type of array index. */
typedef int64_t tvm_index_t;
-/*! \brief Extension device types in TVM */
+/*! \brief Extension device types in TVM
+ *
+ * Additional enumerators to supplement those provided by
+ * DLPack's `DLDeviceType` enumeration.
+ *
+ * MAINTAINERS NOTE #1: We need to ensure that the two devices
+ * are identified by the same integer.
+ * Currently this requires manual verification.
+ * Discussed here: https://github.com/dmlc/dlpack/issues/111
+ * As of DLPack v0.7, the highest-valued enumerator in
+ * `DLDeviceType` is kDLHexagon = 16.
+ *
+ * MAINTAINERS NOTE #2: As of DLPack v0.7, the definition for
+ * `DLDeviceType` specifies an underlying storage type of
+ * `int32_t`. That guarantees a variable of type
+ * `DLDeviceType` is capable of holding any integers provided
+ * by *either* of these enumerations.
+ *
+ * However, the `int32_t` specification only applies when the
+ * header file is compiled as C++, and this header file is also
+ * meant to work as C code. So the unspecified storage type
+ * could be a latent bug when compiled as C.
Review Comment:
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.
##########
jvm/core/src/main/java/org/apache/tvm/Device.java:
##########
@@ -17,32 +17,40 @@
package org.apache.tvm;
-import org.apache.tvm.rpc.RPC;
-
import java.util.HashMap;
import java.util.Map;
+import org.apache.tvm.rpc.RPC;
public class Device {
+ /**
+ * Provides the same information as the C++ enums DLDeviceType and
+ * TVMDeviceExtType.
+ */
+ 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;
+
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on a diff in pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on code in PR #13177:
URL: https://github.com/apache/tvm/pull/13177#discussion_r1009828664
##########
python/tvm/_ffi/runtime_ctypes.py:
##########
@@ -195,44 +195,73 @@ class Device(ctypes.Structure):
OpenCL. Some properties may return None depending on whether an
API exposes that particular property.
+ NOTE! The integer values in MASK2STR and STR2MASK *must* correspond
+ to the values provided by the DLDeviceType and TVMDeviceExtType enums.
"""
+ 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
+
Review Comment:
> 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on PR #13177:
URL: https://github.com/apache/tvm/pull/13177#issuecomment-1297828016
@tvm-bot rerun
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] csullivan commented on pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
csullivan commented on PR #13177:
URL: https://github.com/apache/tvm/pull/13177#issuecomment-1298046449
It's great to have DLPack updated, thank you for working through the issues @cconvey! This is now merged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on a diff in pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on code in PR #13177:
URL: https://github.com/apache/tvm/pull/13177#discussion_r1009849007
##########
jvm/core/src/main/java/org/apache/tvm/Device.java:
##########
@@ -17,32 +17,40 @@
package org.apache.tvm;
-import org.apache.tvm.rpc.RPC;
-
import java.util.HashMap;
import java.util.Map;
+import org.apache.tvm.rpc.RPC;
public class Device {
+ /**
+ * Provides the same information as the C++ enums DLDeviceType and
+ * TVMDeviceExtType.
+ */
+ 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;
+
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] csullivan merged pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
csullivan merged PR #13177:
URL: https://github.com/apache/tvm/pull/13177
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on PR #13177:
URL: https://github.com/apache/tvm/pull/13177#issuecomment-1296389175
@tvm-bot rerun
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tvm-bot commented on pull request #13177: [DLPack] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
tvm-bot commented on PR #13177:
URL: https://github.com/apache/tvm/pull/13177#issuecomment-1288208791
<!---bot-comment-->
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](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
<!--bot-comment-ccs-start-->
* No users to tag found in teams: `dlpack` <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
<sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on PR #13177:
URL: https://github.com/apache/tvm/pull/13177#issuecomment-1289347163
@tvm-bot rerun
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] cconvey commented on a diff in pull request #13177: [DLPack][runtime] Update DLPack to v0.7
Posted by GitBox <gi...@apache.org>.
cconvey commented on code in PR #13177:
URL: https://github.com/apache/tvm/pull/13177#discussion_r1009848023
##########
include/tvm/runtime/c_runtime_api.h:
##########
@@ -80,17 +80,74 @@ extern "C" {
/*! \brief type of array index. */
typedef int64_t tvm_index_t;
-/*! \brief Extension device types in TVM */
+/*! \brief Extension device types in TVM
+ *
+ * Additional enumerators to supplement those provided by
+ * DLPack's `DLDeviceType` enumeration.
+ *
+ * MAINTAINERS NOTE #1: We need to ensure that the two devices
+ * are identified by the same integer.
+ * Currently this requires manual verification.
+ * Discussed here: https://github.com/dmlc/dlpack/issues/111
+ * As of DLPack v0.7, the highest-valued enumerator in
+ * `DLDeviceType` is kDLHexagon = 16.
+ *
+ * MAINTAINERS NOTE #2: As of DLPack v0.7, the definition for
+ * `DLDeviceType` specifies an underlying storage type of
+ * `int32_t`. That guarantees a variable of type
+ * `DLDeviceType` is capable of holding any integers provided
+ * by *either* of these enumerations.
+ *
+ * However, the `int32_t` specification only applies when the
+ * header file is compiled as C++, and this header file is also
+ * meant to work as C code. So the unspecified storage type
+ * could be a latent bug when compiled as C.
Review Comment:
Sorry that the comment wasn't clear!
The two header files in question, [`dlpack.h`](https://github.com/dmlc/dlpack/blob/e2bdd3bee8cb6501558042633fa59144cc8b7f5f/include/dlpack/dlpack.h) and [`include/tvm/runtime/c_runtime_api.h`](https://github.com/apache/tvm/blob/965a51de0b6e515fe0d5a34fba3b8b1ebf69aeb4/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](https://github.com/dmlc/dlpack/blob/e2bdd3bee8cb6501558042633fa59144cc8b7f5f/include/dlpack/dlpack.h#L44-L48) and [here](https://github.com/apache/tvm/blob/965a51de0b6e515fe0d5a34fba3b8b1ebf69aeb4/include/tvm/runtime/c_runtime_api.h#L106-L110)).
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](https://stackoverflow.com/questions/4879286/specifying-size-of-enum-type-in-c).
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org