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.
In general, usage of this method is discouraged. Instead use the Device object as a context manager (with statement) to switch the current device for the specified scope.
Note that the mixed use of this method and with statement may cause surprising results in some cases:
dev0 = cupy.cuda.Device(0) dev1 = cupy.cuda.Device(1) dev1.use() with dev0: dev1.use() with dev0: pass # The current device remains 0. # Notice that the current device at the time of entering the # context is not recalled when exiting a context. # The current device still remains 0.
- __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