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 |
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() |
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(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.
Device
public 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