[cfe-users] How to tell Clang which version of CUDA to use ?

Jean-Loup Tastet via cfe-users cfe-users at lists.llvm.org
Fri Aug 18 03:55:34 PDT 2017


Hi,

I am trying to use Clang to compile CUDA device code. I followed the
instructions in [1] and compiled the latest Clang trunk [2].

However, my system has both CUDA 8.0 and 9.0 RC installed, in
`/usr/local/cuda-{8.0,9.0}`. The default `/usr/local/cuda` is symlinked
to `/usr/local/cuda-8.0`.

Clang only supports version 8.0, however it seems to incorrectly pick
version 9.0, even when manually specifying the `--cuda-path`. For
instance, trying to compile a trivial CUDA program (with no kernel):
```
$ cat main.cu
#include <cuda.h>
#include <iostream>

int main(int argc, char* argv[])
{
    std::cout << "Hello, World!" << std::endl;
}

$ clang++ -o main main.cu \
    --cuda-path=/usr/local/cuda-8.0 \
    -I/usr/local/cuda-8.0/include \
    -L/usr/local/cuda-8.0/lib64 \
    -lcudart_static -ldl -lrt -pthread
```
generates the following error:
```
/home/jtastet/.local/stow/llvm_gcc-
6.3/lib/clang/6.0.0/include/__clang_cuda_runtime_wrapper.h:66:2: error:
"Unsupported CUDA version!"
#error "Unsupported CUDA version!"
 ^
In file included from <built-in>:1:
In file included from /home/jtastet/.local/stow/llvm_gcc-
6.3/lib/clang/6.0.0/include/__clang_cuda_runtime_wrapper.h:169:
/usr/local/cuda-9.0/targets/x86_64-
linux/include/device_functions.hpp:218:10: error: reference to
__device__ function '__nvvm_bar0_popc' in __host__ function
  return __nvvm_bar0_popc(predicate);
         ^
/usr/local/cuda-9.0/targets/x86_64-
linux/include/device_functions.hpp:218:10: note: '__nvvm_bar0_popc'
declared here
/usr/local/cuda-9.0/targets/x86_64-
linux/include/device_functions.hpp:223:10: error: reference to
__device__ function '__nvvm_bar0_and' in __host__ function
  return __nvvm_bar0_and(predicate);
         ^
[...output truncated...]
```
Note the reference to CUDA 9.0 in the path.

Do you know how to tell Clang which version of CUDA to use ? Does it
have to be specified at compile-time or as a command-line option ?

Uninstalling CUDA 9.0 is not an option here, since I do not have
privileged access to the machine.

Thanks in advance for your help !

Best regards,
Jean-Loup Tastet


[1] https://llvm.org/docs/CompileCudaWithLLVM.html
[2] For reference, I compiled revision 311091 with the following
configuration:
```
cmake -G "Unix Makefiles" \
    -D CMAKE_INSTALL_PREFIX=/home/jtastet/.local/stow/llvm_gcc-6.3 \
    -D CMAKE_BUILD_TYPE=Release \
    -D GCC_INSTALL_PREFIX=/afs/cern.ch/sw/lcg/external/gcc/6.3/x86_64-
centos7 \
    ..
```



More information about the cfe-users mailing list