老卫带你学---cuda多版本切换

参考文章:
https://blog.csdn.net/maple2014/article/details/78574275/
https://blog.csdn.net/weixin_32820767/article/details/80421913

在我们gpu运算中,cuda的作用非常关键,但是有的时候我们需要特定的cuda版本,比如老卫在研究tensorflow的过程中发现,直接pip install tensorflow-gpu的版本仅支持cuda-9.0/cuda-10.0,不支持老卫的cuda-9.1。那么我们就需要在同一台机子上安装多个版本的cuda。(本教程是在cuda9.1的情况下安装cuda9.0)

机器环境:

ubuntu18.04+Gtx1070ti

1.下载并安装cuda

下载不用说,自己去nvidia官网去下载自己需要的版本。
接下来主要说下安装,因为要与之前的版本共存,所以有些步骤要注意

  • `chmod 777 cuda_9.0.103_384.59_linux.run 给其运行权限
  • `./cuda_9.0.176_384.81_linux.run 运行安装文件
    在安装的过程中的一些选项:
Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n  #如果在这之前已经安装好更高版本的显卡驱动就不需要再重复安装,如果需要重复安装就选择 yes,此外还需要关闭图形界面。

Do you wish to run the installation with 'sudo'?
(y)es/(n)o: y

Please enter your password: 
Do you want to install the OpenGL libraries?
(y)es/(n)o/(q)uit [ default is yes ]: 

Do you want to run nvidia-xconfig?
This will update the system X configuration file so that the NVIDIA X driver
is used. The pre-existing X configuration file will be backed up.
This option should not be used on systems that require a custom
X configuration, such as systems with multiple GPU vendors.
(y)es/(n)o/(q)uit [ default is no ]:  

Install the CUDA 9.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-9.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: n 

Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: n 
2.切换版本

安装完成后可以在 /usr/local 目录下看到:
cuda-9.1 # 笔者之前安装的cuda-9.1
cuda-9.0 # 刚刚安装的cuda-9.0

打开~/.bashrc文件 gedit ~/.bashrc文件
修改配置文件:

export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
export LIBRARY_PATH="/usr/local/cuda/lib64:$LIBRARY_PATH"

配置文件生效: source ~/.bashrc

然后就可以切换9.1与 9.0了:

rm –rf /usr/local/cuda  #删除原来的软链接
mkdir  /usr/local/cuda 
ln -s /usr/local/cuda-9.0 /usr/local/cuda #创建新的cuda9.0的软链接

此时切换完成,可以通过nvcc --version 来查看当前cuda的版本号

请多多支持老卫的文章,点击左上角的关注,给老卫点个赞!
欢迎交流,互相学习

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值