Pytorch common problems - cuda runtime erorr

1. When running the program, an error "RuntimeError: cuda runtime erorr (77): an illegal memory access was encountered at" will be reported

Solution: add the following command before the code

os.environ['CUDA_LAUNCH_BLOCKING'] = '1'

2. Next, the error "RuntimeError: CUDA error: no kernel image is available for execution on the device" appears

Solution: Enter the following test code in the python console

#1. 导入torch
import torch

# 2. 检测CUDA是否安装正确并能被Pytorch检测
torch.cuda.is_available()

#3. 查看Pytorch能不能调用cuda加速
t = torch.ones(1,1,28,28)
t = t.cuda()
t

Facts have proved that the code in the third step cannot run normally, and an error will be reported "RuntimeError: CUDA error: no kernel image is available for execution on the device", indicating that the cuda version does not match the gpu, please refer to relevant information

cuda computing power

 I am using a 3090 graphics card with a computing power of 8.6. I installed torch=1.10.1 at the beginning, and the dependent cuda does not support GPUs with a computing power of 8.6, so I cannot run the code successfully. Later, follow the following command to replace the torch version and rely on cuda 11, the above test code can be run normally.

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

However, then I get the following error "original error: ..../lib/python3.6/site-packages/cupy_backends/cuda/api/runtime.cpython-36m-x86_64-linux-gnu.so: symbol cudaDeviceSetMemPool version libcudart. so.11.0 not defined in file libcudart.so.11.0 with link time reference”

Guessing that cupy may not be installed successfully, enter the following command to install cupy:

pip install cupy-cuda111
pip install --user --no-cache-dir cupy-cuda111

Cupy 8.3.0 does not match cupy-cuda111, use the following command to reinstall cupy:

conda install -c conda-forge cupy cudatoolkit=11.1 cudnn cutensor nccl

It finally worked!

Guess you like

Origin blog.csdn.net/weixin_41698730/article/details/121266697