Fix host PID detection when CUDA_VISIBLE_DEVICES doesn't start at device 0 - #305
Fix host PID detection when CUDA_VISIBLE_DEVICES doesn't start at device 0#305ihnokim wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ihnokim The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthrough
ChangesProbe Device Alignment
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change is localized and no actionable merge-blocking risk remains after normal checks and review. Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The changes match issue Full details: Out of Scope Changes checkExplanation The device-matching and context-cleanup changes are in scope for issue
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
a595b1a to
cc30e87
Compare
cc30e87 to
ecab05f
Compare
…ice 0 Signed-off-by: ihnokim <ihnokim58@gmail.com>
ecab05f to
1b3d92e
Compare
|
This is being closed because it does not comply with the contribution guidelines. |
Fixes #225 (closed by the lifecycle policy while the bug is still present on
main).Changes?
set_task_pid()now pairs the probe context and the polled NVML device by UUID: the probe context is created on CUDA device 0, and the NVML device whose UUID matches (cuDeviceGetUuidvsnvmlDeviceGetUUID) is used for both process snapshots.nvml_preInit()map reset itself (see below). This PR only makesset_task_pid()independent of the map; other consumers of the map are unchanged.Why We Need?
CUDA_VISIBLE_DEVICESdoes not start with the container's device 0, host-PID detection fails deterministically (host pid is error!), per-process accounting is merged into the wrong slot, and legal allocations trip spurious per-device OOMs. This is the failure analyzed in set_task_pid: deterministic "host pid is error" when CUDA_VISIBLE_DEVICES does not start with the pod's device 0 (probe context and poll target mismatch), leading to spurious Device 0 OOM #225.cuDevicePrimaryCtxRetain(&pctx, 0), which is CUDA device 0, while the before/after NVML snapshots are taken on the first NVML device that has a valid entry incuda_to_nvml_map. With such aCUDA_VISIBLE_DEVICES, those are different physical GPUs, so the probe PID never appears in the snapshot diff.nvml_preInit()resetscuda_to_nvml_map_arrayto identity, and it is triggered viapthread_onceby thenvmlInit()call at the top ofset_task_pid()itself. By the time the polling loop consults the map, it is an identity map regardless of whatparse_cuda_visible_env()computed earlier inpostInit().cudaDevfound through the map) did not resolve the failure when we tested it: with an identity map thatcudaDevis always 0, which is behaviorally identical to the hardcoded value. It is consistent with thecurrent processes num = 0 0runs reported in the fix: probe CUDA context on correct device in set_task_pid() #230 thread with that patch applied. The unresolvedSET_TASK_PID FAILEDcase on driver 580.65.06 from that thread matches this root cause as well, but we could not verify on that exact driver.Tests?
Environment: Kubernetes + HAMi v2.7.1 (hami-scheduler), pod with
nvidia.com/gpu: 2,nvidia.com/gpumem: 5800; node: 2x NVIDIA A100-PCIE-40GB, driver 580.173.02. Cases A-F are the reproduction matrix from #225, 3 repetitions each.011,01,0+ set_device(1)0,1+ set_device(1)0,1cuInit, no CUDA runtime involved),main:current processes num = 1 2->hostPid=581730(v2.7.1 build) /hostPid=1150676(main build)CVD=1,0, 15 s): no lingering probe context during or after the runnvidia/cuda:13.3.0-cudnn-devel-ubi8(themake build-in-dockerimage)main(patched or not) fails CUDA runtime entry-point negotiation for every torch build we tried (cudart 12.6 / 12.8 / 13.0, all ending inFound no NVIDIA driver), while the official v2.7.1 binary works and direct driver-API calls also work. That regression is unrelated to this change (it reproduces on unpatchedmain) and we will report it separately. Because of it, the full-workload validation uses a v2.7.1 backport of this patch, andmainis validated through the driver-API probe path. The probe path was cross-checked against the official v2.7.1 binary, where it reproduces the same B/C/D failures as the torch matrix.