public final class Device
extends java.lang.Object
Device
class provides the specified assignment for CPU/GPU processing on the NDArray
.
Users can use this to specify whether to load/compute the NDArray
on CPU/GPU with
deviceType and deviceId provided.
Modifier and Type | Class and Description |
---|---|
static interface |
Device.Type
Contains device type string constants.
|
Modifier and Type | Method and Description |
---|---|
static Device |
cpu()
Returns the default CPU Device.
|
static Device |
defaultDevice()
Returns the default context used in Engine.
|
static Device |
defaultDevice(Engine engine)
Returns the default context used in Engine.
|
static Device |
defaultIfNull(Device device,
Engine engine)
Returns the given device or the default if it is null.
|
boolean |
equals(java.lang.Object o) |
int |
getDeviceId()
Returns the
deviceId of the Device. |
static Device[] |
getDevices()
Returns an array of devices.
|
static Device[] |
getDevices(int maxGpus)
Returns an array of devices given the maximum number of GPUs to use.
|
java.lang.String |
getDeviceType()
Returns the device type of the Device.
|
static int |
getGpuCount()
Returns the number of GPUs available in the system.
|
static Device |
gpu()
Returns the default GPU Device.
|
static Device |
gpu(int deviceId)
Returns a new instance of GPU
Device with the specified deviceId . |
int |
hashCode() |
static Device |
of(java.lang.String deviceType,
int deviceId)
Returns a
Device with device type and device id. |
java.lang.String |
toString() |
public static Device of(java.lang.String deviceType, int deviceId)
Device
with device type and device id.deviceType
- the device type, typically CPU or GPUdeviceId
- the deviceId on the hardware.Device
instancepublic java.lang.String getDeviceType()
public int getDeviceId()
deviceId
of the Device.deviceId
of the Devicepublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static Device cpu()
public static Device gpu()
public static Device gpu(int deviceId)
Device
with the specified deviceId
.deviceId
- the GPU device IDDevice
with specified deviceId
public static Device[] getDevices()
If GPUs are available, it will return an array of Device
of size
\(min(numAvailable, maxGpus)\). Else, it will return an array with a single CPU device.
public static Device[] getDevices(int maxGpus)
If GPUs are available, it will return an array of Device
of size
\(min(numAvailable, maxGpus)\). Else, it will return an array with a single CPU device.
maxGpus
- the max number of GPUs to use. Use 0 for no GPUs.public static int getGpuCount()
public static Device defaultDevice()
The default type is defined by whether the deep learning engine is recognizing GPUs available on your machine. If there is no GPU available, CPU will be used.
Device
public static Device defaultDevice(Engine engine)
The default type is defined by whether the deep learning engine is recognizing GPUs available on your machine. If there is no GPU available, CPU will be used.
engine
- the engine to retrieveDevice