cuda.core.system.Device#

class cuda.core.system.Device(
int index: int | None = None,
uuid: bytes | str | None = None,
pci_bus_id: bytes | str | None = None,
)#

Representation of a device.

cuda.core.system.Device provides access to various pieces of metadata about devices and their topology, as provided by the NVIDIA Management Library (NVML). To use CUDA with a device, use cuda.core.Device.

Creating a device instance causes NVML to initialize the target GPU. NVML may initialize additional GPUs if the target GPU is an SLI slave.

Parameters:
  • index (int, optional) –

    Integer representing the CUDA device index to get a handle to. Valid values are between 0 and cuda.core.system.get_num_devices() - 1.

    The order in which devices are enumerated has no guarantees of consistency between reboots. For that reason, it is recommended that devices are looked up by their PCI ids or UUID.

  • uuid (bytes or str, optional) – UUID of a CUDA device to get a handle to.

  • pci_bus_id (bytes or str, optional) – PCI bus ID of a CUDA device to get a handle to.

Raises:

ValueError – If anything other than a single index, uuid or pci_bus_id are specified.

Methods

__init__(*args, **kwargs)#
clear_field_values(self, list field_ids: list[int | tuple[int, int]]) None#

Clear multiple field values from the device.

Parameters:

field_ids (list of int or tuple of (int, int)) –

List of field IDs to clear.

Each item may be either a single value from the FieldId enum, or a pair of (FieldId, scope ID).

classmethod get_all_devices(cls) Iterable[Device]#

Query the available device instances.

Returns:

An iterator over available devices.

Return type:

Iterator of Device

get_field_values(self, list field_ids: list[int | tuple[int, int]]) FieldValues#

Get multiple field values from the device.

Each value specified can raise its own exception. That exception will be raised when attempting to access the corresponding value from the returned FieldValues container.

To confirm that there are no exceptions in the entire container, call FieldValues.validate().

Parameters:

field_ids (list of int or tuple of (int, int)) –

List of field IDs to query.

Each item may be either a single value from the FieldId enum, or a pair of (FieldId, scope ID).

Returns:

Container of field values corresponding to the requested field IDs.

Return type:

FieldValues

Attributes

architecture#

DeviceArchitecture

Device architecture. For example, a Tesla V100 will report DeviceArchitecture.name == "Volta", and RTX A6000 will report DeviceArchitecture.name == "Ampere". If the device returns an architecture that is unknown to NVML then DeviceArchitecture.name == "Unknown" is reported, whereas an architecture that is unknown to cuda.core.system is reported as DeviceArchitecture.name == "Unlisted".

Type:

Device.architecture

attributes#

DeviceAttributes

Get various device attributes.

For Ampere™ or newer fully supported devices. Only available on Linux systems.

Type:

Device.attributes

bar1_memory_info#

BAR1MemoryInfo

Get information about BAR1 memory.

BAR1 is used to map the FB (device memory) so that it can be directly accessed by the CPU or by 3rd party devices (peer-to-peer on the PCIE bus).

Type:

Device.bar1_memory_info

brand#

BrandType

Brand of the device

Type:

Device.brand

cpu_affinity#

list[int]

Get a list containing the CPU indices to which the GPU is directly connected.

Examples

>>> Device(index=0).cpu_affinity
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]
Type:

Device.cpu_affinity

cuda_compute_capability#

tuple[int, int]

CUDA compute capability of the device, e.g.: (7, 0) for a Tesla V100.

Returns a tuple (major, minor).

Type:

Device.cuda_compute_capability

index#

int

The NVML index of this device.

The order in which NVML enumerates devices has no guarantees of consistency between reboots. For that reason it is recommended that devices be looked up by their PCI ids or GPU UUID.

Type:

Device.index

is_c2c_mode_enabled#

bool

Whether the C2C (Chip-to-Chip) mode is enabled for this device.

Type:

Device.is_c2c_mode_enabled

memory_info#

MemoryInfo

Object with memory information.

Type:

Device.memory_info

name#

str

Name of the device, e.g.: “Tesla V100-SXM2-32GB”

Type:

Device.name

pci_info#

PciInfo

The PCI attributes of this device.

Type:

Device.pci_info

persistence_mode_enabled#

bool

Whether persistence mode is enabled for this device.

For Linux only.

Type:

Device.persistence_mode_enabled

serial#

str

Retrieves the globally unique board serial number associated with this device’s board.

Type:

Device.serial

uuid#

str

Retrieves the globally unique immutable UUID associated with this device, as a 5 part hexadecimal string, that augments the immutable, board serial identifier.

Type:

Device.uuid