From ffcf6d7fa97e2ae84bf75e3b60b902a5d101387e Mon Sep 17 00:00:00 2001 From: maverick123123 Date: Thu, 23 Jul 2026 16:12:48 +0800 Subject: [PATCH] fix: probe CUDA context on correct device in set_task_pid() set_task_pid() polls NVML processes on the first device where nvml_to_cuda_map(i) >= 0, but the probe context was always created on hardcoded CUDA device 0 via cuDevicePrimaryCtxRetain(&pctx, 0). When CUDA_VISIBLE_DEVICES does not start with the pod's device 0 (e.g., CVD=1 or CVD=1,0), the polled NVML device and the probe context device are different physical GPUs. getextrapid() never finds the new PID, causing a spurious 'host pid is error!' and subsequent Device 0 OOM due to incorrect memory accounting. Fix: use the cudaDev found in the NVML enumeration loop for both cuDevicePrimaryCtxRetain and cuDevicePrimaryCtxRelease, ensuring the probe context runs on the same device being polled. Fixes #225 Signed-off-by: maverick123123 --- src/utils.c | 63 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/utils.c b/src/utils.c index e96b43e3..a86bad30 100755 --- a/src/utils.c +++ b/src/utils.c @@ -101,7 +101,7 @@ nvmlReturn_t set_task_pid() { nvmlProcessInfo_t1 pre_pids_on_device[SHARED_REGION_MAX_PROCESS_NUM]; nvmlProcessInfo_t1 pids_on_device[SHARED_REGION_MAX_PROCESS_NUM]; nvmlDevice_t device; - nvmlReturn_t res; + nvmlReturn_t res = NVML_SUCCESS; CUcontext pctx; int i; CHECK_NVML_API(nvmlInit()); @@ -111,65 +111,82 @@ nvmlReturn_t set_task_pid() { CHECK_NVML_API(nvmlDeviceGetCount(&nvmlCounts)); int cudaDev; + int probeDev = -1; for (i=0;i