Class Device

java.lang.Object
smile.deep.tensor.Device

public class Device extends Object
The compute device on which a tensor is stored.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    Device(DeviceType type, byte index)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.bytedeco.pytorch.Device
    Returns the PyTorch device object.
    static Device
    CPU()
    Returns the CPU device.
    static Device
    Returns the default NVIDIA CUDA device.
    static Device
    CUDA(byte index)
    Returns the NVIDIA CUDA device.
    void
    Releases all unoccupied cached memory.
    boolean
    equals(Object other)
     
    byte
    Returns the device index or ordinal, which identifies the specific compute device when there is more than one of a certain type.
    boolean
    Returns true if the device is CPU.
    boolean
    Returns true if the device is CUDA.
    boolean
    Returns true if the device is MPS.
    static Device
    MPS()
    Returns the GPU for macOS devices with Metal programming framework.
    static Device
    Returns the preferred (most powerful) device.
    void
    Sets Tensor to be allocated on this device.
     
    Returns the device type.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Device

      public Device(DeviceType type)
      Constructor.
      Parameters:
      type - the compute device type.
    • Device

      public Device(DeviceType type, byte index)
      Constructor.
      Parameters:
      type - the compute device type.
      index - the CUDA device index.
  • Method Details

    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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.
    • asTorch

      public org.bytedeco.pytorch.Device asTorch()
      Returns the PyTorch device object.
      Returns:
      the PyTorch device object.
    • preferredDevice

      public static Device preferredDevice()
      Returns the preferred (most powerful) device.
      Returns:
      the preferred (most powerful) device.
    • CPU

      public static Device CPU()
      Returns the CPU device.
      Returns:
      the compute device.
    • MPS

      public static Device MPS()
      Returns the GPU for macOS devices with Metal programming framework.
      Returns:
      the compute device.
    • CUDA

      public static Device CUDA()
      Returns the default NVIDIA CUDA device.
      Returns:
      the compute device.
    • CUDA

      public static Device CUDA(byte index)
      Returns the NVIDIA CUDA device.
      Parameters:
      index - the CUDA device index.
      Returns:
      the compute device.
    • setDefaultDevice

      public void setDefaultDevice()
      Sets Tensor to be allocated on this device. This does not affect factory function calls which are called with an explicit device argument. Factory calls will be performed as if they were passed device as an argument.

      The default device is initially CPU. If you set the default tensor device to another device (e.g., CUDA) without a device index, tensors will be allocated on whatever the current device for the device type.

    • type

      public DeviceType type()
      Returns the device type.
      Returns:
      the 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.