cuda的卸载与重新安装

经常一配置环境就导致cuda不能用 了
报错:RuntimeError: cuda runtime error (30) : unknown error at /pytorch/aten/src/THC/THCGeneral.cpp:74
报错:AssertionError: CUDA unavailable, invalid device 0,1 requested

cuda卸载:
sudo /usr/local/cuda-9.1/bin/uninstall_cuda_9.1.pl
sudo rm -rf /usr/local/cuda-9.1/

cuda重新安装,一直安装的是9.1版本

sudo sh cuda_9.1.85_387.26_linux.run
Do you accept the previously read EULA?
accept/decline/quit: accept

You are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: yes

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 387.26?
(y)es/(n)o/(q)uit: no

Install the CUDA 9.1 Toolkit?
(y)es/(n)o/(q)uit: yes
其他都默认或者是yes,只有nvidia是no,因为之前安装好了。
sudo sh cuda_9.1.85.1_linux.run
sudo sh cuda_9.1.85.2_linux.run
sudo sh cuda_9.1.85.3_linux.run

添加环境变量

sudo vim ~/.bashrc
export  PATH=/usr/local/cuda-8.0/bin:$PATH   //你安装哪个版本就是cuda-x.x
export  LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64$LD_LIBRARY_PATH    //你安装哪个版本就是cuda-x.x

还有一种,不太懂,没有用到

sudo gedit  /etc/profile
export  PATH=/usr/local/cuda-8.0/bin:$PATH   //你安装哪个版本就是cuda-x.x
export  LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64$LD_LIBRARY_PATH    //你安装哪个版本就是cuda-x.x

验证:

cat /proc/driver/nvidia/version
nvcc -V

都没有问题的话进行编译:

cd /usr/local/cuda/samples 
sudo make -j //-j 可以最大限度的使用cpu编译,加快编译的速度

测试:

cd ./bin/x86_64/linux/release
./deviceQuery

或者:

cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
sudo ./deviceQuery

显示通过即为成功
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.4, CUDA Runtime Version = 9.1, NumDevs = 2
Result = PASS

一直不成功,重启就可以成功了。

你可能感兴趣的:(pytorch)