docker 内 pytorch cuda 不可用

拉的官方 docker 仓库里的镜像

nvidia/cuda:12.4.1-cudnn-devel-rockylinux8

conda 安装2.5.0 的 pytorch 后,使用 cuda 报错

go 复制代码
(myenv) [root@000b4321253c opt]# python test1.py 
可用 GPU 数量: 1
检测 CUDA 时出错: Unexpected error from cudaGetDeviceCount(). Did you run some cuda functions before calling NumCudaDevices() that might have already set an error? Error 804: forward compatibility was attempted on non supported HW

我的 test1.py 代码

go 复制代码
import torch

try:
    device_count = torch.cuda.device_count()
    print("可用 GPU 数量:", device_count)
    for i in range(device_count):
        print(f"GPU {i}: {torch.cuda.get_device_name(i)}")
except Exception as e:
    print("检测 CUDA 时出错:", e)

nvidia-smi 可以执行

直接贴原因:

NVIDIA 在 /usr/local/cuda/compat/ 目录下提供了一些兼容库 (libcuda.so.1 等),但如果主机的 NVIDIA 驱动版本较新,则不需要这些兼容库。强行使用这些库可能会导致不匹配的 CUDA 版本,从而触发 Error 804。

解决方案:

go 复制代码
rm -rf /usr/local/cuda/compat
相关推荐
百年੭ ᐕ)੭*⁾⁾20 小时前
docker使用neo4j
docker·容器·neo4j
春风有信1 天前
【2026.05.01】Windows10安装Docker Desktop 4.71.0.0步骤及问题解决
运维·docker·容器
Studying 开龙wu1 天前
深度学习PyTorch 实战九:YOLOv1目标检测从标注-训练-预测
pytorch·深度学习·yolo
sthnyph1 天前
docker compose安装redis
redis·docker·容器
W.A委员会1 天前
Docker基本使用流程
运维·docker·容器
gwjcloud1 天前
Kubernetes从入门到精通(进阶篇)03
云原生·容器·kubernetes
GuokLiu1 天前
260502-Clawith-Docker安装过程
运维·docker·容器·claw
JesseDev1 天前
Docker lnmp环境快速搭建开箱即用
运维·docker·容器
空中海1 天前
Docker入门到精通
java·docker·eureka
小义_1 天前
【Kubernetes】(十二)配置存储卷
云原生·容器·kubernetes