Class Device
java.lang.Object
smile.deep.tensor.Device
The compute device on which a tensor is stored.
A device is an immutable value object identified by its DeviceType
and index. Native ST_Device handles are created on demand and freed
immediately, so Device instances are cheap to create and hold no
native resources.
-
Constructor Summary
ConstructorsConstructorDescriptionDevice(DeviceType type) Constructor.Device(DeviceType type, byte index) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic DeviceCPU()Returns the CPU device.static DeviceCUDA()Returns the default NVIDIA CUDA device.static DeviceCUDA(byte index) Returns the NVIDIA CUDA device.voidReleases all unoccupied cached memory.booleanstatic intReturns the number of threads used for intraop parallelism on CPU.inthashCode()byteindex()Returns the device index or ordinal, which identifies the specific compute device when there is more than one of a certain type.booleanisCPU()Returns true if the device is CPU.booleanisCUDA()Returns true if the device is CUDA.booleanisMPS()Returns true if the device is MPS.static DeviceMPS()Returns the GPU for macOS devices with Metal programming framework.static DeviceReturns the preferred (most powerful) device.static voidsetNumThreads(int n) Sets the number of threads used for intraop parallelism on CPU.toNative()Creates a new nativeST_Devicehandle for this device.toString()type()Returns the device type.
-
Constructor Details
-
Device
-
Device
Constructor.- Parameters:
type- the compute device type.index- the CUDA device index.
-
-
Method Details
-
toNative
Creates a new nativeST_Devicehandle for this device. The caller must free it withsmile_device_free.- Returns:
- a new
ST_Devicehandle.
-
equals
-
hashCode
-
toString
-
getNumThreads
public static int getNumThreads()Returns the number of threads used for intraop parallelism on CPU.- Returns:
- the number of threads used for intraop parallelism on CPU.
-
setNumThreads
public static void setNumThreads(int n) Sets the number of threads used for intraop parallelism on CPU.- Parameters:
n- the number of threads used for intraop parallelism on CPU.
-
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. -
preferredDevice
Returns the preferred (most powerful) device.- Returns:
- the preferred (most powerful) device.
-
CPU
-
MPS
Returns the GPU for macOS devices with Metal programming framework.- Returns:
- the compute device.
-
CUDA
-
CUDA
Returns the NVIDIA CUDA device.- Parameters:
index- the CUDA device index.- Returns:
- the compute 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.
-