如何使用 Clang 的 CUDA 编译器?

Jan*_*sen 5 c++ cuda clang++

我在 Ubuntu 17.10 上。我安装了 NVIDIA 的 CUDA 9.1 SDK。

这是我尝试过的:

~/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.
Run Code Online (Sandbox Code Playgroud)

显然这是行不通的。似乎链接器标志没有通过。我怎样才能正确地传递它们?

Hop*_*bcn 7

好像clang++-5.0不支持CUDA 9.X ...

clang++ 能够使用 CUDA 8.0 编译 CUDA 内核:

$ 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
Run Code Online (Sandbox Code Playgroud)

但是在使用 CUDA 9.XI 时会得到和你一样的错误:

$ 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.
Run Code Online (Sandbox Code Playgroud)

他们在此提交中添加了对 Volta (sm_70) 和 CUDA 9.0 的支持:6d4cb40。在 2017 年,这仅在master分支上可用,您会像这样确认它:

$ 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)
Run Code Online (Sandbox Code Playgroud)

请注意,clang(7.0.0,2018 年 9 月发布)支持 CUDA 7.0 到 9.2。