Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions cuda_core/cuda/core/system/_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,23 @@ 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.

For Linux only.
"""
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
Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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`.
Expand Down Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion cuda_core/cuda/core/system/_fan.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
20 changes: 13 additions & 7 deletions cuda_core/cuda/core/system/_pci_info.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -93,15 +94,17 @@ 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.

For Fermi™ or newer fully supported devices.
"""
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.

Expand All @@ -113,23 +116,25 @@ 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.

For Fermi™ or newer fully supported devices.
"""
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.

For Fermi™ or newer fully supported devices.
"""
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.

Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions cuda_core/cuda/core/system/_temperature.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
62 changes: 31 additions & 31 deletions cuda_core/tests/system/test_system_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -548,15 +548,15 @@ 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)


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
Expand Down Expand Up @@ -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)


Expand All @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -677,15 +677,15 @@ 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

# By docs, should be supported on KEPLER or newer, but experimentally,
# 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

Expand All @@ -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):
Expand All @@ -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
Expand Down
Loading