How to tell Clang which version of CUDA to use ?


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
#include <cuda.h>
#include <iostream>

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

$ clang++ -o main \
    --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:

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-
linux/include/device_functions.hpp:218:10: error: reference to
__device__ function '__nvvm_bar0_popc' in __host__ function
  return __nvvm_bar0_popc(predicate);
linux/include/device_functions.hpp:218:10: note: '__nvvm_bar0_popc'
declared here
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

[2] For reference, I compiled revision 311091 with the following

cmake -G "Unix Makefiles" \
    -D CMAKE_INSTALL_PREFIX=/home/jtastet/.local/stow/llvm_gcc-6.3 \
    -D CMAKE_BUILD_TYPE=Release \
centos7 \

--cuda-path is the right flag to pass. Strange it's not doing the
right thing for you.

Can you include the output of running the same command line with -v?

As a workaround, we have temporarily disabled the CUDA 9.0 install (by renaming its directory to /usr/local/_cuda-9.0). Now the program compiles as expected (I also recompiled Clang in the meantime).

As soon as I manage to convince my sysadmin to enable CUDA 9.0 again, I will retry with the -v command-line option and post the output here.

Sorry for the delayed response, just got back from vacation.

I just installed cuda 9 to /usr/local/cuda-9.0 and couldn't reproduce
this problem. I also tried redirecting /usr/local/cuda to
/usr/local/cuda-9.0 and passing an explicit
--cuda-path=/usr/local/cuda-8.0, and things still worked as expected.

Very strange what you're seeing, although I believe there's a decent
chance it's a bug in clang. Hopefully the -v output will be