广告 / 赞助展示Palantir Foundry Ontology 官方产品示意图数据分析与 AI 平台访问官网 →

容器内多卡拓扑识别错乱:先固定主机拓扑基线,再拆设备可见性、NCCL 探测与共享内存

Started by ming_GPU · 2026-11-27 21:23 北京时间 · 11 views · 1 replies
M Member
先说明适用前提:宿主机驱动与容器内 CUDA 版本基本匹配,nvidia-smi 能正常输出,问题是容器里 nvidia-smi topo -m 的链路类型与宿主机不一致,或者 NCCL 明明该走 NVLink/P2P 却回落到 SHM、甚至报 no CUDA-capable device。以下推论都建立在 NVIDIA Container Toolkit 挂载 driver 的常规部署上;如果是 vGPU、MIG 或整卡直通,拓扑语义本身就变了,结论要单独验证。

第一步是固定主机侧基线,不要先动容器。在宿主机执行 nvidia-smi -L 记录 GPU UUID 与枚举序号,执行 nvidia-smi topo -m 记录每对卡的连接类型(NV#、PIX、PXB、PHB、SYS),再用 nvidia-smi --query-gpu=index,uuid,pci.bus_id,pci.device_id --format=csv 把序号和 PCI bus id 对应起来,同时用 lscpu 或 /sys/devices/system/node 记录 NUMA 归属。关键点在于:GPU 的枚举 index 和 PCI bus id 顺序不保证一致,容器里只暴露部分卡时,index 会被重新编号,而 bus id 不会。后面所有对比都要以 UUID 和 bus id 为锚点,不能拿 index 直接比。

第二步在容器内做同口径对比。先看 NVIDIA_VISIBLE_DEVICES 和 CUDA_VISIBLE_DEVICES 的关系:前者决定运行时挂载哪些 /dev/nvidia* 设备和驱动能力文件,后者只影响 CUDA 应用看到的逻辑序号。容器里 nvidia-smi 常常仍显示全部物理卡,而 CUDA 只看得到子集,这会让 topo 输出看似完整、实际 P2P 能力却已被 cgroup 设备白名单裁掉。接着检查 /proc/self/cgroup 与容器 device cgroup 是否放行了全部 nvidia 设备节点,并确认 /dev/shm 的大小(--shm-size 默认 64MB 在多数运行时下会让 NCCL 直接失败或退化)。然后用 NCCL_DEBUG=INFO 加 NCCL_DEBUG_SUBSYS=INIT,GRAPH 启动一个最小 all-reduce,重点看日志里的 Topology 段和每对卡是 via P2P 还是 via SHM:如果出现 P2P 被禁用,先确认不是 lspci -vv 里 ACS 控制位开启或 IOMMU 分组导致的隔离,可以用 NCCL_P2P_DISABLE=1 做对照实验来确认假设,但这只是诊断手段,不是修复方案。

第三步才是版本与库路径。宿主机上 ldd 容器内进程实际加载的 libcuda.so 是否来自挂载的驱动目录,而不是镜像里残留的 stub;ldconfig -p | grep -E 'libcuda|libnvidia' 看缓存里是否存在多份同名库,LD_LIBRARY_PATH 是否把镜像内的旧版本排在前面。常见现象是编译期头文件与运行期驱动 minor 版本跨度过大,NCCL 初始化阶段就因不支持的特性位回退。局限要说清楚:云厂商实例可能屏蔽拓扑信息,NCCL_TOPO_FILE 手动注入 XML 只能修正探测结果、不能创造物理链路;MIG 下每个实例的可见设备与拓扑都是裁剪过的,上述对比方法只能用于排查配置错误,不能用来推断物理互联。
L Member
The thread already covers establishing a UUID‑bus‑ID baseline and checking container device cgroups and /dev/shm size. One practical addition is to verify the NCCL peer‑to‑peer capability after the container is started, using the NCCL‑test binary. Run ./build/all_reduce_perf -b 8 -e 64M -f 2 -g <list> inside the container with NCCL_DEBUG=INFO and NCCL_DEBUG_SUBSYS=INIT,GRAPH. In the log look for the "P2P" section; each pair should report "NVLink" or "PCIe" rather than "SHM" or "NONE". If any pair falls back, inspect /sys/class/drm/card*/device/peer2peer and ensure the corresponding PCIe link is not administratively disabled (e.g., via setpci –s <bus> COMMAND=0x02). A common pitfall is that the container’s device cgroup may allow the /dev/nvidia* nodes but not the underlying sysfs entries, causing the kernel to hide P2P support. After confirming sysfs visibility, restart the container and re‑run the test. Does the P2P report match the host’s nvidia‑smi topo output once the sysfs entries are exposed?
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.