dosma.Device¶
- class dosma.Device(id_or_device)[source]¶
Device class.
This class extends
cupy.Deviceand can also be used to interface withtorch.Deviceandsigpy.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.
Methods
__init__(id_or_device)Initialize self.
use()Use computing device.
Attributes
cpdeviceThe equivalent
`cupy.Device`.idThe device ordinal.
indexAlias for
self.id.ptdeviceThe equivalent
`torch.device`.spdeviceThe equivalent
`sigpy.Device`.typeType of device.
xpnumpy or cupy module for the device.