[cfe-dev] clang and CUDA problem

Edward Diener via cfe-dev cfe-dev at lists.llvm.org
Sat Oct 12 16:54:54 PDT 2019


At 
https://llvm.org/docs/CompileCudaWithLLVM.html#detecting-clang-vs-nvcc-from-code 
the clang doc tells me that when compiling a CUDA file with clang, 
whether in device or host mode, the predefined macros are __clang__ , 
__CUDA__ , and __CUDACC__ . Yet testing this with clang_cuda_example.cu as:

#if !defined(__clang__)
#if !defined(__CUDACC__)
#if !defined(__CUDA__)
#error The predefined macros __clang__ and __CUDACC__ and __CUDA__ are 
not defined
#else
#error The predefined macros __clang__ and __CUDACC__ are not defined
#endif
#elif !defined(__CUDA__)
#error The predefined macros __clang__ and __CUDA__ are not defined
#else
#error The predefined macro __clang__ is not defined
#endif
#elif !defined(__CUDACC__)
#if !defined(__CUDA__)
#error The predefined macros __CUDACC__ and __CUDA__ are not defined
#else
#error The predefined macro __CUDACC__ is not defined
#endif
#elif !defined(__CUDA__)
#error The predefined macro __CUDA__ is not defined
#endif
int main(void) { return 0; }

using the command line:

clang++ -c -m64 -nocudainc -nocudalib -x cuda clang_cuda_example.cu

the result is:

clang_cuda_example.cu:17:2: error: The predefined macro __CUDACC__ is 
not defined
#error The predefined macro __CUDACC__ is not defined
  ^
1 error generated when compiling for sm_20.

In other words the macro __CUDACC__ is not defined. Do I need to alter 
my example CUDA file so that __CUDACC__ is defined, and if so how ? I 
realize my CUDA file contain no CUDA code and does not include a CUDA 
header file, but the goal of the file, which has other purposes in 
actual testing, is to test that the predefined macros which the clang 
CUDA documentation says are defined when compiling a CUDA file are 
actually defined.





More information about the cfe-dev mailing list