mirror of
https://github.com/XuehaiPan/nvitop.git
synced 2026-05-21 06:45:24 -06:00
feat(api/process): set used_gpu_cc_protected_memor for GpuProcess
This commit is contained in:
parent
788a1fb44e
commit
29b047c18d
2 changed files with 34 additions and 5 deletions
|
|
@ -1692,6 +1692,7 @@ class Device: # pylint: disable=too-many-instance-attributes,too-many-public-me
|
|||
gpu_memory=gpu_memory,
|
||||
gpu_instance_id=getattr(p, 'gpuInstanceId', UINT_MAX),
|
||||
compute_instance_id=getattr(p, 'computeInstanceId', UINT_MAX),
|
||||
used_gpu_cc_protected_memory=getattr(p, 'usedGpuCcProtectedMemory', NA),
|
||||
)
|
||||
proc.type = proc.type + type
|
||||
|
||||
|
|
|
|||
|
|
@ -463,10 +463,12 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi
|
|||
cls,
|
||||
pid: int | None,
|
||||
device: Device,
|
||||
*,
|
||||
# pylint: disable=unused-argument
|
||||
gpu_memory: int | NaType | None = None,
|
||||
gpu_instance_id: int | NaType | None = None,
|
||||
compute_instance_id: int | NaType | None = None,
|
||||
used_gpu_cc_protected_memory: int | NaType | None = None,
|
||||
type: str | NaType | None = None, # pylint: disable=redefined-builtin
|
||||
# pylint: enable=unused-argument
|
||||
) -> GpuProcess:
|
||||
|
|
@ -501,9 +503,11 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi
|
|||
self,
|
||||
pid: int | None, # pylint: disable=unused-argument
|
||||
device: Device,
|
||||
*,
|
||||
gpu_memory: int | NaType | None = None,
|
||||
gpu_instance_id: int | NaType | None = None,
|
||||
compute_instance_id: int | NaType | None = None,
|
||||
used_gpu_cc_protected_memory: int | NaType | None = None,
|
||||
type: str | NaType | None = None, # pylint: disable=redefined-builtin
|
||||
) -> None:
|
||||
"""Initialize the instance returned by :meth:`__new__()`."""
|
||||
|
|
@ -528,6 +532,14 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi
|
|||
else:
|
||||
self._gpu_instance_id = self._compute_instance_id = NA
|
||||
|
||||
if used_gpu_cc_protected_memory is None and not hasattr(
|
||||
self,
|
||||
'_used_gpu_cc_protected_memory',
|
||||
):
|
||||
used_gpu_cc_protected_memory = NA
|
||||
if used_gpu_cc_protected_memory is not None:
|
||||
self.set_used_gpu_cc_protected_memory(used_gpu_cc_protected_memory)
|
||||
|
||||
for util in ('sm', 'memory', 'encoder', 'decoder'):
|
||||
if not hasattr(self, f'_gpu_{util}_utilization'):
|
||||
setattr(self, f'_gpu_{util}_utilization', NA)
|
||||
|
|
@ -617,6 +629,15 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi
|
|||
"""The percentage of used GPU memory by the process, or :const:`nvitop.NA` if not applicable."""
|
||||
return self._gpu_memory_percent
|
||||
|
||||
def used_gpu_cc_protected_memory(self) -> int | NaType: # in bytes
|
||||
"""The used GPU conf compute protected memory in bytes, or :const:`nvitop.NA` if not applicable."""
|
||||
return self._used_gpu_cc_protected_memory
|
||||
|
||||
def used_gpu_cc_protected_memory_human(self) -> str | NaType: # in human readable
|
||||
# pylint: disable-next=line-too-long
|
||||
"""The used GPU conf compute protected memory in human readable format, or :const:`nvitop.NA` if not applicable."""
|
||||
return self._used_gpu_cc_protected_memory_human
|
||||
|
||||
def gpu_sm_utilization(self) -> int | NaType: # in percentage
|
||||
"""The utilization rate of SM (Streaming Multiprocessor), or :const:`nvitop.NA` if not applicable."""
|
||||
return self._gpu_sm_utilization
|
||||
|
|
@ -644,12 +665,18 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi
|
|||
gpu_memory_percent = round(100.0 * memory_used / memory_total, 1) # type: ignore[assignment]
|
||||
self._gpu_memory_percent = gpu_memory_percent
|
||||
|
||||
def set_used_gpu_cc_protected_memory(self, value: int | NaType) -> None:
|
||||
"""Set the used GPU conf compute protected memory in bytes."""
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self._used_gpu_cc_protected_memory = value
|
||||
self._used_gpu_cc_protected_memory_human = bytes2human(self.used_gpu_cc_protected_memory())
|
||||
|
||||
def set_gpu_utilization(
|
||||
self,
|
||||
gpu_sm_utilization: int | None = None,
|
||||
gpu_memory_utilization: int | None = None,
|
||||
gpu_encoder_utilization: int | None = None,
|
||||
gpu_decoder_utilization: int | None = None,
|
||||
gpu_sm_utilization: int | NaType | None = None,
|
||||
gpu_memory_utilization: int | NaType | None = None,
|
||||
gpu_encoder_utilization: int | NaType | None = None,
|
||||
gpu_decoder_utilization: int | NaType | None = None,
|
||||
) -> None:
|
||||
"""Set the GPU utilization rates."""
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
|
|
@ -665,7 +692,8 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi
|
|||
def update_gpu_status(self) -> int | NaType:
|
||||
"""Update the GPU consumption status from a new NVML query."""
|
||||
self.set_gpu_memory(NA)
|
||||
self.set_gpu_utilization(NA, NA, NA, NA) # type: ignore[arg-type]
|
||||
self.set_used_gpu_cc_protected_memory(NA)
|
||||
self.set_gpu_utilization(NA, NA, NA, NA)
|
||||
self.device.processes()
|
||||
return self.gpu_memory()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue