cuda安裝之後使用pytorch報如下錯誤
UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start.
解決方法,cuda及pytorch安裝完成之後,在.bashrc中添加如下
export PATH=/usr/local/cuda-11.4/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda-11.4/bin
export CUDA_VISIBLE_DEVICES=0,1
如果還是有問題,用sudo apt-get install nvidia-modprobe 安裝,安裝完成後可以使用
檢驗cuda是否正常的方法
import torch
flag = torch.cuda.is_available()
print(flag)
輸出為:True cuda正常