Coverage for cuda / core / system / _temperature.pxi: 11.11%
27 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-08 01:07 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-08 01:07 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
6TemperatureSensors = nvml.TemperatureSensors
7TemperatureThresholds = nvml.TemperatureThresholds
8ThermalController = nvml.ThermalController
9ThermalTarget = nvml.ThermalTarget
12# In cuda.bindings.nvml, this is an anonymous struct inside nvmlThermalSettings_t.
15ctypedef struct _ThermalSensor:
16 int controller
17 int defaultMinTemp
18 int defaultMaxTemp
19 int currentTemp
20 int target
23cdef class ThermalSensor:
24 cdef:
25 _ThermalSensor *_ptr
26 object _owner
28 def __init__(self, ptr: int, owner: object):
29 # ptr points to a part of the numpy buffer held by `_owner`, so we need
30 # to maintain a reference to `_owner` to keep it alive.
31 self._ptr = <_ThermalSensor *><intptr_t>ptr
32 self._owner = owner
34 @property
35 def controller(self) -> ThermalController:
36 return ThermalController(self._ptr[0].controller)
38 @property
39 def default_min_temp(self) -> int:
40 return self._ptr[0].defaultMinTemp
42 @property
43 def default_max_temp(self) -> int:
44 return self._ptr[0].defaultMaxTemp
46 @property
47 def current_temp(self) -> int:
48 return self._ptr[0].currentTemp
50 @property
51 def target(self) -> ThermalTarget:
52 return ThermalTarget(self._ptr[0].target)
55cdef class ThermalSettings:
56 cdef object _thermal_settings
58 def __init__(self, thermal_settings: nvml.ThermalSettings):
59 self._thermal_settings = thermal_settings
61 def __len__(self):
62 # MAX_THERMAL_SENSORS_PER_GPU is 3
63 return min(self._thermal_settings.count, 3)
65 def __getitem__(self, idx: int) -> nvml.ThermalSensor:
66 if idx < 0 or idx >= len(self):
67 raise IndexError("Thermal sensor index out of range")
68 return ThermalSensor(
69 self._thermal_settings.sensor.ptr + idx * sizeof(_ThermalSensor),
70 self._thermal_settings
71 )
74cdef class Temperature:
75 cdef intptr_t _handle
77 def __init__(self, handle: int):
78 self._handle = handle 1a
80 def sensor(
81 self,
82 sensor: TemperatureSensors = TemperatureSensors.TEMPERATURE_GPU
83 ) -> int:
84 """
85 Get the temperature reading from a specific sensor on the device, in
86 degrees Celsius.
88 Parameters
89 ----------
90 sensor: :class:`TemperatureSensors`, optional
91 The temperature sensor to query.
93 Returns
94 -------
95 int
96 The temperature in degrees Celsius.
97 """
98 return nvml.device_get_temperature_v(self._handle, sensor) 1a
100 def threshold(self, threshold_type: TemperatureThresholds) -> int:
101 """
102 Retrieves the temperature threshold for this GPU with the specified
103 threshold type, in degrees Celsius.
105 For Kepler™ or newer fully supported devices.
107 See :class:`TemperatureThresholds` for possible threshold types.
109 Note: This API is no longer the preferred interface for retrieving the
110 following temperature thresholds on Ada and later architectures:
111 ``NVML_TEMPERATURE_THRESHOLD_SHUTDOWN``,
112 ``NVML_TEMPERATURE_THRESHOLD_SLOWDOWN``,
113 ``NVML_TEMPERATURE_THRESHOLD_MEM_MAX`` and
114 ``NVML_TEMPERATURE_THRESHOLD_GPU_MAX``.
116 Support for reading these temperature thresholds for Ada and later
117 architectures would be removed from this API in future releases. Please
118 use :meth:`get_field_values` with ``NVML_FI_DEV_TEMPERATURE_*`` fields
119 to retrieve temperature thresholds on these architectures.
120 """
121 return nvml.device_get_temperature_threshold(self._handle, threshold_type) 1a
123 @property
124 def margin(self) -> int:
125 """
126 The thermal margin temperature (distance to nearest slowdown threshold) for the device.
127 """
128 return nvml.device_get_margin_temperature(self._handle)
130 def thermal_settings(self, sensor_index: ThermalTarget) -> ThermalSettings:
131 """
132 Used to execute a list of thermal system instructions.
134 TODO: The above docstring is from the NVML header, but it doesn't seem to make sense.
136 Parameters
137 ----------
138 sensor_index: ThermalTarget
139 The index of the thermal sensor.
141 Returns
142 -------
143 :class:`ThermalSettings`
144 The thermal settings for the specified sensor.
145 """
146 return ThermalSettings(nvml.device_get_thermal_settings(self._handle, sensor_index))