Caffe 安装:如何使用 libc++ 而不是 clang 为 CUDA 供电? (Mac)

Caffe Installation: How to use libc++ instead of clang to power CUDA? (Mac)

我知道这样做很蠢,但我不得不这样做。因为目前 CUDA 7.0 在我使用 Xcode 7 beta 时不支持 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

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

我遇到了同样的问题。您可以通过从 Apple 的 Developer Download Center 下载旧版本,将其与 Xcode 7 一起安装,而不是回滚到 Xcode 6。给它起一个不同于 Xcode 7 的名字(例如叫它 "Xcode 6.4"),他们可以毫无问题地生活在一起。

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

我遇到了同样的问题,我猜会有更多问题,因为 Xcode 7.0 现已在 App Store 上可用,本来打算评论 Jay 的,但我没有足够的声誉。
您可以做的不是下载整个 5gb Xcode 6.x,而是检查

下的 Xcode

设置 > 位置 > 命令行工具

如果有使用 6.4 的选项,请切换到那个。如果没有,请安装 JUST 命令行工具 6.4 here 然后该选项应该可用。
他发布作品的方式也是如此,但是您的计算机上需要两个版本的 Xcode。

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 : The version ('30800') of the host compiler ('clang') is not supported

这意味着...?

> 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

是啊!
nvcc 使用 clang version 7.0.0 编译。

这样,

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

不需要

小心。

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

仅供参考

我的要点文章,
gist - How to compiling use CUDA nvcc with Xcode7.0 clang 7.0.0