Coverage for cuda / core / system / _performance.pxi: 100.00%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-08 01:07 +0000

1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 

2# 

3# SPDX-License-Identifier: Apache-2.0 

4  

5  

6# In cuda.bindings.nvml, this is an anonymous struct inside nvmlGpuDynamicPstatesInfo_t. 

7  

8  

9ctypedef struct _GpuDynamicPstatesUtilization: 

10 unsigned int bIsPresent 

11 unsigned int percentage 

12 unsigned int incThreshold 

13 unsigned int decThreshold 

14  

15  

16cdef class GpuDynamicPstatesUtilization: 

17 cdef: 

18 _GpuDynamicPstatesUtilization *_ptr 

19 object _owner 

20  

21 def __init__(self, ptr: int, owner: object): 

22 # ptr points to a part of the numpy buffer held by `_owner`, so we need 

23 # to maintain a reference to `_owner` to keep it alive. 

24 self._ptr = <_GpuDynamicPstatesUtilization *><intptr_t>ptr 1a

25 self._owner = owner 1a

26  

27 @property 

28 def is_present(self) -> bool: 

29 """ 

30 Set if the utilization domain is present on this GPU. 

31 """ 

32 return bool(self._ptr[0].bIsPresent) 1a

33  

34 @property 

35 def percentage(self) -> int: 

36 """ 

37 Percentage of time where the domain is considered busy in the last 1-second interval. 

38 """ 

39 return self._ptr[0].percentage 1a

40  

41 @property 

42 def inc_threshold(self) -> int: 

43 """ 

44 Utilization threshold that can trigger a perf-increasing P-State change when crossed. 

45 """ 

46 return self._ptr[0].incThreshold 1a

47  

48 @property 

49 def dec_threshold(self) -> int: 

50 """ 

51 Utilization threshold that can trigger a perf-decreasing P-State change when crossed. 

52 """ 

53 return self._ptr[0].decThreshold 1a

54  

55  

56cdef class GpuDynamicPstatesInfo: 

57 """ 

58 Handles performance monitor samples from the device. 

59 """ 

60 cdef object _gpu_dynamic_pstates_info 

61  

62 def __init__(self, gpu_dynamic_pstates_info: nvml.GpuDynamicPstatesInfo): 

63 self._gpu_dynamic_pstates_info = gpu_dynamic_pstates_info 1a

64  

65 def __len__(self): 

66 return nvml.MAX_GPU_UTILIZATIONS 1a

67  

68 def __getitem__(self, idx: int) -> GpuDynamicPstatesUtilization: 

69 if idx < 0 or idx >= nvml.MAX_GPU_UTILIZATIONS: 1a

70 raise IndexError("GPU dynamic P-states index out of range") 1a

71 return GpuDynamicPstatesUtilization( 1a

72 self._gpu_dynamic_pstates_info.utilization.ptr + idx * sizeof(_GpuDynamicPstatesUtilization), 1a

73 self._gpu_dynamic_pstates_info 1a

74 )