cupy.cuda.Device#

class cupy.cuda.Device(device=None)[source]#

Object that represents a CUDA device.

This class provides some basic manipulations on CUDA devices.

It supports the context protocol. For example, the following code is an example of temporarily switching the current device:

with Device(0):
    do_something_on_device_0()

After the with statement gets done, the current device is reset to the original one.

Parameters:

device (int or cupy.cuda.Device) – Index of the device to manipulate. Be careful that the device ID (a.k.a. GPU ID) is zero origin. If it is a Device object, then its ID is used. The current device is selected by default.

Variables:

id (int) – ID of this device.

Methods

__enter__(self)#
__exit__(self, *args)#
from_pci_bus_id(type cls, pci_bus_id)#

Returns a new device instance based on a PCI Bus ID

Parameters:

pci_bus_id (str) – The string for a device in the following format [domain]:[bus]:[device].[function] where domain, bus, device, and function are all hexadecimal values.

Returns:

An instance of the Device class that has the PCI Bus ID as given by the argument pci_bus_id.

Return type:

device (Device)

synchronize(self)#

Synchronizes the current thread to the device.

use(self)#

Makes this device current.

If you want to switch a device temporarily, use the with statement.

__eq__(value, /)#

Return self==value.

__ne__(value, /)#

Return self!=value.

__lt__(value, /)#

Return self<value.

__le__(value, /)#

Return self<=value.

__gt__(value, /)#

Return self>value.

__ge__(value, /)#

Return self>=value.

Attributes

attributes#

A dictionary of device attributes.

Returns:

Dictionary of attribute values with the names as keys. The string cudaDevAttr has been trimmed from the names. For example, the attribute corresponding to the enumerated value cudaDevAttrMaxThreadsPerBlock will have key MaxThreadsPerBlock.

Return type:

attributes (dict)

compute_capability#

Compute capability of this device.

The capability is represented by a string containing the major index and the minor index. For example, compute capability 3.5 is represented by the string ‘35’.

cublas_handle#

The cuBLAS handle for this device.

The same handle is used for the same device even if the Device instance itself is different.

cusolver_handle#

The cuSOLVER handle for this device.

The same handle is used for the same device even if the Device instance itself is different.

cusolver_sp_handle#

The cuSOLVER Sphandle for this device.

The same handle is used for the same device even if the Device instance itself is different.

cusparse_handle#

The cuSPARSE handle for this device.

The same handle is used for the same device even if the Device instance itself is different.

id#

‘int’

Type:

id

mem_info#

The device memory info.

Returns:

The amount of free memory, in bytes. total: The total amount of memory, in bytes.

Return type:

free

pci_bus_id#

A string of the PCI Bus ID

Returns:

Returned identifier string for the device in the following format [domain]:[bus]:[device].[function] where domain, bus, device, and function are all hexadecimal values.

Return type:

pci_bus_id (str)