Caffe安装:如何使用libc++代替clang来驱动CUDA?(Mac)



我知道这样做很愚蠢,但我必须这样做。因为目前CUDA 7.0在我使用Xcode 7测试版时不支持clang 7.0,我几乎不可能回滚到Xcode 6.0

NVCC src/caffe/layers/absval_layer.cu
nvcc fatal   : The version ('70000') of the host compiler ('Apple clang') is not supported
make: *** [.build_release/cuda/src/caffe/layers/absval_layer.o] Error 1

我也有同样的问题。而不是回滚到Xcode 6,你可以通过从苹果的开发者下载中心下载旧版本来安装Xcode 7。给它起一个不同于Xcode 7的名字(比如叫它"Xcode 6.4"),它们就可以共存了。

当你想用CUDA编译时,请确保你将Xcode首选项中的命令行工具设置为旧版本。

CUDA 7.0的文档说明对于Mac OS X Clang 6.0 (Xcode 6)是最新支持的版本。

nvcc实际情况

nvcc是从当前clang二进制版本解析的
例如,

> export
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/local/var/rbenv/shims:/sbin
> clang -v
clang version 3.8.0 (git@github.com:llvm-mirror/clang.git
1082a41a5196e0fdddf1af1aa388af197cfc4514) (git@github.com:llvm
mirror/llvm.git 60fe48f86639ab4472d186bc97e7676f269cae18)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
InstalledDir: /usr/local/bin
> make
/Developer/NVIDIA/CUDA-7.5/bin/nvcc -ccbin clang++ -I../../common/inc  -m64  -Xcompiler -arch -Xcompiler x86_64  -gencode arch=compute_20,code=sm_20 -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_52,code=compute_52 -o asyncAPI.o -c asyncAPI.cu
nvcc fatal   : The version ('30800') of the host compiler ('clang') is not supported
Makefile:229: recipe for target 'asyncAPI.o' failed
make: *** [asyncAPI.o] Error 1

nvcc fatal:不支持主机编译器('clang')的版本('30800')

这意味着…?

> export PATH=/Applications/Xcode-6.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/usr/local/bin:/usr/bin:/usr/sbin:/usr/local/var/rbenv/shims:/sbin
> CC=/usr/bin/clang CXX=/usr/bin/clang++ make
/Developer/NVIDIA/CUDA-7.5/bin/nvcc -ccbin clang++ -I../../common/inc  -m64  -Xcompiler -arch -Xcompiler x86_64  -gencode arch=compute_20,code=sm_20 -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_52,code=compute_52 -o asyncAPI.o -c asyncAPI.cu
/Developer/NVIDIA/CUDA-7.5/bin/nvcc -ccbin clang++   -m64  -Xcompiler -arch -Xcompiler x86_64  -Xlinker -rpath -Xlinker /Developer/NVIDIA/CUDA-7.5/lib  -gencode arch=compute_20,code=sm_20 -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_52,code=compute_52 -o asyncAPI asyncAPI.o
mkdir -p ../../bin/x86_64/darwin/release
cp asyncAPI ../../bin/x86_64/darwin/release

成功。
…然而,不知道实际上nvcc使用的是CXX的clang。

<标题> 解决方案

那么,让我们编辑clang二进制文件。

> cp /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang /tmp/clang
> cd /tmp
> vim ./clang
# or nvim, emacs, etc...
# Searching `700.1.75` and replace `602.0.53`.  
# In case of vim,
:%s/700.1.75/602.0.53/g
:wq
> export PATH=/tmp:/usr/local/bin:/usr/bin:/usr/sbin:/usr/local/var/rbenv/shims:/sbin
> wihch clang
/tmp/clang
> clang -v
Apple LLVM version 7.0.0 (clang-602.0.53)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
# Faking clang version 602.0.53 (Xcode 6.4's clang)
# but, Actual implementation clang 7.0.0
> make
/Developer/NVIDIA/CUDA-7.5/bin/nvcc -ccbin clang++ -I../../common/inc  -m64  -Xcompiler -arch -Xcompiler x86_64  -gencode arch=compute_20,code=sm_20 -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_52,code=compute_52 -o asyncAPI.o -c asyncAPI.cu
/Developer/NVIDIA/CUDA-7.5/bin/nvcc -ccbin clang++   -m64  -Xcompiler -arch -Xcompiler x86_64  -Xlinker -rpath -Xlinker /Developer/NVIDIA/CUDA-7.5/lib  -gencode arch=compute_20,code=sm_20 -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_52,code=compute_52 -o asyncAPI asyncAPI.o
mkdir -p ../../bin/x86_64/darwin/release
cp asyncAPI ../../bin/x86_64/darwin/release

Yeeeeees !
nvcc编译使用clang version 7.0.0

这样,

sudo xcode-select -s /Applications/Xcode-6.4.app/Contents/Developer

不是必需的。

<标题>小心。

现在,你的clang的遗体变成了/tmp/clang

<标题>供参考

我的主旨文章,
如何使用Xcode7.0 clang 7.0.0编译CUDA nvcc

我也有同样的问题,我猜更多的人会因为Xcode 7.0现在在App Store上可用,我本来想评论Jay的,但我没有足够的声誉。
你可以做什么,而不是下载整个5gb Xcode 6。x是在

下检查Xcode

设置>位置>命令行工具

如果有使用6.4的选项,就切换到它。如果没有,在这里安装JUST命令行工具6.4,然后该选项应该可用。
他发布的方式也很好,但是你需要在你的机器上安装两个版本的Xcode

最新更新