如何使用 Clang 的 CUDA 编译器?
How to use Clang's CUDA compiler?
我在 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.
显然是行不通的。似乎链接器标志没有通过。我怎样才能正确传递它们?
我试图在 Ubuntu 17.10 下构建 GrinGoldMiner 的 Cudacka,我所要做的就是:
make
这在我的机器上生成了两个命令(经过一些清理后):
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o cudacka.o -c kernel.cu
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o Cudacka.exe cudacka.o
他们成功生成了可执行文件 Cudacka.exe
。
如果您对 clang 特别感兴趣:
当我尝试将 g++
替换为 clang++-5.0
时,出现此错误:
nvcc fatal : The version ('50000') of the host compiler ('clang') is not supported
如果我使用 -std=c++11 -ccbin clang++
而不是 -ccbin g++
,我会得到这个错误:
kernel.cu(397): error: explicit instantiation definition directive for __global__ functions with clang host compiler is not yet supported
因此,我怀疑您是否可以使用 clang 为 Ubuntu 编译该代码。
好像clang++-5.0
不支持CUDA9.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
但是在使用 CUDA 时 9.X 我得到了和你一样的错误:
$ 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.
他们在此提交中添加了对 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)
请注意,clang(7.0.0,2018 年 9 月发布)支持 CUDA 7.0 到 9.2。
我在 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.
显然是行不通的。似乎链接器标志没有通过。我怎样才能正确传递它们?
我试图在 Ubuntu 17.10 下构建 GrinGoldMiner 的 Cudacka,我所要做的就是:
make
这在我的机器上生成了两个命令(经过一些清理后):
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o cudacka.o -c kernel.cu
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o Cudacka.exe cudacka.o
他们成功生成了可执行文件 Cudacka.exe
。
如果您对 clang 特别感兴趣:
当我尝试将 g++
替换为 clang++-5.0
时,出现此错误:
nvcc fatal : The version ('50000') of the host compiler ('clang') is not supported
如果我使用 -std=c++11 -ccbin clang++
而不是 -ccbin g++
,我会得到这个错误:
kernel.cu(397): error: explicit instantiation definition directive for __global__ functions with clang host compiler is not yet supported
因此,我怀疑您是否可以使用 clang 为 Ubuntu 编译该代码。
好像clang++-5.0
不支持CUDA9.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
但是在使用 CUDA 时 9.X 我得到了和你一样的错误:
$ 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.
他们在此提交中添加了对 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)
请注意,clang(7.0.0,2018 年 9 月发布)支持 CUDA 7.0 到 9.2。