Package smile.deep.tensor
Class Device
java.lang.Object
smile.deep.tensor.Device
The compute device on which a tensor is stored.
-
Constructor Summary
ConstructorDescriptionDevice
(DeviceType type) Constructor.Device
(DeviceType type, byte index) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionorg.bytedeco.pytorch.Device
asTorch()
Returns the PyTorch device object.static Device
CPU()
Returns the CPU device.static Device
CUDA()
Returns the default NVIDIA CUDA device.static Device
CUDA
(byte index) Returns the NVIDIA CUDA device.void
Releases all unoccupied cached memory.boolean
byte
index()
Returns the device index or ordinal, which identifies the specific compute device when there is more than one of a certain type.boolean
isCPU()
Returns true if the device is CPU.boolean
isCUDA()
Returns true if the device is CUDA.boolean
isMPS()
Returns true if the device is MPS.static Device
MPS()
Returns the GPU for macOS devices with Metal programming framework.static Device
Returns the preferred (most powerful) device.void
Sets Tensor to be allocated on this device.toString()
type()
Returns the device type.
-
Constructor Details
-
Device
Constructor.- Parameters:
type
- the compute device type.
-
Device
Constructor.- Parameters:
type
- the compute device type.index
- the CUDA device index.
-
-
Method Details
-
equals
-
toString
-
isCUDA
public boolean isCUDA()Returns true if the device is CUDA.- Returns:
- true if the device is CUDA.
-
isCPU
public boolean isCPU()Returns true if the device is CPU.- Returns:
- true if the device is CPU.
-
isMPS
public boolean isMPS()Returns true if the device is MPS.- Returns:
- true if the device is MPS.
-
emptyCache
public void emptyCache()Releases all unoccupied cached memory. -
asTorch
public org.bytedeco.pytorch.Device asTorch()Returns the PyTorch device object.- Returns:
- the PyTorch device object.
-
preferredDevice
Returns the preferred (most powerful) device.- Returns:
- the preferred (most powerful) device.
-
CPU
Returns the CPU device.- Returns:
- the compute device.
-
MPS
Returns the GPU for macOS devices with Metal programming framework.- Returns:
- the compute device.
-
CUDA
Returns the default NVIDIA CUDA device.- Returns:
- the compute device.
-
CUDA
Returns the NVIDIA CUDA device.- Parameters:
index
- the CUDA device index.- Returns:
- the compute device.
-
setDefaultDevice
public void setDefaultDevice()Sets Tensor to be allocated on this device. This does not affect factory function calls which are called with an explicit device argument. Factory calls will be performed as if they were passed device as an argument.The default device is initially CPU. If you set the default tensor device to another device (e.g., CUDA) without a device index, tensors will be allocated on whatever the current device for the device type.
-
type
Returns the device type.- Returns:
- the device type.
-
index
public byte index()Returns the device index or ordinal, which identifies the specific compute device when there is more than one of a certain type. The device index is optional, and in its defaulted state represents (abstractly) "the current device". Further, there are two constraints on the value of the device index, if one is explicitly stored: 1. A negative index represents the current device, a non-negative index represents a specific, concrete device, 2. When the device type is CPU, the device index must be zero.- Returns:
- the device index.
-