Skip to content

Commit 38c032f

Browse files
authored
Move all cuda.core.system enums into cuda.core.system.typing (#2022)
* Move all cuda.core.system enums into cuda.core.system.typing * Don't re-expose things in cuda.core.system.typing * Fix tests * Fix imports * Fix missing StrEnum test * Fix imports * Fix del and fix a test
1 parent cec0efb commit 38c032f

19 files changed

Lines changed: 465 additions & 401 deletions

cuda_core/cuda/core/_memory/_device_memory_resource.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import multiprocessing
2525
import platform # no-cython-lint
2626
import uuid
2727

28-
from ._peer_access_utils import plan_peer_access_update
28+
from cuda.core._memory._peer_access_utils import plan_peer_access_update
2929
from cuda.core._utils.cuda_utils import check_multiprocessing_start_method
3030

3131
__all__ = ['DeviceMemoryResource', 'DeviceMemoryResourceOptions']

cuda_core/cuda/core/system/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

@@ -18,6 +18,8 @@
1818
]
1919

2020

21+
from cuda.core.system import typing
22+
2123
from ._system import *
2224

2325
if CUDA_BINDINGS_NVML_IS_COMPATIBLE:

cuda_core/cuda/core/system/_clock.pxi

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,12 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
class ClockId(StrEnum):
7-
"""
8-
Clock Ids. These are used in combination with :class:`ClockType` to specify a single clock value.
9-
"""
10-
CURRENT = "current"
11-
CUSTOMER_BOOST_MAX = "customer_boost_max"
12-
# APP_CLOCK_TARGET and APP_CLOCK_DEFAULT are deprecated so not included here
13-
14-
15-
ClockId.CURRENT.__doc__ = "Current actual clock value."
16-
ClockId.CUSTOMER_BOOST_MAX.__doc__ = "OEM-defined maximum clock rate"
17-
18-
196
_CLOCK_ID_MAPPING = {
207
ClockId.CURRENT: nvml.ClockId.CURRENT,
218
ClockId.CUSTOMER_BOOST_MAX: nvml.ClockId.CUSTOMER_BOOST_MAX,
229
}
2310

2411

25-
class ClocksEventReasons(StrEnum):
26-
"""
27-
Reasons for a clocks event. These are used in combination with :class:`ClockType` to specify the reason for a clocks event.
28-
"""
29-
NONE = "none"
30-
GPU_IDLE = "gpu_idle"
31-
APPLICATIONS_CLOCKS_SETTING = "applications_clocks_setting"
32-
SW_POWER_CAP = "sw_power_cap"
33-
HW_SLOWDOWN = "hw_slowdown"
34-
SYNC_BOOST = "sync_boost"
35-
SW_THERMAL_SLOWDOWN = "sw_thermal_slowdown"
36-
HW_THERMAL_SLOWDOWN = "hw_thermal_slowdown"
37-
HW_POWER_BRAKE_SLOWDOWN = "hw_power_brake_slowdown"
38-
DISPLAY_CLOCK_SETTING = "display_clock_setting"
39-
40-
4112
_CLOCKS_EVENT_REASONS_MAPPING = {
4213
nvml.ClocksEventReasons.EVENT_REASON_NONE: ClocksEventReasons.NONE,
4314
nvml.ClocksEventReasons.EVENT_REASON_GPU_IDLE: ClocksEventReasons.GPU_IDLE,
@@ -52,16 +23,6 @@ _CLOCKS_EVENT_REASONS_MAPPING = {
5223
}
5324

5425

55-
class ClockType(StrEnum):
56-
"""
57-
Clock types. All speeds are in Mhz.
58-
"""
59-
GRAPHICS = "graphics"
60-
SM = "sm"
61-
MEMORY = "memory"
62-
VIDEO = "video"
63-
64-
6526
_CLOCK_TYPE_MAPPING = {
6627
ClockType.GRAPHICS: nvml.ClockType.CLOCK_GRAPHICS,
6728
ClockType.SM: nvml.ClockType.CLOCK_SM,

cuda_core/cuda/core/system/_cooler.pxi

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,12 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
class CoolerControl(StrEnum):
7-
"""
8-
Cooler control type.
9-
"""
10-
TOGGLE = "toggle"
11-
VARIABLE = "variable"
12-
13-
14-
CoolerControl.TOGGLE.__doc__ = """
15-
This cooler can only be toggled either ON or OFF (e.g. a switch).
16-
"""
17-
CoolerControl.VARIABLE.__doc__ = """
18-
This cooler's level can be adjusted from some minimum to some maximum (e.g. a knob).
19-
"""
20-
21-
226
_COOLER_CONTROL_MAPPING = {
237
nvml.CoolerControl.THERMAL_COOLER_SIGNAL_TOGGLE: CoolerControl.TOGGLE,
248
nvml.CoolerControl.THERMAL_COOLER_SIGNAL_VARIABLE: CoolerControl.VARIABLE,
259
}
2610

2711

28-
class CoolerTarget(StrEnum):
29-
"""
30-
Cooler target.
31-
"""
32-
NONE = "none"
33-
GPU = "gpu"
34-
MEMORY = "memory"
35-
POWER_SUPPLY = "power_supply"
36-
# THERMAL_GPU_RELATED is a composite target, so it is omitted here and will
37-
# get returned as 3 separate targets: GPU, MEMORY, and POWER_SUPPLY.
38-
39-
40-
CoolerTarget.NONE.__doc__ = "This cooler controls nothing."
41-
CoolerTarget.GPU.__doc__ = "This cooler can cool the GPU."
42-
CoolerTarget.MEMORY.__doc__ = "This cooler can cool the memory."
43-
CoolerTarget.POWER_SUPPLY.__doc__ = "This cooler can cool the power supply."
44-
45-
4612
_COOLER_TARGET_MAPPING = {
4713
nvml.CoolerTarget.THERMAL_NONE: CoolerTarget.NONE,
4814
nvml.CoolerTarget.THERMAL_GPU: CoolerTarget.GPU,

cuda_core/cuda/core/system/_device.pyx

Lines changed: 21 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,34 @@
55
from libc.stdint cimport intptr_t, uint64_t
66
from libc.math cimport ceil
77

8-
import sys
9-
if sys.version_info >= (3, 11):
10-
from enum import StrEnum
11-
else:
12-
from backports.strenum import StrEnum
138
from multiprocessing import cpu_count
149
from typing import Iterable
1510
import warnings
1611

1712
from cuda.bindings import nvml
18-
try:
19-
from cuda.bindings._internal._fast_enum import FastEnum
20-
except ImportError:
21-
from enum import IntEnum as FastEnum
2213

2314
from ._nvml_context cimport initialize
15+
from cuda.core.system.typing import (
16+
AddressingMode,
17+
AffinityScope,
18+
DeviceArch,
19+
ClockId,
20+
ClocksEventReasons,
21+
ClockType,
22+
CoolerControl,
23+
CoolerTarget,
24+
DeviceArch,
25+
EventType,
26+
FanControlPolicy,
27+
FieldId,
28+
GpuP2PCapsIndex,
29+
GpuP2PStatus,
30+
GpuTopologyLevel,
31+
InforomObject,
32+
TemperatureThresholds,
33+
ThermalController,
34+
ThermalTarget,
35+
)
2436

2537

2638
cdef object _pstate_to_int(object pstate):
@@ -57,53 +69,12 @@ include "_temperature.pxi"
5769
include "_utilization.pxi"
5870

5971

60-
class AddressingMode(StrEnum):
61-
"""
62-
Addressing mode of a device.
63-
64-
For Kepler™ or newer fully supported devices.
65-
"""
66-
HMM = "hmm"
67-
ATS = "ats"
68-
69-
70-
AddressingMode.HMM.__doc__ = """
71-
System allocated memory (``malloc``, ``mmap``) is addressable from the device
72-
(GPU), via software-based mirroring of the CPU's page tables, on the GPU.
73-
"""
74-
75-
76-
AddressingMode.ATS.__doc__ = """
77-
System allocated memory (``malloc``, ``mmap``) is addressable from the device
78-
(GPU), via Address Translation Services. This means that there is (effectively)
79-
a single set of page tables, and the CPU and GPU both use them.
80-
"""
81-
82-
8372
_ADDRESSING_MODE_MAPPING = {
8473
nvml.DeviceAddressingModeType.DEVICE_ADDRESSING_MODE_HMM: AddressingMode.HMM,
8574
nvml.DeviceAddressingModeType.DEVICE_ADDRESSING_MODE_ATS: AddressingMode.ATS,
8675
}
8776

8877

89-
class AffinityScope(StrEnum):
90-
"""
91-
Scope for affinity queries.
92-
"""
93-
NODE = "node"
94-
SOCKET = "socket"
95-
96-
97-
AffinityScope.NODE.__doc__ = """
98-
The NUMA node is the scope of the affinity query. This is the default scope.
99-
"""
100-
101-
102-
AffinityScope.SOCKET.__doc__ = """
103-
The CPU socket is the scope of the affinity query.
104-
"""
105-
106-
10778
_AFFINITY_SCOPE_MAPPING = {
10879
AffinityScope.NODE: nvml.AffinityScope.NODE,
10980
AffinityScope.SOCKET: nvml.AffinityScope.SOCKET,
@@ -132,37 +103,6 @@ _BRAND_TYPE_MAPPING = {
132103
}
133104

134105

135-
# This uses FastEnum instead of StrEnum because the ordering of the values is
136-
# meaningful, e.g. Kepler "or later"
137-
class DeviceArch(FastEnum):
138-
"""
139-
Device architecture.
140-
"""
141-
KEPLER = int(nvml.DeviceArch.KEPLER)
142-
MAXWELL = int(nvml.DeviceArch.MAXWELL)
143-
PASCAL = int(nvml.DeviceArch.PASCAL)
144-
VOLTA = int(nvml.DeviceArch.VOLTA)
145-
TURING = int(nvml.DeviceArch.TURING)
146-
AMPERE = int(nvml.DeviceArch.AMPERE)
147-
ADA = int(nvml.DeviceArch.ADA)
148-
HOPPER = int(nvml.DeviceArch.HOPPER)
149-
BLACKWELL = int(nvml.DeviceArch.BLACKWELL)
150-
UNKNOWN = int(nvml.DeviceArch.UNKNOWN)
151-
152-
153-
class GpuP2PCapsIndex(StrEnum):
154-
"""
155-
GPU peer-to-peer capabilities index.
156-
"""
157-
READ = "read"
158-
WRITE = "write"
159-
NVLINK = "nvlink"
160-
ATOMICS = "atomics"
161-
PCI = "pci"
162-
PROP = "prop"
163-
UNKNOWN = "unknown"
164-
165-
166106
_GPU_P2P_CAPS_INDEX_MAPPING = {
167107
GpuP2PCapsIndex.READ: nvml.GpuP2PCapsIndex.P2P_CAPS_INDEX_READ,
168108
GpuP2PCapsIndex.WRITE: nvml.GpuP2PCapsIndex.P2P_CAPS_INDEX_WRITE,
@@ -174,19 +114,6 @@ _GPU_P2P_CAPS_INDEX_MAPPING = {
174114
}
175115

176116

177-
class GpuP2PStatus(StrEnum):
178-
"""
179-
GPU peer-to-peer status.
180-
"""
181-
OK = "ok"
182-
CHIPSET_NOT_SUPPORTED = "chipset not supported"
183-
GPU_NOT_SUPPORTED = "GPU not supported"
184-
IOH_TOPOLOGY_NOT_SUPPORTED = "IOH topology not supported"
185-
DISABLED_BY_REGKEY = "disabled by regkey"
186-
NOT_SUPPORTED = "not supported"
187-
UNKNOWN = "unknown"
188-
189-
190117
_GPU_P2P_STATUS_MAPPING = {
191118
nvml.GpuP2PStatus.P2P_STATUS_OK: GpuP2PStatus.OK,
192119
nvml.GpuP2PStatus.P2P_STATUS_CHIPSET_NOT_SUPPORTED: GpuP2PStatus.CHIPSET_NOT_SUPPORTED,
@@ -198,18 +125,6 @@ _GPU_P2P_STATUS_MAPPING = {
198125
}
199126

200127

201-
class GpuTopologyLevel(StrEnum):
202-
"""
203-
Represents level relationships within a system between two GPUs.
204-
"""
205-
INTERNAL = "internal"
206-
SINGLE = "single"
207-
MULTIPLE = "multiple"
208-
HOSTBRIDGE = "hostbridge"
209-
NODE = "node"
210-
SYSTEM = "system"
211-
212-
213128
_GPU_TOPOLOGY_LEVEL_MAPPING = {
214129
GpuTopologyLevel.INTERNAL: nvml.GpuTopologyLevel.TOPOLOGY_INTERNAL,
215130
GpuTopologyLevel.SINGLE: nvml.GpuTopologyLevel.TOPOLOGY_SINGLE,
@@ -1204,27 +1119,8 @@ def get_p2p_status(device1: Device, device2: Device, index: GpuP2PCapsIndex | st
12041119
12051120
12061121
__all__ = [
1207-
"AddressingMode",
1208-
"AffinityScope",
1209-
"ClockId",
1210-
"ClocksEventReasons",
1211-
"ClockType",
1212-
"CoolerControl",
1213-
"CoolerTarget",
12141122
"Device",
1215-
"DeviceArch",
1216-
"EventType",
1217-
"FanControlPolicy",
1218-
"FieldId",
12191123
"get_p2p_status",
12201124
"get_topology_common_ancestor",
1221-
"GpuP2PCapsIndex",
1222-
"GpuP2PStatus",
1223-
"GpuTopologyLevel",
1224-
"InforomObject",
12251125
"NvlinkInfo",
1226-
"TemperatureThresholds",
1227-
"ThermalController",
1228-
"ThermalTarget",
1229-
"Utilization",
12301126
]

cuda_core/cuda/core/system/_event.pxi

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,6 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
class EventType(StrEnum):
7-
"""
8-
Event types that can be waited on with :class:`DeviceEvents`.
9-
"""
10-
NONE = "none"
11-
SINGLE_BIT_ECC_ERROR = "single_bit_ecc_error"
12-
DOUBLE_BIT_ECC_ERROR = "double_bit_ecc_error"
13-
PSTATE = "pstate"
14-
XID_CRITICAL_ERROR = "xid_critical_error"
15-
CLOCK = "clock"
16-
POWER_SOURCE_CHANGE = "power_source_change"
17-
MIG_CONFIG_CHANGE = "mig_config_change"
18-
SINGLE_BIT_ECC_ERROR_STORM = "single_bit_ecc_error_storm"
19-
DRAM_RETIREMENT_EVENT = "dram_retirement_event"
20-
DRAM_RETIREMENT_FAILURE = "dram_retirement_failure"
21-
NON_FATAL_POISON_ERROR = "non_fatal_poison_error"
22-
FATAL_POISON_ERROR = "fatal_poison_error"
23-
GPU_UNAVAILABLE_ERROR = "gpu_unavailable_error"
24-
GPU_RECOVERY_ACTION = "gpu_recovery_action"
25-
26-
27-
EventType.PSTATE.__doc__ = """
28-
Event about PState changes
29-
30-
On Fermi™ architecture, PState changes are also an indicator that GPU is throttling down due to
31-
no work being executed on the GPU, power capping or thermal capping. In a typical situation,
32-
Fermi-based GPU should stay in P0 for the duration of the execution of the compute process.
33-
"""
34-
35-
366
_EVENT_TYPE_MAPPING = {
377
nvml.EventType.NONE: EventType.NONE,
388
nvml.EventType.SINGLE_BIT_ECC_ERROR: EventType.SINGLE_BIT_ECC_ERROR,

cuda_core/cuda/core/system/_fan.pxi

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
class FanControlPolicy(StrEnum):
7-
"""
8-
Fan control policies.
9-
"""
10-
TEMPERATURE_CONTROLLED = "temperature_controlled"
11-
MANUAL = "manual"
12-
13-
146
_FAN_CONTROL_POLICY_MAPPING = {
157
nvml.FanControlPolicy.TEMPERATURE_CONTINUOUS_SW: FanControlPolicy.TEMPERATURE_CONTROLLED,
168
nvml.FanControlPolicy.MANUAL: FanControlPolicy.MANUAL,

cuda_core/cuda/core/system/_field_values.pxi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
FieldId = nvml.FieldId
7-
8-
96
cdef class FieldValue:
107
"""
118
Represents the data from a single field value.

0 commit comments

Comments
 (0)