nvidia-uvm: first `UVM_REGISTER_GPU` holds `g_uvm_global.global_lock` for the whole `add_gpu()` setup, so concurrent `cuInit` in N processes on N different GPUs is serialized (~4.5 s on an 8x B200 node)

Aperta
#1,541 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, linux

Direzione di ricerca

Start with kernel-open/nvidia-uvm/uvm_gpu.c, tracing uvm_gpu_retain_by_uuid(), gpu_retain_by_uuid_locked(), and add_gpu() to understand the global lock and GPU registration path. The report also identifies NV_ESC_RM_CONTROL calls whose serialization is unexplained, so read those paths alongside registration before deciding the scope. Profile both phases with the supplied concurrent cuInit reproducer; done means concurrent initialization on distinct GPUs no longer queues behind node-wide setup and the reported timings improve.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
NVIDIA Open GPU Kernel Modules Version

580.126.09

Please confirm this issue does not happen with the proprietary driver (of the same version). This issue tracker is only for bugs specific to the open kernel driver.
  • I confirm that this does not happen with the proprietary driver package.
Operating System and Version

Red Hat Enterprise Linux 9.4 (Plow)

Kernel Release

5.14.0-427.42.1.el9_4.x86_64

Please confirm you are running a stable release kernel (e.g. not a -rc). We do not accept bug reports for unreleased kernels.
  • I am running on a stable kernel release.
Hardware: GPU

GPU 0: NVIDIA B200 (UUID: GPU-994d3962-dcb4-09b7-7863-81cc07c000f3) GPU 1: NVIDIA B200 (UUID: GPU-c3af7f06-77cc-298c-6878-4ffc853f901b) GPU 2: NVIDIA B200 (UUID: GPU-64247ee0-418d-d3c4-2072-035e59c1c3a4) GPU 3: NVIDIA B200 (UUID: GPU-5e6ac0f2-b02a-0d5e-94c8-67ad751595d6) GPU 4: NVIDIA B200 (UUID: GPU-d3810e9e-4606-a71c-0dc1-a05f1fadc8ec) GPU 5: NVIDIA B200 (UUID: GPU-b339c54a-6988-65ab-71db-350d4caf2a0d) GPU 6: NVIDIA B200 (UUID: GPU-c6306ffb-cdb8-d304-39af-56fcad864308) GPU 7: NVIDIA B200 (UUID: GPU-495ca190-a4b9-02bc-9060-4f547e013f0b)

Describe the bug

Summary

On an 8x B200 node, 8 processes that each start CUDA on their own, distinct GPU at the same time are served one after another inside the UVM driver. Each process's first cuInit sends UVM_REGISTER_GPU (ioctl nr 37 / 0x25 on
/dev/nvidia-uvm). That call's duration is staggered across the processes: 0.33, 0.44, 0.80, 1.74, 2.07, 2.57, 3.45, 4.44 s. The slowest is ~8 x the single-process cost. The processes don't share a GPU, so the serialization is node-wide, not per GPU.

This hits every MPI job that runs one rank per GPU: Open MPI's MPI_Init ends in a fence, so every rank waits for the last one in the driver queue. On our 8x B200 nodes MPI_Init takes ~7 s for 8 ranks/node vs ~1.2 s for 1 rank/node, and it grows by ~0.7-0.9 s per additional rank on the same node.

Environment

  • GPUs: 8x NVIDIA B200 (183359 MiB each), one node
  • Driver: 580.126.09, open kernel module (Dual MIT/GPL)
  • nvidia-smi -q: Persistence Mode = Enabled, Addressing Mode = HMM
  • nvidia_uvm parameters: uvm_disable_hmm=N, uvm_ats_mode=1, rest default
  • Kernel: 5.14.0-427.42.1.el9_4.x86_64 (RHEL 9.4)
  • CUDA: 12.9 (libcudart 12.9.79)
  • Slurm with cgroup GPU binding: each process can open only its own
    /dev/nvidiaN (all other /dev/nvidia* GPU nodes return EPERM), so each
    process sees exactly one, distinct GPU.

Evidence (strace -f -k -y, 8 processes, one GPU each)

Every process blocks in the same ioctl, issued from cuInit:

ioctl(20</dev/nvidia-uvm>, _IOC(_IOC_NONE, 0, 0x25, 0), 0x7ffefe270d00) = 0 <4.438661>
 > libc.so.6(ioctl+0xb)
 > libcuda.so.580.126.09() [0x449e53]
 > libcuda.so.580.126.09() [0x320961]
 > libcuda.so.580.126.09() [0x31187c]
 > libcuda.so.580.126.09() [0x2d2ef7]
 > libcuda.so.580.126.09() [0x331a31]
 > libcuda.so.580.126.09(cuInit+0x1f)
 > ... (caller: Open MPI / hwloc / UCX -- irrelevant, see below)

UVM_INITIALIZE (shown as _IOC(_IOC_NONE, 0, 0x1, 0x3000)) runs just before on the same fd and takes ~80 us, so the cost is in UVM_REGISTER_GPU.

Per-process UVM_REGISTER_GPU durations in one run (8 processes, 8 distinct GPUs):

0.327596  0.438258  0.800688  1.740365  2.066696  2.565258  3.448307  4.438661  s

A second run on another node of the same type gave 0.31-4.61 s. A third run where a different library made the first cuInit call gave 0.23-4.63 s. So the cost doesn't depend on the caller, only on concurrent first-time registration.

A related symptom: a process that closes a /dev/nvidia-uvm fd (here from nvmlShutdown) while others are registering blocks in close() for up to ~4.3 s and returns when the registration queue drains.

Where we think it comes from (source reading, 580.126.09)

kernel-open/nvidia-uvm/uvm_gpu.c:

  • uvm_gpu_retain_by_uuid() takes g_uvm_global.global_lock and calls gpu_retain_by_uuid_locked().
  • On the first retain of a GPU, gpu_retain_by_uuid_locked() runs nvUvmInterfaceRegisterGpu() and then add_gpu() (parent GPU init, GPU init, and with HMM uvm_pmm_devmem_init() -> memremap_pages() for the device-private page map), all with the global lock held.
  • If the GPU is already retained, it only does atomic64_inc(&gpu->retained_count).
  • uvm_gpu_release() takes the same lock, and remove_gpu() runs when the count reaches zero. So once the last process on a GPU exits, the next process pays the full setup again (every batch job, in practice).

So N processes doing their first registration of N different GPUs all run their add_gpu() back to back under one mutex. The same structure is still present in 620.70.06 (also checked 595.112.07 and 610.57.04).

We haven't profiled inside the kernel, so we can't say which part of add_gpu() dominates the ~0.55 s per GPU.

See reproducer below. Expected with per-GPU registration: all 8 close to the single-process time.

Observed (8x B200, 580.126.09, three repeats; every repeat is a first-time registration again because all processes exit in between):

rep 1 rep 2 rep 3
1 process, cuInit 0.509 s 0.519 s 0.517 s
8 concurrent, cuInit per process (sorted) 2.73 3.03 3.45 3.98 4.64 5.38 6.23 7.19 s 2.81 3.30 3.91 4.59 5.44 6.42 7.41 8.56 s 2.87 3.34 3.89 4.57 5.39 6.35 7.36 8.31 s

strace -f -T -y -e trace=ioctl on one 8-process run splits this into two phases:

  1. UVM_REGISTER_GPU (/dev/nvidia-uvm, _IOC(_IOC_NONE, 0, 0x25, 0)), staggered: 0.207 0.546 0.957 1.520 2.167 2.950 3.781 4.724 s. This is the one-at-a-time queue described above. UVM_INITIALIZE takes 51-69 us in every process.
  2. Before that, ~2.35 s in every process in NV_ESC_RM_CONTROL (/dev/nvidiactl, _IOC(_IOC_READ|_IOC_WRITE, 0x46, 0x2a, ...)): about 25 calls of ~0.05-0.19 s each, and in each round all 8 processes' calls return within microseconds of each other. A single process's whole cuInit takes 0.51 s, so this phase also seems to be serialized or batched across processes. We can't see which RM control commands these are, or which lock is involved, from user space.

Per-process ioctl time in that traced run (nvidiactl / nvidia-uvm): gpu0 2.35/0.96, gpu1 2.37/3.78, gpu2 2.35/4.72, gpu3 2.34/0.55, gpu4 2.34/1.52, gpu5 2.34/0.21, gpu6 2.33/2.95, gpu7 2.36/2.17 s.

To Reproduce

Minimal reproducer (no MPI)

// cuinit_time.c -- build: gcc -O2 cuinit_time.c -o cuinit_time -I$CUDA_HOME/include -lcuda
#include <cuda.h>
#include <stdio.h>
#include <time.h>

static double now(void) {
  struct timespec t;
  clock_gettime(CLOCK_MONOTONIC,&t);
  return t.tv_sec+t.tv_nsec*1e-9;
}
int main(void){
  double t0=now();
  CUresult r=cuInit(0);
  printf("cuInit=%d %.3f s\n",(int)r,now()-t0);
  return r;
}

On a fully, exclusively allocated node:

# one process alone (baseline)
CUDA_VISIBLE_DEVICES=0 ./cuinit_time

# 8 concurrent processes, each on its own GPU
for i in 0 1 2 3 4 5 6 7; do
  CUDA_VISIBLE_DEVICES=$i ./cuinit_time &
done;
wait
Bug Incidence

Always

nvidia-bug-report.log.gz

nvidia-bug-report.part-00.gz
nvidia-bug-report.part-01.gz
nvidia-bug-report.part-02.gz

More Info

No response

Lingua principale
C
Stelle
17.7k
Fork
2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/open-gpu-kernel-modules

Tutte le issue di NVIDIA/open-gpu-kernel-modules

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.