Give DLDeviceType a sentinel value
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 169
- PR merge metrics
- No merged PRs in 30d
Description
The [`DLDeviceType` enum](https://github.com/dmlc/dlpack/blob/v0.7/include/dlpack/dlpack.h#L44-L92) enumerates the list of device types.
The TVM project defines another enumeration, `TVMDeviceExtType`, that provides a _supplemental set_ of devices / enumerators. It's important that there's no overlap of the integers provided by `DLDeviceType` and `TVMDeviceExtType`.
Unfortunately there's currently no good mechanism to notice when changes to either project lead to both using the same integer value in those enumerations.
We could address this by adding a sentinel value to `DLDeviceType`, e.g.:
``` c++
typedef enum {
kDLDeviceType_Begin = 1,
kDLCPU = kDLDeviceType_Begin,
...
kDLWebGPU = 15,
/*! \brief Qualcomm Hexagon DSP */
kDLHexagon = 16,
kDLDeviceType_End, // all DLDeviceType enumerators are guaranteed to be numerically lower than this integer
} DLDeviceType;
```
With this in place, TVM could safely avoid problems using something like this:
``` c++
typedef enum {
kDLAOCL = kDLDeviceType_End,
kDLSDAccel,
kOpenGL,
kDLMicroDev,
kDLWebGPU,
// AddExtraTVMType which is not in DLPack here
} TVMDeviceExtType;
```
or this:
``` c++
typedef enum {
kDLAOCL = ...,
...
} TVMDeviceExtType;
// Relies on kDLAOCL having the lowest integer value in TVMDeviceExtType.
static_assert(KDLAOCL > kDLEnumEnd);
``
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.