Skip to content

Instantly share code, notes, and snippets.

@zchee
Last active August 15, 2017 23:51
Show Gist options
  • Save zchee/7833bf67013e83523181 to your computer and use it in GitHub Desktop.
Save zchee/7833bf67013e83523181 to your computer and use it in GitHub Desktop.
How to compiling use CUDA nvcc with Xcode7.0 clang 7.0.0

CUDA7.5

Now, CUDA did not compatible Apple clang 7.0.0 also Xcode7.0.

e.g,

> cd /Developer/NVIDIA/CUDA-7.5/samples/0_Simple/asyncAPI

> clang -v
Apple LLVM version 7.0.0 (clang-700.1.75)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

> 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 ('70000') of the host compiler ('Apple clang') is not supported
Makefile:229: recipe for target 'asyncAPI.o' failed
make: *** [asyncAPI.o] Error 1

nvcc fatal : The version ('70000') of the host compiler ('Apple clang') is not supported

CUDA(nvcc) is parsed clang version.
but,

# Swich clang to version 602.0.53(based on LLVM 3.6.0svn) in Xcode 6.4
> 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

> 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

Successful make.

nvcc actual situation

nvcc is parsed version from a current clang binary.
e.g,

> export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/local/var/rbenv/shims:/sbin

> clang -v
# My /usr/local/bin/clang is LLVM clang
clang version 3.8.0 ([email protected]:llvm-mirror/clang.git 1082a41a5196e0fdddf1af1aa388af197cfc4514) ([email protected]: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

...
That means...?

> 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

Yes! Success!
...However, unknown actually what nvcc are using the clang of CXX.

Solution

So, Let's edit clang binary.

> 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

And,

> export PATH=/tmp:/usr/local/bin:/usr/bin:/usr/sbin:/usr/local/var/rbenv/shims:/sbin

> wihch clang
/tmp/clang

> clang -v
# Faking clang version 602.0.53 (Xcode 6.4's clang)
# but, Actual implementation clang 7.0.0
Apple LLVM version 7.0.0 (clang-602.0.53)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

> 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 compiled using clang version 7.0.0.

In this way, sudo xcode-select -s /Applications/Xcode-6.4.app/Contents/Developer is not required.
but, Your clang is remains became /tmp/clang. Be careful.
🎉

@Sentient07
Copy link

I do not have x-code installed. I just use command line tool. Could you help me with what to do then ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment