From 283a821c08b26203a6916f81ef55fdb7dee896e3 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 17 Apr 2026 14:33:56 -0400 Subject: [PATCH] cuda.core.system: Naming improvements suggested in #1945 --- cuda_core/cuda/core/system/_device.pyx | 32 +++++----- cuda_core/cuda/core/system/_fan.pxi | 2 +- cuda_core/cuda/core/system/_pci_info.pxi | 20 ++++--- cuda_core/cuda/core/system/_temperature.pxi | 6 +- cuda_core/tests/system/test_system_device.py | 62 ++++++++++---------- 5 files changed, 66 insertions(+), 56 deletions(-) diff --git a/cuda_core/cuda/core/system/_device.pyx b/cuda_core/cuda/core/system/_device.pyx index f661c4e685..58102d73b7 100644 --- a/cuda_core/cuda/core/system/_device.pyx +++ b/cuda_core/cuda/core/system/_device.pyx @@ -215,14 +215,14 @@ cdef class Device: return nvml.device_get_minor_number(self._handle) @property - def is_c2c_mode_enabled(self) -> bool: + def is_c2c_enabled(self) -> bool: """ Whether the C2C (Chip-to-Chip) mode is enabled for this device. """ return bool(nvml.device_get_c2c_mode_info_v(self._handle).is_c2c_enabled) @property - def persistence_mode_enabled(self) -> bool: + def persistence_mode(self) -> bool: """ Whether persistence mode is enabled for this device. @@ -230,8 +230,8 @@ cdef class Device: """ return nvml.device_get_persistence_mode(self._handle) == nvml.EnableState.FEATURE_ENABLED - @persistence_mode_enabled.setter - def persistence_mode_enabled(self, enabled: bool) -> None: + @persistence_mode.setter + def persistence_mode(self, enabled: bool) -> None: nvml.device_set_persistence_mode( self._handle, nvml.EnableState.FEATURE_ENABLED if enabled else nvml.EnableState.FEATURE_DISABLED @@ -409,13 +409,14 @@ cdef class Device: # CLOCK # See external class definitions in _clock.pxi - def clock(self, clock_type: ClockType) -> ClockInfo: + def get_clock(self, clock_type: ClockType) -> ClockInfo: """ Get information about and manage a specific clock on a device. """ return ClockInfo(self._handle, clock_type) - def get_auto_boosted_clocks_enabled(self) -> tuple[bool, bool]: + @property + def is_auto_boosted_clocks_enabled(self) -> tuple[bool, bool]: """ Retrieve the current state of auto boosted clocks on a device. @@ -440,7 +441,8 @@ cdef class Device: current, default = nvml.device_get_auto_boosted_clocks_enabled(self._handle) return current == nvml.EnableState.FEATURE_ENABLED, default == nvml.EnableState.FEATURE_ENABLED - def get_current_clock_event_reasons(self) -> list[ClocksEventReasons]: + @property + def current_clock_event_reasons(self) -> list[ClocksEventReasons]: """ Retrieves the current clocks event reasons. @@ -450,7 +452,8 @@ cdef class Device: reasons[0] = nvml.device_get_current_clocks_event_reasons(self._handle) return [ClocksEventReasons(1 << reason) for reason in _unpack_bitmask(reasons)] - def get_supported_clock_event_reasons(self) -> list[ClocksEventReasons]: + @property + def supported_clock_event_reasons(self) -> list[ClocksEventReasons]: """ Retrieves supported clocks event reasons that can be returned by :meth:`get_current_clock_event_reasons`. @@ -492,17 +495,17 @@ cdef class Device: # DISPLAY @property - def display_mode(self) -> bool: + def is_display_connected(self) -> bool: """ The display mode for this device. Indicates whether a physical display (e.g. monitor) is currently connected to any of the device's connectors. """ - return True if nvml.device_get_display_mode(self._handle) == nvml.EnableState.FEATURE_ENABLED else False + return nvml.device_get_display_mode(self._handle) == nvml.EnableState.FEATURE_ENABLED @property - def display_active(self) -> bool: + def is_display_active(self) -> bool: """ The display active status for this device. @@ -512,7 +515,7 @@ cdef class Device: Display can be active even when no monitor is physically attached. """ - return True if nvml.device_get_display_active(self._handle) == nvml.EnableState.FEATURE_ENABLED else False + return nvml.device_get_display_active(self._handle) == nvml.EnableState.FEATURE_ENABLED ########################################################################## # EVENTS @@ -580,7 +583,7 @@ cdef class Device: # FAN # See external class definitions in _fan.pxi - def fan(self, fan: int = 0) -> FanInfo: + def get_fan(self, fan: int = 0) -> FanInfo: """ Get information and manage a specific fan on a device. """ @@ -707,7 +710,8 @@ cdef class Device: """ return GpuDynamicPstatesInfo(nvml.device_get_dynamic_pstates_info(self._handle)) - def get_supported_pstates(self) -> list[Pstates]: + @property + def supported_pstates(self) -> list[Pstates]: """ Get all supported Performance States (P-States) for the device. diff --git a/cuda_core/cuda/core/system/_fan.pxi b/cuda_core/cuda/core/system/_fan.pxi index 6b5e26f4b0..bfe417c267 100644 --- a/cuda_core/cuda/core/system/_fan.pxi +++ b/cuda_core/cuda/core/system/_fan.pxi @@ -96,7 +96,7 @@ cdef class FanInfo: """ return FanControlPolicy(nvml.device_get_fan_control_policy_v2(self._handle, self._fan)) - def set_default_fan_speed(self): + def set_default_speed(self): """ Set the speed of the fan control policy to default. diff --git a/cuda_core/cuda/core/system/_pci_info.pxi b/cuda_core/cuda/core/system/_pci_info.pxi index e5f1bb287e..1402853fa2 100644 --- a/cuda_core/cuda/core/system/_pci_info.pxi +++ b/cuda_core/cuda/core/system/_pci_info.pxi @@ -81,7 +81,8 @@ cdef class PciInfo: """ return self._pci_info_ext.sub_class - def get_max_pcie_link_generation(self) -> int: + @property + def link_generation(self) -> int: """ Retrieve the maximum PCIe link generation possible with this device and system. @@ -93,7 +94,8 @@ cdef class PciInfo: """ return nvml.device_get_max_pcie_link_generation(self._handle) - def get_gpu_max_pcie_link_generation(self) -> int: + @property + def max_link_generation(self) -> int: """ Retrieve the maximum PCIe link generation supported by this GPU device. @@ -101,7 +103,8 @@ cdef class PciInfo: """ return nvml.device_get_gpu_max_pcie_link_generation(self._handle) - def get_max_pcie_link_width(self) -> int: + @property + def max_link_width(self) -> int: """ Retrieve the maximum PCIe link width possible with this device and system. @@ -113,7 +116,8 @@ cdef class PciInfo: """ return nvml.device_get_max_pcie_link_width(self._handle) - def get_current_pcie_link_generation(self) -> int: + @property + def current_link_generation(self) -> int: """ Retrieve the current PCIe link generation. @@ -121,7 +125,8 @@ cdef class PciInfo: """ return nvml.device_get_curr_pcie_link_generation(self._handle) - def get_current_pcie_link_width(self) -> int: + @property + def current_link_width(self) -> int: """ Retrieve the current PCIe link width. @@ -129,7 +134,7 @@ cdef class PciInfo: """ return nvml.device_get_curr_pcie_link_width(self._handle) - def get_pcie_throughput(self, counter: PcieUtilCounter) -> int: + def get_throughput(self, counter: PcieUtilCounter) -> int: """ Retrieve PCIe utilization information, in KB/s. @@ -143,7 +148,8 @@ cdef class PciInfo: """ return nvml.device_get_pcie_throughput(self._handle, counter) - def get_pcie_replay_counter(self) -> int: + @property + def replay_counter(self) -> int: """ Retrieve the PCIe replay counter. diff --git a/cuda_core/cuda/core/system/_temperature.pxi b/cuda_core/cuda/core/system/_temperature.pxi index c56eb719d1..362fb6eca0 100644 --- a/cuda_core/cuda/core/system/_temperature.pxi +++ b/cuda_core/cuda/core/system/_temperature.pxi @@ -77,7 +77,7 @@ cdef class Temperature: def __init__(self, handle: int): self._handle = handle - def sensor( + def get_sensor( self, sensor: TemperatureSensors = TemperatureSensors.TEMPERATURE_GPU ) -> int: @@ -97,7 +97,7 @@ cdef class Temperature: """ return nvml.device_get_temperature_v(self._handle, sensor) - def threshold(self, threshold_type: TemperatureThresholds) -> int: + def get_threshold(self, threshold_type: TemperatureThresholds) -> int: """ Retrieves the temperature threshold for this GPU with the specified threshold type, in degrees Celsius. @@ -127,7 +127,7 @@ cdef class Temperature: """ return nvml.device_get_margin_temperature(self._handle) - def thermal_settings(self, sensor_index: ThermalTarget) -> ThermalSettings: + def get_thermal_settings(self, sensor_index: ThermalTarget) -> ThermalSettings: """ Used to execute a list of thermal system instructions. diff --git a/cuda_core/tests/system/test_system_device.py b/cuda_core/tests/system/test_system_device.py index 2a094d8211..fc96aa694b 100644 --- a/cuda_core/tests/system/test_system_device.py +++ b/cuda_core/tests/system/test_system_device.py @@ -198,25 +198,25 @@ def test_device_pci_info(): assert isinstance(pci_info.sub_class, int) assert 0x00 <= pci_info.sub_class <= 0xFF - assert isinstance(pci_info.get_max_pcie_link_generation(), int) - assert 0 <= pci_info.get_max_pcie_link_generation() <= 0xFF + assert isinstance(pci_info.link_generation, int) + assert 0 <= pci_info.link_generation <= 0xFF - assert isinstance(pci_info.get_gpu_max_pcie_link_generation(), int) - assert 0 <= pci_info.get_gpu_max_pcie_link_generation() <= 0xFF + assert isinstance(pci_info.max_link_generation, int) + assert 0 <= pci_info.max_link_generation <= 0xFF - assert isinstance(pci_info.get_max_pcie_link_width(), int) - assert 0 <= pci_info.get_max_pcie_link_width() <= 0xFF + assert isinstance(pci_info.max_link_width, int) + assert 0 <= pci_info.max_link_width <= 0xFF - assert isinstance(pci_info.get_current_pcie_link_generation(), int) - assert 0 <= pci_info.get_current_pcie_link_generation() <= 0xFF + assert isinstance(pci_info.current_link_generation, int) + assert 0 <= pci_info.current_link_generation <= 0xFF - assert isinstance(pci_info.get_current_pcie_link_width(), int) - assert 0 <= pci_info.get_current_pcie_link_width() <= 0xFF + assert isinstance(pci_info.current_link_width, int) + assert 0 <= pci_info.current_link_width <= 0xFF with unsupported_before(device, None): - assert isinstance(pci_info.get_pcie_throughput(system.PcieUtilCounter.PCIE_UTIL_TX_BYTES), int) + assert isinstance(pci_info.get_throughput(system.PcieUtilCounter.PCIE_UTIL_TX_BYTES), int) - assert isinstance(pci_info.get_pcie_replay_counter(), int) + assert isinstance(pci_info.replay_counter, int) def test_device_serial(): @@ -336,23 +336,23 @@ def test_device_attributes(): def test_c2c_mode_enabled(): for device in system.Device.get_all_devices(): with unsupported_before(device, None): - is_enabled = device.is_c2c_mode_enabled + is_enabled = device.is_c2c_enabled assert isinstance(is_enabled, bool) @pytest.mark.skipif(helpers.IS_WSL or helpers.IS_WINDOWS, reason="Persistence mode not supported on WSL or Windows") def test_persistence_mode_enabled(): for device in system.Device.get_all_devices(): - is_enabled = device.persistence_mode_enabled + is_enabled = device.persistence_mode assert isinstance(is_enabled, bool) try: - device.persistence_mode_enabled = False + device.persistence_mode = False except nvml.NoPermissionError as e: pytest.xfail(f"nvml.NoPermissionError: {e}") try: - assert device.persistence_mode_enabled is False + assert device.persistence_mode is False finally: - device.persistence_mode_enabled = is_enabled + device.persistence_mode = is_enabled def test_field_values(): @@ -440,11 +440,11 @@ def test_addressing_mode(): def test_display_mode(): for device in system.Device.get_all_devices(): - display_mode = device.display_mode - assert isinstance(display_mode, bool) + is_display_connected = device.is_display_connected + assert isinstance(is_display_connected, bool) - display_active = device.display_active - assert isinstance(display_active, bool) + is_display_active = device.is_display_active + assert isinstance(is_display_active, bool) def test_repair_status(): @@ -548,7 +548,7 @@ def test_auto_boosted_clocks_enabled(): # This API is supported on KEPLER and newer, but it also seems # unsupported elsewhere. with unsupported_before(device, None): - current, default = device.get_auto_boosted_clocks_enabled() + current, default = device.is_auto_boosted_clocks_enabled assert isinstance(current, bool) assert isinstance(default, bool) @@ -556,7 +556,7 @@ def test_auto_boosted_clocks_enabled(): def test_clock(): for device in system.Device.get_all_devices(): for clock_type in system.ClockType: - clock = device.clock(clock_type) + clock = device.get_clock(clock_type) assert isinstance(clock, system.ClockInfo) # These are ordered from oldest API to newest API so we test as much @@ -605,11 +605,11 @@ def test_clock(): def test_clock_event_reasons(): for device in system.Device.get_all_devices(): with unsupported_before(device, None): - reasons = device.get_current_clock_event_reasons() + reasons = device.current_clock_event_reasons assert all(isinstance(reason, system.ClocksEventReasons) for reason in reasons) with unsupported_before(device, None): - reasons = device.get_supported_clock_event_reasons() + reasons = device.supported_clock_event_reasons assert all(isinstance(reason, system.ClocksEventReasons) for reason in reasons) @@ -621,7 +621,7 @@ def test_fan(): pytest.skip("Device has no fans to test") for fan_idx in range(device.num_fans): - fan_info = device.fan(fan_idx) + fan_info = device.get_fan(fan_idx) assert isinstance(fan_info, system.FanInfo) speed = fan_info.speed @@ -650,7 +650,7 @@ def test_fan(): control_policy = fan_info.control_policy assert isinstance(control_policy, system.FanControlPolicy) finally: - fan_info.set_default_fan_speed() + fan_info.set_default_speed() def test_cooler(): @@ -677,7 +677,7 @@ def test_temperature(): temperature = device.temperature assert isinstance(temperature, system.Temperature) - sensor = temperature.sensor() + sensor = temperature.get_sensor() assert isinstance(sensor, int) assert sensor >= 0 @@ -685,7 +685,7 @@ def test_temperature(): # is also unsupported on other hardware. with unsupported_before(device, None): for threshold in list(system.TemperatureThresholds)[:-1]: - t = temperature.threshold(threshold) + t = temperature.get_threshold(threshold) assert isinstance(t, int) assert t >= 0 @@ -695,7 +695,7 @@ def test_temperature(): assert margin >= 0 with unsupported_before(device, None): - thermals = temperature.thermal_settings(system.ThermalTarget.ALL) + thermals = temperature.get_thermal_settings(system.ThermalTarget.ALL) assert isinstance(thermals, system.ThermalSettings) for i, sensor in enumerate(thermals): @@ -716,7 +716,7 @@ def test_pstates(): pstate = device.performance_state assert isinstance(pstate, system.Pstates) - pstates = device.get_supported_pstates() + pstates = device.supported_pstates assert all(isinstance(p, system.Pstates) for p in pstates) dynamic_pstates_info = device.dynamic_pstates_info