[PATCH] D94884: [Clang][OpenMP] Include header for CUDA builtin vars into OpenMP wrapper header

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 17 11:50:58 PST 2021


tianshilei1992 created this revision.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Current OpenMP wrapper header `__clang_openmp_device_functions.h`
doesn't include the header for CUDA builtin vars, so variable like `threadIdx`
cannot be used in OpenMP code, even within `declare target`.

This patch includes the header. One thing left is, is it fine that we still use
the name `__clang_openmp_device_functions.h`? Those builtin vars seems like not
part of "device functions".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94884

Files:
  clang/lib/Headers/__clang_cuda_builtin_vars.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h


Index: clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
===================================================================
--- clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
+++ clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
@@ -30,6 +30,9 @@
 /// Provide definitions for these functions.
 #include <__clang_cuda_device_functions.h>
 
+/// Provide definition for CUDA builtin variables
+#include <__clang_cuda_builtin_vars.h>
+
 #undef __OPENMP_NVPTX__
 #undef __CUDA__
 
Index: clang/lib/Headers/__clang_cuda_builtin_vars.h
===================================================================
--- clang/lib/Headers/__clang_cuda_builtin_vars.h
+++ clang/lib/Headers/__clang_cuda_builtin_vars.h
@@ -101,8 +101,12 @@
   __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_gridDim_t);
 };
 
+#ifdef __OPENMP_NVPTX__
+#define __CUDA_BUILTIN_VAR extern const __attribute__((weak))
+#else
 #define __CUDA_BUILTIN_VAR                                                     \
   extern const __attribute__((device)) __attribute__((weak))
+#endif
 __CUDA_BUILTIN_VAR __cuda_builtin_threadIdx_t threadIdx;
 __CUDA_BUILTIN_VAR __cuda_builtin_blockIdx_t blockIdx;
 __CUDA_BUILTIN_VAR __cuda_builtin_blockDim_t blockDim;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94884.317239.patch
Type: text/x-patch
Size: 1263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210117/371e1e7d/attachment.bin>


More information about the cfe-commits mailing list