public 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.
|
| Constructor and Description |
|---|
Device(java.lang.String deviceType)
Creates a
Device with basic information. |
Device(java.lang.String deviceType,
int deviceId)
Creates a
Device with basic information. |
| 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 |
defaultIfNull(Device device)
Returns the given device or the default if it is null.
|
static Device |
defaultIfNull(Device device,
Device def)
Returns the given device or the passed in default if it is null.
|
boolean |
equals(java.lang.Object o) |
int |
getDeviceId()
Returns the
deviceId of the Device. |
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 int |
getGpuCount(java.lang.String engineName)
Returns the number of GPUs available with specified framework.
|
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() |
java.lang.String |
toString() |
public Device(java.lang.String deviceType)
Device with basic information.deviceType - the device type, typically CPU or GPU choose which GPU to process the
NDArraypublic Device(java.lang.String deviceType,
int deviceId)
Device with basic information.deviceType - the device type, typically CPU or GPUdeviceId - the deviceId on the hardware. For example, if you have multiple GPUs, you can
choose which GPU to process the NDArraypublic java.lang.String getDeviceType()
public int getDeviceId()
deviceId of the Device.deviceId of the Devicepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic 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 deviceIdpublic 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 usepublic static int getGpuCount()
public static int getGpuCount(java.lang.String engineName)
engineName - the name of engine to retrievepublic static Device defaultDevice()
The default type is defined by whether the Deep Learning framework is recognizing GPUs available on your machine. If there is no GPU available, CPU will be used.
Devicepublic static Device defaultIfNull(Device device)
device - the device to try to returnpublic static Device defaultIfNull(Device device, Device def)
device - the device to try to returndef - the default device to return if device is null