Package ai.djl
Class Device
java.lang.Object
ai.djl.Device
- Direct Known Subclasses:
Device.MultiDevice
The
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.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A combinedDevice
representing the composition of multiple other devices.static interface
Contains device type string constants. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Device
cpu()
Returns the default CPU Device.boolean
static Device
Parses a deviceName string into a device for the default engine.static Device
Parses a deviceName string into a device.int
Returns thedeviceId
of the Device.Returns the sub devices if present (such as aDevice.MultiDevice
), otherwise this.Returns the device type of the Device.static Device
gpu()
Returns the default GPU Device.static Device
gpu
(int deviceId) Returns a new instance of GPUDevice
with the specifieddeviceId
.int
hashCode()
boolean
isGpu()
Returns if theDevice
is GPU.static Device
Returns aDevice
with device type and device id.toString()
-
Field Details
-
deviceType
-
deviceId
protected int deviceId
-
-
Method Details
-
of
Returns aDevice
with device type and device id.- Parameters:
deviceType
- the device type, typically CPU or GPUdeviceId
- the deviceId on the hardware.- Returns:
- a
Device
instance
-
fromName
Parses a deviceName string into a device for the default engine.- Parameters:
deviceName
- deviceName String to parse- Returns:
- the parsed device
- See Also:
-
fromName
Parses a deviceName string into a device.The main format of a device name string is "cpu", "gpu0", or "nc1". This is simply deviceType concatenated with the deviceId. If no deviceId is used, -1 will be assumed.
There are also several simplified formats. The "-1", deviceNames corresponds to cpu. Non-negative integer deviceNames such as "0", "1", or "2" correspond to gpus with those deviceIds.
Finally, unspecified deviceNames (null or "") are parsed into the engine's default device.
- Parameters:
deviceName
- deviceName stringengine
- the engine the devie is for- Returns:
- the device
-
getDeviceType
Returns the device type of the Device.- Returns:
- the device type of the Device
-
getDeviceId
public int getDeviceId()Returns thedeviceId
of the Device.- Returns:
- the
deviceId
of the Device
-
isGpu
public boolean isGpu()Returns if theDevice
is GPU.- Returns:
- if the
Device
is GPU.
-
getDevices
Returns the sub devices if present (such as aDevice.MultiDevice
), otherwise this.- Returns:
- the sub devices if present (such as a
Device.MultiDevice
), otherwise this.
-
toString
-
equals
-
hashCode
public int hashCode() -
cpu
Returns the default CPU Device.- Returns:
- the default CPU Device
-
gpu
Returns the default GPU Device.- Returns:
- the default GPU Device
-
gpu
Returns a new instance of GPUDevice
with the specifieddeviceId
.- Parameters:
deviceId
- the GPU device ID- Returns:
- a new instance of GPU
Device
with specifieddeviceId
-