From b99d90544d1e67fe55fa480d007690850339a199 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Fri, 4 Aug 2023 15:47:55 +0800 Subject: [PATCH] feat(api/process): update GPU status for gone processes --- nvitop/api/process.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nvitop/api/process.py b/nvitop/api/process.py index 05d8c3d..74fccb0 100644 --- a/nvitop/api/process.py +++ b/nvitop/api/process.py @@ -694,7 +694,19 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi self.set_gpu_memory(NA) self.set_gpu_cc_protected_memory(NA) self.set_gpu_utilization(NA, NA, NA, NA) - self.device.processes() + processes = self.device.processes() + process = processes.get(self.pid, self) + if process is not self: + # The current process is gone and the instance has been removed from the cache. + # Update GPU status from the new instance. + self.set_gpu_memory(process.gpu_memory()) + self.set_gpu_cc_protected_memory(process.gpu_cc_protected_memory()) + self.set_gpu_utilization( + process.gpu_sm_utilization(), + process.gpu_memory_utilization(), + process.gpu_encoder_utilization(), + process.gpu_decoder_utilization(), + ) return self.gpu_memory() @property