[Ubuntu Error] RuntimeError: CUDA error: no kernel image is available for execution on the device
0. Background:
I installed the cuda following the nvidia procedures and website reference.
Furthermore, i also installed the corresponding pytorch version .
But the above issues happened when i run my script.
1. Check the nvcc --version
nvcc --version
Output:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
2. Check the dpkg -l |grep cuda
dpkg -l |grep cuda
ii cuda-keyring 1.1-1 all GPG keyring for the CUDA repository ii libcudart10.1:amd64 10.1.243-3 amd64 NVIDIA CUDA Runtime Library ii nvidia-cuda-dev 10.1.243-3 amd64 NVIDIA CUDA development files ii nvidia-cuda-doc 10.1.243-3 all NVIDIA CUDA and OpenCL documentation ii nvidia-cuda-gdb 10.1.243-3 amd64 NVIDIA CUDA Debugger (GDB) ii nvidia-cuda-toolkit 10.1.243-3 amd64 NVIDIA CUDA development toolkit
3. run my script
RuntimeError: CUDA error: no kernel image is available for execution on the device CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. Compile with
TORCH_USE_CUDA_DSAto enable device-side assertions.
4. Analyze the issue
提供的输出信息来看,系统上安装了CUDA 10.1相关的包,但nvcc --version命令显示使用的是CUDA 11.8编译器。这种不一致可能导致运行时出现问题,因为库和编译器版本不匹配。
5. 清理旧的CUDA安装:
如果你不再需要CUDA 10.1,可以卸载它以避免冲突。
sudo apt-get --purge remove "cuda-10.1*" "libcudart10.1*" "nvidia-cuda-dev" "nvidia-cuda-doc" "nvidia-cuda-gdb" "nvidia-cuda-toolkit"
sudo apt-get autoremove
sudo apt-get autoclean
6. 验证安装
完成上述步骤后,验证CUDA和PyTorch安装是否正确:
use ipython
import torch
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("CUDA version:", torch.version.cuda)
print("Device name:", torch.cuda.get_device_name(0))
更多推荐

所有评论(0)