查看当前计算机cudatoolkit的版本
nvcc -V
下载
如果想切换到指定版本,则去官网下载(10.1版本为例):
cuda下载
cudnn下载
将下载好的文件放到服务器的文件夹中
安装
安装cuda
sh cuda_10.1.243_418.87.00_linux.run
选择接受
只安装toolkit
修改toolkit的路径
修改最终的安装路径
最后的结果显示
安装cudann
解压
tar -xzvf cudnn-10.1-linux-x64-v8.0.5.39.tgz
cp tmp_path/cuda/include/cudnn.h install_path/include/
cp tmp_path/cuda/lib64/libcudnn* install_path/lib64
chmod a+r install_path/include/cudnn.h install_path/lib64/libcudnn*
修改bashrc
在bashrc中添加
export CUDA_HOME=$CUDA_HOME:install_path
export PATH=$PATH:install_path/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:install_path/lib64
之后
source ~/.bashrc
显示
一键查看版本
import torch
print("PyTorch version:", torch.__version__)
print("Is CUDA available:", torch.cuda.is_available())
print("CUDA version:", torch.version.cuda)
print("CUDA device count:", torch.cuda.device_count())
print("CUDA device name:", torch.cuda.get_device_name(0) if torch.cuda.is_available() else "No CUDA device")
参考:
https://blog.csdn.net/qq_35091353/article/details/123762363
https://zhuanlan.zhihu.com/p/198161777