Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Clang's CUDA compiler?

Tags:

c++

cuda

clang++

I am on Ubuntu 17.10. I installed the CUDA 9.1 SDK from NVIDIA.

This is what I tried:

~/GrinGoldMiner/src/Cudacka$ clang++-5.0 -Wl,--cuda-path=/usr/local/cuda-9.1 kernel.cu
clang: error: cannot find libdevice for sm_20. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.
clang: error: cannot find CUDA installation.  Provide its path via --cuda-path, or pass -nocudainc to build without CUDA includes.
clang: error: cannot find CUDA installation.  Provide its path via --cuda-path, or pass -nocudainc to build without CUDA includes.

Obviously it doesn't work. It seems like the linker flags are not getting passed. How can I pass them correctly?

like image 340
Janus Troelsen Avatar asked Apr 11 '18 16:04

Janus Troelsen


1 Answers

It seems clang++-5.0 does not support CUDA 9.X ...

clang++ is able to compile CUDA kernels with CUDA 8.0:

$ clang++-5.0 -O0 -g --cuda-gpu-arch=sm_50 --cuda-path=/usr/local/cuda-8.0 -o t1 t1.cu -L/usr/local/cuda-8.0/lib64 -lcudart

But when using CUDA 9.X I get the same error as you:

$ clang++-5.0 --cuda-gpu-arch=sm_50 --cuda-path=/usr/local/cuda-9.0 -o t1 t1.cu -L/usr/local/cuda-9.0/lib64 -lcudart
clang: error: cannot find libdevice for sm_50. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.

They added support for Volta (sm_70) and CUDA 9.0 in this commit: 6d4cb40. In 2017, this was only available on master branch, and you would have confirmed it like this:

$ git clone https://github.com/llvm-mirror/clang.git 
$ cd clang/ 
$ git branch --contains 6d4cb40
* master

$ git checkout release_50
Branch release_50 set up to track remote branch release_50 from origin.
Switched to a new branch 'release_50'
$ git log | grep 6d4cb40
$ (output was empty)

Note that clang (7.0.0, released September 2018) supports CUDA 7.0 through 9.2.

like image 173
Hopobcn Avatar answered Oct 05 '22 21:10

Hopobcn