Package ai.djl.engine
Class Engine
- java.lang.Object
-
- ai.djl.engine.Engine
-
public abstract class Engine extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Engine()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static voiddebugEnvironment()Prints debug information about the environment for debugging environment issues.DevicedefaultDevice()Returns the engine's defaultDevice.static java.util.Set<java.lang.String>getAllEngines()Returns a set of engine names that are loaded.abstract EnginegetAlternativeEngine()Returns the alternativeengineif available.static java.lang.StringgetDefaultEngineName()Returns the default Engine name.Device[]getDevices()Returns an array of devices.Device[]getDevices(int maxGpus)Returns an array of devices given the maximum number of GPUs to use.static java.lang.StringgetDjlVersion()Returns the DJL API version.static EnginegetEngine(java.lang.String engineName)Returns theEnginewith the given name.abstract java.lang.StringgetEngineName()Returns the name of the Engine.intgetGpuCount()Returns the number of GPUs available in the system.static EnginegetInstance()Returns the default Engine.abstract intgetRank()Return the rank of theEngine.java.lang.IntegergetSeed()Returns the random seed in DJL Engine.abstract java.lang.StringgetVersion()Returns the version of the deep learning engine.abstract booleanhasCapability(java.lang.String capability)Returns whether the engine has the specified capability.static booleanhasEngine(java.lang.String engineName)Returns if the specified engine is available.abstract NDManagernewBaseManager()Creates a new top-levelNDManager.abstract NDManagernewBaseManager(Device device)GradientCollectornewGradientCollector()Returns a new instance ofGradientCollector.abstract ModelnewModel(java.lang.String name, Device device)Constructs a new model.ParameterServernewParameterServer(Optimizer optimizer)Returns a new instance ofParameterServer.SymbolBlocknewSymbolBlock(NDManager manager)Construct an empty SymbolBlock for loading.static voidregisterEngine(EngineProvider provider)Registers aEngineProviderif not registered.voidsetRandomSeed(int seed)Seeds the random number generator in DJL Engine.java.lang.StringtoString()
-
-
-
Method Detail
-
getAlternativeEngine
public abstract Engine getAlternativeEngine()
Returns the alternativeengineif available.- Returns:
- the alternative
engine
-
getEngineName
public abstract java.lang.String getEngineName()
Returns the name of the Engine.- Returns:
- the name of the engine
-
getRank
public abstract int getRank()
Return the rank of theEngine.- Returns:
- the rank of the engine
-
getDefaultEngineName
public static java.lang.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:
EngineProvider
-
hasEngine
public static boolean hasEngine(java.lang.String engineName)
Returns if the specified engine is available.- Parameters:
engineName- the name of Engine to check- Returns:
trueif the specified engine is available- See Also:
EngineProvider
-
registerEngine
public static void registerEngine(EngineProvider provider)
Registers aEngineProviderif not registered.- Parameters:
provider- theEngineProviderto be registered
-
getAllEngines
public static java.util.Set<java.lang.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(java.lang.String engineName)
Returns theEnginewith the given name.- Parameters:
engineName- the name of Engine to retrieve- Returns:
- the instance of
Engine - See Also:
EngineProvider
-
getVersion
public abstract java.lang.String getVersion()
Returns the version of the deep learning engine.- Returns:
- the version number of the deep learning engine
-
hasCapability
public abstract boolean hasCapability(java.lang.String capability)
Returns whether the engine has the specified capability.- Parameters:
capability- the capability to retrieve- Returns:
trueif the engine has the specified capability
-
defaultDevice
public Device defaultDevice()
Returns the engine's defaultDevice.- 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
Deviceof 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
Deviceof 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
SymbolBlockfor static graph
-
newModel
public abstract Model newModel(java.lang.String name, Device device)
Constructs a new model.- Parameters:
name- the model namedevice- 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()
- Returns:
- a new top-level
NDManager
-
newBaseManager
public abstract NDManager newBaseManager(Device device)
- Parameters:
device- the defaultDevice- Returns:
- a new top-level
NDManager
-
newGradientCollector
public GradientCollector newGradientCollector()
Returns a new instance ofGradientCollector.- Returns:
- a new instance of
GradientCollector
-
newParameterServer
public ParameterServer newParameterServer(Optimizer optimizer)
Returns a new instance ofParameterServer.- 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 java.lang.Integer getSeed()
Returns the random seed in DJL Engine.- Returns:
- seed the seed to be fixed in Engine
-
getDjlVersion
public static java.lang.String getDjlVersion()
Returns the DJL API version.- Returns:
- seed the seed to be fixed in Engine
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
debugEnvironment
public static void debugEnvironment()
Prints debug information about the environment for debugging environment issues.
-
-