Search code examples
cudaclangnvidiamacos-sierra

"make" command is using wrong clang compiler (to compile CUDA samples) - how to fix this?


I am on MacOS Sierra 10.12.4 and trying to make CUDA 8.0 work on my MacBook Pro (Late 2013) with the CUDA compatible NVIDIA GeForce GT 750M.

I followed the NVIDIA installation guide and installed Xcode 8.2 and the corresponding command line tools, but when I try to compile the samples I get the following error:

$ make -C 1_Utilities/deviceQuery

/Developer/NVIDIA/CUDA-8.0/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_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o deviceQuery.o -c deviceQuery.cpp
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
nvcc fatal : The version ('30900') of the host compiler ('clang') is not supported
make: *** [deviceQuery.o] Error 1

Here is I think what the problem is:
the "make" command is using the wrong clang, but I don't know how to change/fix this.

Here you can see the two versions of clang, that are on my machine:

$ clang --version

clang version 3.9.0 (tags/RELEASE_390/final)
Target: x86_64-apple-darwin16.5.0 Thread model: posix
InstalledDir: /opt/local/libexec/llvm-3.9/bin

$ /usr/bin/clang --version

Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.5.0
Thread model: posix InstalledDir: /Applications/Xcode_8.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

How can I make the "make" command use the correct clang version in the folder /usr/bin/clang by default?

Or is there a way to tell the "make" command to use the clang version in the folder /usr/bin/clang explicitly by adding some parameters/tags?

Here is also how my ~/.bash_profile looks like if that helps:

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

# MacPorts Installer addition on 2016-09-26_at_12:06:30: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

# colorful terminal
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'

# CUDA
export PATH=/Developer/NVIDIA/CUDA-8.0.61/bin${PATH:+:${PATH}}
export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-8.0.61/lib\
                         ${DYLD_LIBRARY_PATH:+:${DYLD_LIBRARY_PATH}}

Solution

  • By make -n as a dry run, you can see the real command behind make. Since I don't have a nvidia based mac, I'll show you the linux version as an example:

    "/usr/local/cuda-8.0"/bin/nvcc -ccbin g++ -I../../common/inc  -m64    -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_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o deviceQuery.o -c deviceQuery.cpp
    "/usr/local/cuda-8.0"/bin/nvcc -ccbin g++   -m64      -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_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o deviceQuery deviceQuery.o
    mkdir -p ../../bin/x86_64/linux/release
    cp deviceQuery ../../bin/x86_64/linux/release
    

    You can see that -ccbin (or --compiler-bindir) is the actual argument to set host compiler. Also nvcc --help will tell you about this argument.

    Then you can either run nvcc manually or try to make some changes in the Makefile.

    If changing the Makefile, you can easily find there is a HOST_COMPILER variable to set. And the darwin version part is like this:

    ifeq ($(TARGET_OS),darwin)
        ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
            HOST_COMPILER ?= clang++
        endif
    

    I guess you can just change it to your own clang path.