[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)
Krzysztof Parzyszek via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 27 11:23:40 PDT 2024
kparzysz wrote:
> Yeah I was actually wondering if I should go for something like this:
>
> ```c
> #ifdef __NVPTX__
> uint32_t nvptx_get_thread_id_x() { return __nvvm_ptx_read_sreg_tid_x(); }
> #define IMPL nvptx
> #endif
> uint32_t gpu_get_thread_id_x() { return ##IMPL##_get_thread_id_x(); }
> #undef IMPL
> ```
You could put all the common prototypes in the common include, e.g.
```
inline uint32_t gpu_get_thread_id_x() { return __impl_gpu_get_thread_id_x(); }
```
Then each arch-specific header would define the "impl" versions:
```
inline uint32_t __impl_gpu_get_thread_id_x() { return __nvvm_ptx_read_sreg_tid_x(); }
```
This way the common intrinsics would be defined in a single location, and it would be harder for someone to add a new intrinsic without realizing that all files should implement a common interface.
https://github.com/llvm/llvm-project/pull/110179
More information about the cfe-commits
mailing list