为 nvcc 设置默认主机编译器 [英] Set default host compiler for nvcc

查看:30
本文介绍了为 nvcc 设置默认主机编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在新的 GPU 服务器上安装了 Debian Stretch (9) 和 Cuda 8.Stretch 不附带旧版本的 gcc,所以我需要使用 clang 作为宿主编译器(nvcc 不支持 gcc-6).我可以通过以下方式调用 nvcc:

I have just installed Debian Stretch (9) and Cuda 8 on a new GPU server. Stretch does not come with older versions of gcc, so I need to use clang as the host compiler (nvcc does not support gcc-6). I can do this invoking nvcc as:

nvcc -ccbin clang-3.8

有什么方法可以在整个系统范围内实现 - 例如在 cuda 配置或环境变量中?

Is there any way to acheive this system wide - e.g. in cuda config or an environment variable?

推荐答案

nvcc的文档没有列出任何改变ccbin的env变量,只有选项:

Documentation of nvcc does not list any env variable to change ccbin, only the option:

http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html

--compiler-bindir directory, -ccbin 指定编译器可执行文件所在的目录.还可以指定宿主编译器的可执行文件名,以确保选择正确的宿主编译器.

--compiler-bindir directory, -ccbin Specify the directory in which the compiler executable resides. The host compiler executable name can be also specified to ensure that the correct host compiler is selected.

Linux 指南也没有这样的信息:http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

Linux guide have no such info too: http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

您可以尝试创建一些 nvcc 包装脚本并将其放在 PATH env var 中,例如:

You may try creating some nvcc wrapper script and putting it earlier in the PATH env var like:

mkdir ~/supernvcc
echo '#!/bin/sh' > ~/supernvcc/nvcc
echo `which nvcc` -ccbin clang-3.8 '$@' >> ~/supernvcc/nvcc
chmod +x ~/supernvcc/nvcc
export PATH=/home/`id -un`/supernvcc:$PATH

(在使用 nvcc 或将其添加到您的 .bashrc 或其他 shell 初始化脚本之前,在每个新 shell 中重复最后一行 export)

(repeat last line with export in every new shell before using nvcc or add it to your .bashrc or other shell init script)

PS:nvcc 也是 bash 脚本,你可以复制它并编辑它:

PS: and nvcc is bash script too, you can just copy it and edit:

cat `which nvcc`

更新:人们建议将正确的 gcc 版本链接到内部目录 /usr/local/cuda/bin/cuda的:

UPDATE: People recommend to link correct gcc version to the internal dir /usr/local/cuda/bin/ of cuda:

  sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc

这篇关于为 nvcc 设置默认主机编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆