DarkSharpness opened a new issue, #365:
URL: https://github.com/apache/tvm-ffi/issues/365

   Hi! As a downstream user of tvm-ffi, I was wondering whether it would make 
sense to provide some official support for mapping C++ types to DLDataType via 
type traits. For example, for native C++ types such as int32_t, we often want 
some association like: `DLDataType{.code = DLDataTypeCode::kDLInt, .bits = 32, 
.lanes = 1}`
   
   If a trait-based utility (e.g. `dtype_trait<T>`) were available, downstream 
code could perform type checks in a much more readable and idiomatic way:
   
   ```c++
   template <typename T>
   inline bool is_type(DLDataType dtype) {
     return dtype == dtype_trait<T>::value;
   }
   
   // usage
   if (is_type<int>(dtype)) {
     // do something
   }
   ```
   
   This would significantly improve code readability in downstream 
applications, and help avoid repetitive, error-prone direct manipulation of 
DLPack fields. We have implemented a small prototype along these lines in the 
[SGLang JIT 
kernel](https://github.com/sgl-project/sglang/blob/8087ef126f1e6a66e2e2f3f09d561e2efcd758d4/python/sglang/jit_kernel/include/sgl_kernel/tensor.h#L46-L73)
   I believe a similar utility upstream could also be useful in other helpers, 
such as #202.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to