【问题标题】:"make" command is using wrong clang compiler (to compile CUDA samples) - how to fix this?“make”命令使用了错误的 clang 编译器(编译 CUDA 示例) - 如何解决这个问题?
【发布时间】:2017-09-25 01:37:29
【问题描述】:

我正在使用 MacOS Sierra 10.12.4 并尝试使用 CUDA 兼容的 NVIDIA GeForce GT 750M 在我的 MacBook Pro(2013 年末)上运行 CUDA 8.0。

我按照NVIDIA installation guide 安装了Xcode 8.2 和相应的命令行工具,但是当我尝试编译示例时出现以下错误:

$ 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 警告:“compute_20”、“sm_20”和“sm_21”架构已弃用,可能会在未来的版本中删除(使用 -Wno-deprecated-gpu-targets 来抑制警告)。
nvcc致命:不支持主机编译器('clang')的版本('30900')
make: *** [deviceQuery.o] 错误 1

这是我认为的问题所在:
“make”命令使用了错误的 clang,但我不知道如何更改/修复它。

在这里你可以看到我机器上的两个版本的clang:

$ clang --version

clang 版本 3.9.0 (tags/RELEASE_390/final)
目标:x86_64-apple-darwin16.5.0 线程模型:posix
安装目录:/opt/local/libexec/llvm-3.9/bin

$ /usr/bin/clang --version

Apple LLVM 版本 8.0.0 (clang-800.0.42.1)
目标:x86_64-apple-darwin16.5.0
线程模型:posix 安装目录:/Applications/Xcode_8.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

如何让“make”命令默认使用文件夹 /usr/bin/clang 中正确的 clang 版本?

或者有没有办法通过添加一些参数/标签来告诉“make”命令显式使用文件夹/usr/bin/clang中的clang版本?

如果有帮助,这也是我的 ~/.bash_profile 的样子:

# 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}}

【问题讨论】:

    标签: cuda clang nvidia macos-sierra


    【解决方案1】:

    通过make -n作为试运行,你可以看到make背后的真实命令。由于我没有基于nvidia的mac,我以linux版本为例:

    "/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
    

    您可以看到-ccbin(或--compiler-bindir)是设置主机编译器的实际参数。 nvcc --help 也会告诉你这个论点。

    然后您可以手动运行nvcc 或尝试在Makefile 中进行一些更改。

    如果更改Makefile,您可以轻松找到要设置的HOST_COMPILER 变量。而darwin版本部分是这样的:

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

    我想你可以把它改成你自己的 clang 路径。

    【讨论】:

    • 非常感谢,将 make 文件中的 "clang++" 替换为 "/usr/bin/clang" 解决了这个问题 :)
    猜你喜欢
    • 2020-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2018-03-19
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多