ubuntu系统安装11.6+版本的cuda
可以参考这两篇博客
ubuntu22.04多版本安装cuda及快速切换(cuda11.1和11.8)_ubuntu调整cuda版本
【Linux】在一台机器上同时安装多个版本的CUDA(切换CUDA版本)_linux安装多个cuda
安装CUDA
https://developer.nvidia.com/cuda-toolkit-archive
找到11.8版本的cuda
依次选择Linux x86_64 Ubuntu 22.04 runfile(local)
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.runsudo sh cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run
运行上述两个命令
用enter把Driver去掉勾选 然后用方向键移动到最下面的enter然后回车
选择no
出现这样说明cuda安装成功
我们暂时先不去修改环境变量,为了不影响现有的CUDA环境。之后会用脚本进行切换
安装cuDNN
https://developer.nvidia.com/rdp/cudnn-archive
从这里下载cuDNN
我们输入
cd /usr/local/
ls
现在有三个版本的cuda文件
我们将下载的cudnn解压到对应的文件夹下面并且赋予执行权限
sudo cp include/cudnn.h /usr/local/cuda-11.8/include
sudo cp lib/libcudnn* /usr/local/cuda-11.8/lib64
sudo chmod a+r /usr/local/cuda-11.8/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.8/lib64/libcudnn*
切换CUDA版本
我们使用以下命令在/usr/local/ 目录下新建一个switch-cuda的脚本
sudo vim /usr/local/switch-cuda.sh
把以下代码复制粘贴进去
#!/usr/bin/env bash
# Copyright (c) 2018 Patrick Hohenecker
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARI