Skip to content

Commit 283a821

Browse files
committed
cuda.core.system: Naming improvements suggested in #1945
1 parent b991295 commit 283a821

5 files changed

Lines changed: 66 additions & 56 deletions

File tree

cuda_core/cuda/core/system/_device.pyx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,23 @@ cdef class Device:
215215
return nvml.device_get_minor_number(self._handle)
216216

217217
@property
218-
def is_c2c_mode_enabled(self) -> bool:
218+
def is_c2c_enabled(self) -> bool:
219219
"""
220220
Whether the C2C (Chip-to-Chip) mode is enabled for this device.
221221
"""
222222
return bool(nvml.device_get_c2c_mode_info_v(self._handle).is_c2c_enabled)
223223

224224
@property
225-
def persistence_mode_enabled(self) -> bool:
225+
def persistence_mode(self) -> bool:
226226
"""
227227
Whether persistence mode is enabled for this device.
228228

229229
For Linux only.
230230
"""
231231
return nvml.device_get_persistence_mode(self._handle) == nvml.EnableState.FEATURE_ENABLED
232232

233-
@persistence_mode_enabled.setter
234-
def persistence_mode_enabled(self, enabled: bool) -> None:
233+
@persistence_mode.setter
234+
def persistence_mode(self, enabled: bool) -> None:
235235
nvml.device_set_persistence_mode(
236236
self._handle,
237237
nvml.EnableState.FEATURE_ENABLED if enabled else nvml.EnableState.FEATURE_DISABLED
@@ -409,13 +409,14 @@ cdef class Device:
409409
# CLOCK
410410
# See external class definitions in _clock.pxi
411411

412-
def clock(self, clock_type: ClockType) -> ClockInfo:
412+
def get_clock(self, clock_type: ClockType) -> ClockInfo:
413413
"""
414414
Get information about and manage a specific clock on a device.
415415
"""
416416
return ClockInfo(self._handle, clock_type)
417417

418-
def get_auto_boosted_clocks_enabled(self) -> tuple[bool, bool]:
418+
@property
419+
def is_auto_boosted_clocks_enabled(self) -> tuple[bool, bool]:
419420
"""
420421
Retrieve the current state of auto boosted clocks on a device.
421422

@@ -440,7 +441,8 @@ cdef class Device:
440441
current, default = nvml.device_get_auto_boosted_clocks_enabled(self._handle)
441442
return current == nvml.EnableState.FEATURE_ENABLED, default == nvml.EnableState.FEATURE_ENABLED
442443

443-
def get_current_clock_event_reasons(self) -> list[ClocksEventReasons]:
444+
@property
445+
def current_clock_event_reasons(self) -> list[ClocksEventReasons]:
444446
"""
445447
Retrieves the current clocks event reasons.
446448

@@ -450,7 +452,8 @@ cdef class Device:
450452
reasons[0] = nvml.device_get_current_clocks_event_reasons(self._handle)
451453
return [ClocksEventReasons(1 << reason) for reason in _unpack_bitmask(reasons)]
452454

453-
def get_supported_clock_event_reasons(self) -> list[ClocksEventReasons]:
455+
@property
456+
def supported_clock_event_reasons(self) -> list[ClocksEventReasons]:
454457
"""
455458
Retrieves supported clocks event reasons that can be returned by
456459
:meth:`get_current_clock_event_reasons`.
@@ -492,17 +495,17 @@ cdef class Device:
492495
# DISPLAY
493496

494497
@property
495-
def display_mode(self) -> bool:
498+
def is_display_connected(self) -> bool:
496499
"""
497500
The display mode for this device.
498501

499502
Indicates whether a physical display (e.g. monitor) is currently connected to
500503
any of the device's connectors.
501504
"""
502-
return True if nvml.device_get_display_mode(self._handle) == nvml.EnableState.FEATURE_ENABLED else False
505+
return nvml.device_get_display_mode(self._handle) == nvml.EnableState.FEATURE_ENABLED
503506

504507
@property
505-
def display_active(self) -> bool:
508+
def is_display_active(self) -> bool:
506509
"""
507510
The display active status for this device.
508511

@@ -512,7 +515,7 @@ cdef class Device:
512515

513516
Display can be active even when no monitor is physically attached.
514517
"""
515-
return True if nvml.device_get_display_active(self._handle) == nvml.EnableState.FEATURE_ENABLED else False
518+
return nvml.device_get_display_active(self._handle) == nvml.EnableState.FEATURE_ENABLED
516519

517520
##########################################################################
518521
# EVENTS
@@ -580,7 +583,7 @@ cdef class Device:
580583
# FAN
581584
# See external class definitions in _fan.pxi
582585
583-
def fan(self, fan: int = 0) -> FanInfo:
586+
def get_fan(self, fan: int = 0) -> FanInfo:
584587
"""
585588
Get information and manage a specific fan on a device.
586589
"""
@@ -707,7 +710,8 @@ cdef class Device:
707710
"""
708711
return GpuDynamicPstatesInfo(nvml.device_get_dynamic_pstates_info(self._handle))
709712
710-
def get_supported_pstates(self) -> list[Pstates]:
713+
@property
714+
def supported_pstates(self) -> list[Pstates]:
711715
"""
712716
Get all supported Performance States (P-States) for the device.
713717

cuda_core/cuda/core/system/_fan.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ cdef class FanInfo:
9696
"""
9797
return FanControlPolicy(nvml.device_get_fan_control_policy_v2(self._handle, self._fan))
9898

99-
def set_default_fan_speed(self):
99+
def set_default_speed(self):
100100
"""
101101
Set the speed of the fan control policy to default.
102102

cuda_core/cuda/core/system/_pci_info.pxi

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ cdef class PciInfo:
8181
"""
8282
return self._pci_info_ext.sub_class
8383

84-
def get_max_pcie_link_generation(self) -> int:
84+
@property
85+
def link_generation(self) -> int:
8586
"""
8687
Retrieve the maximum PCIe link generation possible with this device and system.
8788

@@ -93,15 +94,17 @@ cdef class PciInfo:
9394
"""
9495
return nvml.device_get_max_pcie_link_generation(self._handle)
9596

96-
def get_gpu_max_pcie_link_generation(self) -> int:
97+
@property
98+
def max_link_generation(self) -> int:
9799
"""
98100
Retrieve the maximum PCIe link generation supported by this GPU device.
99101

100102
For Fermi™ or newer fully supported devices.
101103
"""
102104
return nvml.device_get_gpu_max_pcie_link_generation(self._handle)
103105

104-
def get_max_pcie_link_width(self) -> int:
106+
@property
107+
def max_link_width(self) -> int:
105108
"""
106109
Retrieve the maximum PCIe link width possible with this device and system.
107110

@@ -113,23 +116,25 @@ cdef class PciInfo:
113116
"""
114117
return nvml.device_get_max_pcie_link_width(self._handle)
115118

116-
def get_current_pcie_link_generation(self) -> int:
119+
@property
120+
def current_link_generation(self) -> int:
117121
"""
118122
Retrieve the current PCIe link generation.
119123

120124
For Fermi™ or newer fully supported devices.
121125
"""
122126
return nvml.device_get_curr_pcie_link_generation(self._handle)
123127

124-
def get_current_pcie_link_width(self) -> int:
128+
@property
129+
def current_link_width(self) -> int:
125130
"""
126131
Retrieve the current PCIe link width.
127132

128133
For Fermi™ or newer fully supported devices.
129134
"""
130135
return nvml.device_get_curr_pcie_link_width(self._handle)
131136

132-
def get_pcie_throughput(self, counter: PcieUtilCounter) -> int:
137+
def get_throughput(self, counter: PcieUtilCounter) -> int:
133138
"""
134139
Retrieve PCIe utilization information, in KB/s.
135140

@@ -143,7 +148,8 @@ cdef class PciInfo:
143148
"""
144149
return nvml.device_get_pcie_throughput(self._handle, counter)
145150

146-
def get_pcie_replay_counter(self) -> int:
151+
@property
152+
def replay_counter(self) -> int:
147153
"""
148154
Retrieve the PCIe replay counter.
149155

cuda_core/cuda/core/system/_temperature.pxi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cdef class Temperature:
7777
def __init__(self, handle: int):
7878
self._handle = handle
7979

80-
def sensor(
80+
def get_sensor(
8181
self,
8282
sensor: TemperatureSensors = TemperatureSensors.TEMPERATURE_GPU
8383
) -> int:
@@ -97,7 +97,7 @@ cdef class Temperature:
9797
"""
9898
return nvml.device_get_temperature_v(self._handle, sensor)
9999

100-
def threshold(self, threshold_type: TemperatureThresholds) -> int:
100+
def get_threshold(self, threshold_type: TemperatureThresholds) -> int:
101101
"""
102102
Retrieves the temperature threshold for this GPU with the specified
103103
threshold type, in degrees Celsius.
@@ -127,7 +127,7 @@ cdef class Temperature:
127127
"""
128128
return nvml.device_get_margin_temperature(self._handle)
129129

130-
def thermal_settings(self, sensor_index: ThermalTarget) -> ThermalSettings:
130+
def get_thermal_settings(self, sensor_index: ThermalTarget) -> ThermalSettings:
131131
"""
132132
Used to execute a list of thermal system instructions.
133133

cuda_core/tests/system/test_system_device.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,25 @@ def test_device_pci_info():
198198
assert isinstance(pci_info.sub_class, int)
199199
assert 0x00 <= pci_info.sub_class <= 0xFF
200200

201-
assert isinstance(pci_info.get_max_pcie_link_generation(), int)
202-
assert 0 <= pci_info.get_max_pcie_link_generation() <= 0xFF
201+
assert isinstance(pci_info.link_generation, int)
202+
assert 0 <= pci_info.link_generation <= 0xFF
203203

204-
assert isinstance(pci_info.get_gpu_max_pcie_link_generation(), int)
205-
assert 0 <= pci_info.get_gpu_max_pcie_link_generation() <= 0xFF
204+
assert isinstance(pci_info.max_link_generation, int)
205+
assert 0 <= pci_info.max_link_generation <= 0xFF
206206

207-
assert isinstance(pci_info.get_max_pcie_link_width(), int)
208-
assert 0 <= pci_info.get_max_pcie_link_width() <= 0xFF
207+
assert isinstance(pci_info.max_link_width, int)
208+
assert 0 <= pci_info.max_link_width <= 0xFF
209209

210-
assert isinstance(pci_info.get_current_pcie_link_generation(), int)
211-
assert 0 <= pci_info.get_current_pcie_link_generation() <= 0xFF
210+
assert isinstance(pci_info.current_link_generation, int)
211+
assert 0 <= pci_info.current_link_generation <= 0xFF
212212

213-
assert isinstance(pci_info.get_current_pcie_link_width(), int)
214-
assert 0 <= pci_info.get_current_pcie_link_width() <= 0xFF
213+
assert isinstance(pci_info.current_link_width, int)
214+
assert 0 <= pci_info.current_link_width <= 0xFF
215215

216216
with unsupported_before(device, None):
217-
assert isinstance(pci_info.get_pcie_throughput(system.PcieUtilCounter.PCIE_UTIL_TX_BYTES), int)
217+
assert isinstance(pci_info.get_throughput(system.PcieUtilCounter.PCIE_UTIL_TX_BYTES), int)
218218

219-
assert isinstance(pci_info.get_pcie_replay_counter(), int)
219+
assert isinstance(pci_info.replay_counter, int)
220220

221221

222222
def test_device_serial():
@@ -336,23 +336,23 @@ def test_device_attributes():
336336
def test_c2c_mode_enabled():
337337
for device in system.Device.get_all_devices():
338338
with unsupported_before(device, None):
339-
is_enabled = device.is_c2c_mode_enabled
339+
is_enabled = device.is_c2c_enabled
340340
assert isinstance(is_enabled, bool)
341341

342342

343343
@pytest.mark.skipif(helpers.IS_WSL or helpers.IS_WINDOWS, reason="Persistence mode not supported on WSL or Windows")
344344
def test_persistence_mode_enabled():
345345
for device in system.Device.get_all_devices():
346-
is_enabled = device.persistence_mode_enabled
346+
is_enabled = device.persistence_mode
347347
assert isinstance(is_enabled, bool)
348348
try:
349-
device.persistence_mode_enabled = False
349+
device.persistence_mode = False
350350
except nvml.NoPermissionError as e:
351351
pytest.xfail(f"nvml.NoPermissionError: {e}")
352352
try:
353-
assert device.persistence_mode_enabled is False
353+
assert device.persistence_mode is False
354354
finally:
355-
device.persistence_mode_enabled = is_enabled
355+
device.persistence_mode = is_enabled
356356

357357

358358
def test_field_values():
@@ -440,11 +440,11 @@ def test_addressing_mode():
440440

441441
def test_display_mode():
442442
for device in system.Device.get_all_devices():
443-
display_mode = device.display_mode
444-
assert isinstance(display_mode, bool)
443+
is_display_connected = device.is_display_connected
444+
assert isinstance(is_display_connected, bool)
445445

446-
display_active = device.display_active
447-
assert isinstance(display_active, bool)
446+
is_display_active = device.is_display_active
447+
assert isinstance(is_display_active, bool)
448448

449449

450450
def test_repair_status():
@@ -548,15 +548,15 @@ def test_auto_boosted_clocks_enabled():
548548
# This API is supported on KEPLER and newer, but it also seems
549549
# unsupported elsewhere.
550550
with unsupported_before(device, None):
551-
current, default = device.get_auto_boosted_clocks_enabled()
551+
current, default = device.is_auto_boosted_clocks_enabled
552552
assert isinstance(current, bool)
553553
assert isinstance(default, bool)
554554

555555

556556
def test_clock():
557557
for device in system.Device.get_all_devices():
558558
for clock_type in system.ClockType:
559-
clock = device.clock(clock_type)
559+
clock = device.get_clock(clock_type)
560560
assert isinstance(clock, system.ClockInfo)
561561

562562
# These are ordered from oldest API to newest API so we test as much
@@ -605,11 +605,11 @@ def test_clock():
605605
def test_clock_event_reasons():
606606
for device in system.Device.get_all_devices():
607607
with unsupported_before(device, None):
608-
reasons = device.get_current_clock_event_reasons()
608+
reasons = device.current_clock_event_reasons
609609
assert all(isinstance(reason, system.ClocksEventReasons) for reason in reasons)
610610

611611
with unsupported_before(device, None):
612-
reasons = device.get_supported_clock_event_reasons()
612+
reasons = device.supported_clock_event_reasons
613613
assert all(isinstance(reason, system.ClocksEventReasons) for reason in reasons)
614614

615615

@@ -621,7 +621,7 @@ def test_fan():
621621
pytest.skip("Device has no fans to test")
622622

623623
for fan_idx in range(device.num_fans):
624-
fan_info = device.fan(fan_idx)
624+
fan_info = device.get_fan(fan_idx)
625625
assert isinstance(fan_info, system.FanInfo)
626626

627627
speed = fan_info.speed
@@ -650,7 +650,7 @@ def test_fan():
650650
control_policy = fan_info.control_policy
651651
assert isinstance(control_policy, system.FanControlPolicy)
652652
finally:
653-
fan_info.set_default_fan_speed()
653+
fan_info.set_default_speed()
654654

655655

656656
def test_cooler():
@@ -677,15 +677,15 @@ def test_temperature():
677677
temperature = device.temperature
678678
assert isinstance(temperature, system.Temperature)
679679

680-
sensor = temperature.sensor()
680+
sensor = temperature.get_sensor()
681681
assert isinstance(sensor, int)
682682
assert sensor >= 0
683683

684684
# By docs, should be supported on KEPLER or newer, but experimentally,
685685
# is also unsupported on other hardware.
686686
with unsupported_before(device, None):
687687
for threshold in list(system.TemperatureThresholds)[:-1]:
688-
t = temperature.threshold(threshold)
688+
t = temperature.get_threshold(threshold)
689689
assert isinstance(t, int)
690690
assert t >= 0
691691

@@ -695,7 +695,7 @@ def test_temperature():
695695
assert margin >= 0
696696

697697
with unsupported_before(device, None):
698-
thermals = temperature.thermal_settings(system.ThermalTarget.ALL)
698+
thermals = temperature.get_thermal_settings(system.ThermalTarget.ALL)
699699
assert isinstance(thermals, system.ThermalSettings)
700700

701701
for i, sensor in enumerate(thermals):
@@ -716,7 +716,7 @@ def test_pstates():
716716
pstate = device.performance_state
717717
assert isinstance(pstate, system.Pstates)
718718

719-
pstates = device.get_supported_pstates()
719+
pstates = device.supported_pstates
720720
assert all(isinstance(p, system.Pstates) for p in pstates)
721721

722722
dynamic_pstates_info = device.dynamic_pstates_info

0 commit comments

Comments
 (0)