dosma.Device

class dosma.Device(id_or_device)[source]

Device class.

This class extends cupy.Device and can also be used to interface with torch.Device and sigpy.Device. This class contains a device type (‘cpu’ or ‘cuda’) and optional device ordinal (i.e. the id) for the device type. This class can also be constructed using only the ordinal id, where id >= 0 representing the id-th GPU, and id = -1 representing CPU. cupy must be installed to use GPUs.

The array module for the corresponding device can be obtained via device.xp. Similar to cupy.Device, the Device object can be used as a context:

>>> device = Device(1)  # gpu 1
>>> xp = device.xp  # xp is cupy.
>>> with device:
>>>     x = xp.array([1, 2, 3])
>>>     x += 1
Parameters

id_or_device (int or Device or cupy.cuda.Device) – id > 0 represents the corresponding GPUs, and id = -1 represents CPU.

Variables
  • type (str) – Device type. Either 'cpu' or 'cuda'.

  • index (int) – index = -1 represents CPU, and others represents the id_th ordinances.

Note

This class is heavily based on sigpy.Device.

__init__(id_or_device)[source]

Methods

__init__(id_or_device)

use()

Use computing device.

Attributes

cpdevice

The equivalent `cupy.Device`.

id

The device ordinal.

index

Alias for self.id.

ptdevice

The equivalent `torch.device`.

spdevice

The equivalent `sigpy.Device`.

type

Type of device.

xp

numpy or cupy module for the device.