Package ai.djl.engine

Class Engine

java.lang.Object
ai.djl.engine.Engine

public abstract class Engine extends Object
The Engine interface is the base of the provided implementation for DJL.

Any engine-specific functionality should be provided through this class. In general, it should contain methods to detect information about the usable machine hardware and to create a new NDManager and Model.

See Also:
  • Constructor Details

    • Engine

      public Engine()
  • Method Details

    • getAlternativeEngine

      public abstract Engine getAlternativeEngine()
      Returns the alternative engine if available.
      Returns:
      the alternative engine
    • getEngineName

      public abstract String getEngineName()
      Returns the name of the Engine.
      Returns:
      the name of the engine
    • getRank

      public abstract int getRank()
      Return the rank of the Engine.
      Returns:
      the rank of the engine
    • getDefaultEngineName

      public static String getDefaultEngineName()
      Returns the default Engine name.
      Returns:
      the default Engine name
    • getInstance

      public static Engine getInstance()
      Returns the default Engine.
      Returns:
      the instance of Engine
      See Also:
    • hasEngine

      public static boolean hasEngine(String engineName)
      Returns if the specified engine is available.
      Parameters:
      engineName - the name of Engine to check
      Returns:
      true if the specified engine is available
      See Also:
    • registerEngine

      public static void registerEngine(EngineProvider provider)
      Registers a EngineProvider if not registered.
      Parameters:
      provider - the EngineProvider to be registered
    • getAllEngines

      public static Set<String> getAllEngines()
      Returns a set of engine names that are loaded.
      Returns:
      a set of engine names that are loaded
    • getEngine

      public static Engine getEngine(String engineName)
      Returns the Engine with the given name.
      Parameters:
      engineName - the name of Engine to retrieve
      Returns:
      the instance of Engine
      See Also:
    • getVersion

      public abstract String getVersion()
      Returns the version of the deep learning engine.
      Returns:
      the version number of the deep learning engine
    • hasCapability

      public abstract boolean hasCapability(String capability)
      Returns whether the engine has the specified capability.
      Parameters:
      capability - the capability to retrieve
      Returns:
      true if the engine has the specified capability
    • defaultDevice

      public Device defaultDevice()
      Returns the engine's default Device.
      Returns:
      the engine's default Device
    • getDevices

      public Device[] getDevices()
      Returns an array of devices.

      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.

      Returns:
      an array of devices
    • getDevices

      public Device[] getDevices(int maxGpus)
      Returns an array of devices given the maximum number of GPUs to use.

      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.

      Parameters:
      maxGpus - the max number of GPUs to use. Use 0 for no GPUs.
      Returns:
      an array of devices
    • getGpuCount

      public int getGpuCount()
      Returns the number of GPUs available in the system.
      Returns:
      the number of GPUs available in the system
    • newSymbolBlock

      public SymbolBlock newSymbolBlock(NDManager manager)
      Construct an empty SymbolBlock for loading.
      Parameters:
      manager - the manager to manage parameters
      Returns:
      Empty SymbolBlock for static graph
    • newModel

      public abstract Model newModel(String name, Device device)
      Constructs a new model.
      Parameters:
      name - the model name
      device - the device that the model will be loaded onto
      Returns:
      a new Model instance using the network defined in block
    • newBaseManager

      public abstract NDManager newBaseManager()
      Creates a new top-level NDManager.

      NDManager will inherit default Device.

      Returns:
      a new top-level NDManager
    • newBaseManager

      public abstract NDManager newBaseManager(Device device)
      Creates a new top-level NDManager with specified Device.
      Parameters:
      device - the default Device
      Returns:
      a new top-level NDManager
    • newGradientCollector

      public GradientCollector newGradientCollector()
      Returns a new instance of GradientCollector.
      Returns:
      a new instance of GradientCollector
    • newParameterServer

      public ParameterServer newParameterServer(Optimizer optimizer)
      Returns a new instance of ParameterServer.
      Parameters:
      optimizer - the optimizer to update
      Returns:
      a new instance of ParameterServer
    • setRandomSeed

      public void setRandomSeed(int seed)
      Seeds the random number generator in DJL Engine.

      This will affect all Devices and all operators using Engine's random number generator.

      Parameters:
      seed - the seed to be fixed in Engine
    • getSeed

      public Integer getSeed()
      Returns the random seed in DJL Engine.
      Returns:
      seed the seed to be fixed in Engine
    • getDjlVersion

      public static String getDjlVersion()
      Returns the DJL API version.
      Returns:
      seed the seed to be fixed in Engine
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • debugEnvironment

      public static void debugEnvironment()
      Prints debug information about the environment for debugging environment issues.