Class DefaultOpExecutioner
- java.lang.Object
-
- org.nd4j.linalg.api.ops.executioner.DefaultOpExecutioner
-
- All Implemented Interfaces:
OpExecutioner
public abstract class DefaultOpExecutioner extends Object implements OpExecutioner
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.nd4j.linalg.api.ops.executioner.OpExecutioner
OpExecutioner.ExecutionerType, OpExecutioner.ProfilingMode
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicBooleandebugprotected OpExecutioner.ProfilingModeprofilingModeprotected AtomicBooleanverbose
-
Constructor Summary
Constructors Constructor Description DefaultOpExecutioner()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description INDArray[]allocateOutputArrays(CustomOp op)Equivalent to callistatic List<String>allOpenWorkspaces()StringarrayInfo(INDArray arr)INDArraybitmapDecode(INDArray encoded, INDArray target)INDArraybitmapEncode(INDArray indArray, double threshold)longbitmapEncode(INDArray indArray, INDArray target, double threshold)This method returns number of elements affected by encoderOpContextbuildContext()This method returns OpContext which can be used (and reused) to execute custom opsList<LongShapeDescriptor>calculateOutputShape(CustomOp op)List<LongShapeDescriptor>calculateOutputShape(CustomOp op, OpContext opContext)protected voidcheckForCompression(Op op)protected voidcheckForWorkspaces(CustomOp op, OpContext oc)protected voidcheckForWorkspaces(Op op, OpContext oc)protected voidcheckWorkspace(String opName, INDArray array)voidcommit()This method ensures all operations that supposed to be executed at this moment, are executed and finished.DataBuffercreateConstantBuffer(double[] values, DataType desiredType)DataBuffercreateConstantBuffer(float[] values, DataType desiredType)DataBuffercreateConstantBuffer(int[] values, DataType desiredType)DataBuffercreateConstantBuffer(long[] values, DataType desiredType)This method returns constant buffer for the given jvm arrayDataBuffercreateShapeInfo(long[] shape, long[] stride, long elementWiseStride, char order, DataType dtype, boolean empty)This method returns shapeInfo DataBufferDataBuffercreateShapeInfo(long[] shape, long[] stride, long elementWiseStride, char order, DataType dtype, long extras)voidenableDebugMode(boolean reallyEnable)voidenableVerboseMode(boolean reallyEnable)voidexec(List<Aggregate> batch)This method takes arbitrary sized list of aggregates, and packs them into batchesvoidexec(Aggregate op)<T extends Aggregate>
voidexec(Batch<T> batch)This method executes previously built batchabstract INDArrayexec(BroadcastOp broadcast)Execute a broadcast op, possibly along one or more dimensionsINDArray[]exec(CustomOp op)INDArray[]exec(CustomOp op, OpContext context)This method executes op with given contextvoidexec(GridOp op)Execute GridOpabstract INDArrayexec(Variance accumulation)Execute an variance accumulation op, possibly along one or more dimensionsabstract INDArrayexec(IndexAccumulation op)Execute an index accumulation along one or more dimensionsvoidexec(MetaOp op)Execute MetaOpabstract INDArrayexec(Op op)Execute the operationabstract INDArrayexec(Op op, OpContext opContext)Execute the operationINDArrayexec(RandomOp op)This method executes specified RandomOp using default RNG available via Nd4j.getRandom()abstract INDArrayexec(RandomOp op, Random rng)This method executes specific RandomOp against specified RNGabstract INDArrayexec(ReduceOp op)Execute a reduceOp, possibly along one or more dimensionsabstract INDArrayexec(ScalarOp op)Execute ScalarOpBroadcastOpexecAndReturn(BroadcastOp op)Execute and return the result from a vector opCustomOpexecAndReturn(CustomOp op)This method executes given CustomOp PLEASE NOTE: You're responsible for input/output validationVarianceexecAndReturn(Variance op)Execute and return the result from an accumulationIndexAccumulationexecAndReturn(IndexAccumulation op)Execute and return the result from an index accumulationOpexecAndReturn(Op op)Execute and return a result ndarray from the given opReduceOpexecAndReturn(ReduceOp op)Execute and return the result from an accumulationScalarOpexecAndReturn(ScalarOp op)Execute and return the result from a scalar opTransformOpexecAndReturn(TransformOp op)Execute a TransformOp and return the resultMap<String,INDArray>executeGraph(long id, Map<String,INDArray> map, Map<String,Integer> reverseMap)protected static StringfirstX(INDArray array, int x)voidforgetGraph(long id)Map<String,CustomOpDescriptor>getCustomOperations()This method returns names of all custom operations available in current backend, and their number of input/output argumentsPropertiesgetEnvironmentInformation()This method return set of key/value and key/key/value objects, describing current environmentStringgetLastOp()This method returns opName of the last invoked opOpExecutioner.ProfilingModegetProfilingMode()Deprecated.StringgetString(DataBuffer buffer, long index)This method extracts String from Utf8BufferTADManagergetTADManager()This method returns TADManager instance used for this OpExecutionerINDArraygetX(Op op, OpContext oc)INDArraygetY(Op op, OpContext oc)INDArraygetZ(Op op, OpContext oc)INDArrayStatisticsinspectArray(INDArray array)protected voidinterceptIntDataType(Op op)This method checks if any Op operand has data opType of INT, and throws exception if any.booleanisDebug()This method returns true if debug mode is enabled, false otherwisebooleanisExperimentalMode()booleanisVerbose()This method returns true if verbose mode is enabled, false otherwiseStringopInfoString(Op op, Optional<int[]> dimensions)Get the information about the op in a String representation, for throwing more useful exceptions (mainly for debugging)voidprintEnvironmentInformation()This method prints out environmental information returned by getEnvironmentInformation() methodlongprofilingConfigurableHookIn(CustomOp op, OpContext oc)longprofilingConfigurableHookIn(Op op, DataBuffer... tadBuffers)voidprofilingConfigurableHookOut(CustomOp op, OpContext oc, long timeStart)voidprofilingConfigurableHookOut(Op op, OpContext oc, long timeStart)longprofilingHookIn(CustomOp op, OpContext oc)Deprecated.longprofilingHookIn(Op op, DataBuffer... tadBuffers)Deprecated.voidprofilingHookOut(CustomOp op, OpContext oc, long timeStart)Deprecated.voidprofilingHookOut(Op op, OpContext oc, long timeStart)Deprecated.voidpush()This method ensures all operations that supposed to be executed at this moment, are executed.voidregisterGraph(long id, org.bytedeco.javacpp.Pointer graph)voidscatterUpdate(ScatterUpdate.UpdateOp op, INDArray array, INDArray indices, INDArray updates, int[] axis)Temporary hookvoidsetElementsThreshold(int threshold)This method allows to set desired number of elements per thread, for performance optimization purposes.voidsetProfilingConfig(ProfilerConfig config)This method stores specified configuration.voidsetProfilingMode(OpExecutioner.ProfilingMode mode)Deprecated.voidsetTadThreshold(int threshold)This method allows to set desired number of sub-arrays per thread, for performance optimization purposes.voidsetX(INDArray x, Op op, OpContext oc)voidsetY(INDArray y, Op op, OpContext oc)voidsetZ(INDArray z, Op op, OpContext oc)TadPacktadShapeInfoAndOffsets(INDArray array, int[] dimension)This method returns host/device tad buffersINDArraythresholdDecode(INDArray encoded, INDArray target)This method decodes thresholds array, and puts it into target arrayINDArraythresholdEncode(INDArray input, double threshold)This method encodes array as thresholds, updating input array at the same timeINDArraythresholdEncode(INDArray input, double threshold, Integer boundary)This method encodes array as thresholds, updating input array at the same timeOpExecutioner.ExecutionerTypetype()This method returns type for this executioner instanceintuseCount(DataBuffer buffer)This method returns reference use count from the Bufferstatic voidvalidateDataType(DataType expectedType, Object op, INDArray... operands)static voidvalidateDataType(DataType expectedType, Op op)Validate the data types for the given operation
-
-
-
Field Detail
-
profilingMode
protected OpExecutioner.ProfilingMode profilingMode
-
verbose
protected AtomicBoolean verbose
-
debug
protected AtomicBoolean debug
-
-
Method Detail
-
checkForCompression
protected void checkForCompression(Op op)
-
getLastOp
public String getLastOp()
Description copied from interface:OpExecutionerThis method returns opName of the last invoked op- Specified by:
getLastOpin interfaceOpExecutioner- Returns:
-
interceptIntDataType
protected void interceptIntDataType(Op op)
This method checks if any Op operand has data opType of INT, and throws exception if any.- Parameters:
op-
-
exec
public abstract INDArray exec(Op op)
Description copied from interface:OpExecutionerExecute the operation- Specified by:
execin interfaceOpExecutioner- Parameters:
op- the operation to execute
-
exec
public abstract INDArray exec(Op op, OpContext opContext)
Description copied from interface:OpExecutionerExecute the operation- Specified by:
execin interfaceOpExecutioner- Parameters:
op- the operation to execute
-
execAndReturn
public Op execAndReturn(Op op)
Description copied from interface:OpExecutionerExecute and return a result ndarray from the given op- Specified by:
execAndReturnin interfaceOpExecutioner- Parameters:
op- the operation to execute- Returns:
- the result from the operation
-
execAndReturn
public TransformOp execAndReturn(TransformOp op)
Description copied from interface:OpExecutionerExecute a TransformOp and return the result- Specified by:
execAndReturnin interfaceOpExecutioner- Parameters:
op- the operation to execute
-
execAndReturn
public ReduceOp execAndReturn(ReduceOp op)
Description copied from interface:OpExecutionerExecute and return the result from an accumulation- Specified by:
execAndReturnin interfaceOpExecutioner- Parameters:
op- the operation to execute- Returns:
- the accumulated result
-
execAndReturn
public Variance execAndReturn(Variance op)
Description copied from interface:OpExecutionerExecute and return the result from an accumulation- Specified by:
execAndReturnin interfaceOpExecutioner- Parameters:
op- the operation to execute- Returns:
- the accumulated result
-
execAndReturn
public ScalarOp execAndReturn(ScalarOp op)
Description copied from interface:OpExecutionerExecute and return the result from a scalar op- Specified by:
execAndReturnin interfaceOpExecutioner- Parameters:
op- the operation to execute- Returns:
- the accumulated result
-
execAndReturn
public IndexAccumulation execAndReturn(IndexAccumulation op)
Description copied from interface:OpExecutionerExecute and return the result from an index accumulation- Specified by:
execAndReturnin interfaceOpExecutioner- Parameters:
op- the index accumulation operation to execute- Returns:
- the accumulated index
-
execAndReturn
public BroadcastOp execAndReturn(BroadcastOp op)
Description copied from interface:OpExecutionerExecute and return the result from a vector op- Specified by:
execAndReturnin interfaceOpExecutioner
-
exec
public INDArray[] exec(CustomOp op)
- Specified by:
execin interfaceOpExecutioner
-
exec
public abstract INDArray exec(ReduceOp op)
Description copied from interface:OpExecutionerExecute a reduceOp, possibly along one or more dimensions- Specified by:
execin interfaceOpExecutioner- Parameters:
op- the reduceOp- Returns:
- the reduceOp op
-
exec
public abstract INDArray exec(Variance accumulation)
Description copied from interface:OpExecutionerExecute an variance accumulation op, possibly along one or more dimensions- Specified by:
execin interfaceOpExecutioner- Parameters:
accumulation- the accumulation- Returns:
- the accmulation op
-
exec
public abstract INDArray exec(IndexAccumulation op)
Description copied from interface:OpExecutionerExecute an index accumulation along one or more dimensions- Specified by:
execin interfaceOpExecutioner- Parameters:
op- the index accumulation operation- Returns:
- result
-
exec
public abstract INDArray exec(BroadcastOp broadcast)
Description copied from interface:OpExecutionerExecute a broadcast op, possibly along one or more dimensions- Specified by:
execin interfaceOpExecutioner- Parameters:
broadcast- the accumulation- Returns:
- the broadcast op
-
exec
public void exec(MetaOp op)
Description copied from interface:OpExecutionerExecute MetaOp- Specified by:
execin interfaceOpExecutioner
-
exec
public void exec(GridOp op)
Description copied from interface:OpExecutionerExecute GridOp- Specified by:
execin interfaceOpExecutioner
-
exec
public <T extends Aggregate> void exec(Batch<T> batch)
Description copied from interface:OpExecutionerThis method executes previously built batch- Specified by:
execin interfaceOpExecutioner
-
exec
public void exec(Aggregate op)
- Specified by:
execin interfaceOpExecutioner
-
exec
public abstract INDArray exec(ScalarOp op)
Description copied from interface:OpExecutionerExecute ScalarOp- Specified by:
execin interfaceOpExecutioner- Returns:
-
exec
public void exec(List<Aggregate> batch)
Description copied from interface:OpExecutionerThis method takes arbitrary sized list of aggregates, and packs them into batches- Specified by:
execin interfaceOpExecutioner
-
exec
public INDArray exec(RandomOp op)
This method executes specified RandomOp using default RNG available via Nd4j.getRandom()- Specified by:
execin interfaceOpExecutioner- Parameters:
op-
-
exec
public abstract INDArray exec(RandomOp op, Random rng)
This method executes specific RandomOp against specified RNG- Specified by:
execin interfaceOpExecutioner- Parameters:
op-rng-
-
setProfilingMode
@Deprecated public void setProfilingMode(OpExecutioner.ProfilingMode mode)
Deprecated.Description copied from interface:OpExecutionerThis method specifies desired profiling mode- Specified by:
setProfilingModein interfaceOpExecutioner
-
setProfilingConfig
public void setProfilingConfig(ProfilerConfig config)
Description copied from interface:OpExecutionerThis method stores specified configuration.- Specified by:
setProfilingConfigin interfaceOpExecutioner
-
getProfilingMode
@Deprecated public OpExecutioner.ProfilingMode getProfilingMode()
Deprecated.Description copied from interface:OpExecutionerThs method returns current profiling- Specified by:
getProfilingModein interfaceOpExecutioner- Returns:
-
profilingHookIn
@Deprecated public long profilingHookIn(Op op, DataBuffer... tadBuffers)
Deprecated.
-
profilingHookIn
@Deprecated public long profilingHookIn(CustomOp op, OpContext oc)
Deprecated.
-
profilingHookOut
@Deprecated public void profilingHookOut(Op op, OpContext oc, long timeStart)
Deprecated.
-
profilingHookOut
@Deprecated public void profilingHookOut(CustomOp op, OpContext oc, long timeStart)
Deprecated.
-
profilingConfigurableHookIn
public long profilingConfigurableHookIn(Op op, DataBuffer... tadBuffers)
-
profilingConfigurableHookOut
public void profilingConfigurableHookOut(Op op, OpContext oc, long timeStart)
-
profilingConfigurableHookOut
public void profilingConfigurableHookOut(CustomOp op, OpContext oc, long timeStart)
-
validateDataType
public static void validateDataType(DataType expectedType, Op op)
Validate the data types for the given operation- Parameters:
expectedType-op-
-
validateDataType
public static void validateDataType(DataType expectedType, Object op, INDArray... operands)
-
getTADManager
public TADManager getTADManager()
Description copied from interface:OpExecutionerThis method returns TADManager instance used for this OpExecutioner- Specified by:
getTADManagerin interfaceOpExecutioner- Returns:
-
getEnvironmentInformation
public Properties getEnvironmentInformation()
This method return set of key/value and key/key/value objects, describing current environment- Specified by:
getEnvironmentInformationin interfaceOpExecutioner- Returns:
-
printEnvironmentInformation
public void printEnvironmentInformation()
Description copied from interface:OpExecutionerThis method prints out environmental information returned by getEnvironmentInformation() method- Specified by:
printEnvironmentInformationin interfaceOpExecutioner
-
push
public void push()
Description copied from interface:OpExecutionerThis method ensures all operations that supposed to be executed at this moment, are executed.- Specified by:
pushin interfaceOpExecutioner
-
commit
public void commit()
Description copied from interface:OpExecutionerThis method ensures all operations that supposed to be executed at this moment, are executed and finished.- Specified by:
commitin interfaceOpExecutioner
-
thresholdEncode
public INDArray thresholdEncode(INDArray input, double threshold)
Description copied from interface:OpExecutionerThis method encodes array as thresholds, updating input array at the same time- Specified by:
thresholdEncodein interfaceOpExecutioner- Returns:
- encoded array is returned
-
thresholdEncode
public INDArray thresholdEncode(INDArray input, double threshold, Integer boundary)
Description copied from interface:OpExecutionerThis method encodes array as thresholds, updating input array at the same time- Specified by:
thresholdEncodein interfaceOpExecutioner- Returns:
- encoded array is returned
-
thresholdDecode
public INDArray thresholdDecode(INDArray encoded, INDArray target)
Description copied from interface:OpExecutionerThis method decodes thresholds array, and puts it into target array- Specified by:
thresholdDecodein interfaceOpExecutioner- Returns:
- target is returned
-
bitmapEncode
public long bitmapEncode(INDArray indArray, INDArray target, double threshold)
Description copied from interface:OpExecutionerThis method returns number of elements affected by encoder- Specified by:
bitmapEncodein interfaceOpExecutioner- Returns:
-
bitmapEncode
public INDArray bitmapEncode(INDArray indArray, double threshold)
- Specified by:
bitmapEncodein interfaceOpExecutioner- Returns:
-
bitmapDecode
public INDArray bitmapDecode(INDArray encoded, INDArray target)
- Specified by:
bitmapDecodein interfaceOpExecutioner- Returns:
-
getCustomOperations
public Map<String,CustomOpDescriptor> getCustomOperations()
Description copied from interface:OpExecutionerThis method returns names of all custom operations available in current backend, and their number of input/output arguments- Specified by:
getCustomOperationsin interfaceOpExecutioner- Returns:
-
execAndReturn
public CustomOp execAndReturn(CustomOp op)
Description copied from interface:OpExecutionerThis method executes given CustomOp PLEASE NOTE: You're responsible for input/output validation- Specified by:
execAndReturnin interfaceOpExecutioner
-
calculateOutputShape
public List<LongShapeDescriptor> calculateOutputShape(CustomOp op)
- Specified by:
calculateOutputShapein interfaceOpExecutioner
-
calculateOutputShape
public List<LongShapeDescriptor> calculateOutputShape(CustomOp op, OpContext opContext)
- Specified by:
calculateOutputShapein interfaceOpExecutioner
-
allocateOutputArrays
public INDArray[] allocateOutputArrays(CustomOp op)
Description copied from interface:OpExecutionerEquivalent to calli- Specified by:
allocateOutputArraysin interfaceOpExecutioner
-
enableDebugMode
public void enableDebugMode(boolean reallyEnable)
- Specified by:
enableDebugModein interfaceOpExecutioner
-
enableVerboseMode
public void enableVerboseMode(boolean reallyEnable)
- Specified by:
enableVerboseModein interfaceOpExecutioner
-
registerGraph
public void registerGraph(long id, org.bytedeco.javacpp.Pointer graph)- Specified by:
registerGraphin interfaceOpExecutioner
-
executeGraph
public Map<String,INDArray> executeGraph(long id, Map<String,INDArray> map, Map<String,Integer> reverseMap)
- Specified by:
executeGraphin interfaceOpExecutioner
-
forgetGraph
public void forgetGraph(long id)
- Specified by:
forgetGraphin interfaceOpExecutioner
-
setElementsThreshold
public void setElementsThreshold(int threshold)
This method allows to set desired number of elements per thread, for performance optimization purposes. I.e. if array contains 2048 elements, and threshold is set to 1024, 2 threads will be used for given op execution.Default value: 1024
- Specified by:
setElementsThresholdin interfaceOpExecutioner- Parameters:
threshold-
-
setTadThreshold
public void setTadThreshold(int threshold)
This method allows to set desired number of sub-arrays per thread, for performance optimization purposes. I.e. if matrix has shape of 64 x 128, and threshold is set to 8, each thread will be processing 8 sub-arrays (sure, if you have 8 core cpu). If your cpu has, say, 4, cores, only 4 threads will be spawned, and each will process 16 sub-arraysDefault value: 8
- Specified by:
setTadThresholdin interfaceOpExecutioner- Parameters:
threshold-
-
isVerbose
public boolean isVerbose()
Description copied from interface:OpExecutionerThis method returns true if verbose mode is enabled, false otherwise- Specified by:
isVerbosein interfaceOpExecutioner- Returns:
-
isDebug
public boolean isDebug()
Description copied from interface:OpExecutionerThis method returns true if debug mode is enabled, false otherwise- Specified by:
isDebugin interfaceOpExecutioner- Returns:
-
type
public OpExecutioner.ExecutionerType type()
Description copied from interface:OpExecutionerThis method returns type for this executioner instance- Specified by:
typein interfaceOpExecutioner- Returns:
-
getString
public String getString(DataBuffer buffer, long index)
Description copied from interface:OpExecutionerThis method extracts String from Utf8Buffer- Specified by:
getStringin interfaceOpExecutioner- Returns:
-
scatterUpdate
public void scatterUpdate(ScatterUpdate.UpdateOp op, INDArray array, INDArray indices, INDArray updates, int[] axis)
Description copied from interface:OpExecutionerTemporary hook- Specified by:
scatterUpdatein interfaceOpExecutioner
-
opInfoString
public String opInfoString(Op op, Optional<int[]> dimensions)
Get the information about the op in a String representation, for throwing more useful exceptions (mainly for debugging)- Parameters:
op-dimensions- Use optional here for 3 states: null = "not an exec(Op, int... dim) call". empty = "exec(Op, null)". Otherwise present = "exec(Op,int[])" call- Returns:
-
isExperimentalMode
public boolean isExperimentalMode()
- Specified by:
isExperimentalModein interfaceOpExecutioner
-
buildContext
public OpContext buildContext()
Description copied from interface:OpExecutionerThis method returns OpContext which can be used (and reused) to execute custom ops- Specified by:
buildContextin interfaceOpExecutioner- Returns:
-
exec
public INDArray[] exec(CustomOp op, OpContext context)
Description copied from interface:OpExecutionerThis method executes op with given context- Specified by:
execin interfaceOpExecutioner- Returns:
- method returns output arrays defined within context
-
inspectArray
public INDArrayStatistics inspectArray(INDArray array)
- Specified by:
inspectArrayin interfaceOpExecutioner
-
createShapeInfo
public DataBuffer createShapeInfo(long[] shape, long[] stride, long elementWiseStride, char order, DataType dtype, boolean empty)
Description copied from interface:OpExecutionerThis method returns shapeInfo DataBuffer- Specified by:
createShapeInfoin interfaceOpExecutioner- Returns:
-
createShapeInfo
public DataBuffer createShapeInfo(long[] shape, long[] stride, long elementWiseStride, char order, DataType dtype, long extras)
- Specified by:
createShapeInfoin interfaceOpExecutioner
-
tadShapeInfoAndOffsets
public TadPack tadShapeInfoAndOffsets(INDArray array, int[] dimension)
Description copied from interface:OpExecutionerThis method returns host/device tad buffers- Specified by:
tadShapeInfoAndOffsetsin interfaceOpExecutioner
-
createConstantBuffer
public DataBuffer createConstantBuffer(long[] values, DataType desiredType)
Description copied from interface:OpExecutionerThis method returns constant buffer for the given jvm array- Specified by:
createConstantBufferin interfaceOpExecutioner- Returns:
-
createConstantBuffer
public DataBuffer createConstantBuffer(int[] values, DataType desiredType)
- Specified by:
createConstantBufferin interfaceOpExecutioner
-
createConstantBuffer
public DataBuffer createConstantBuffer(float[] values, DataType desiredType)
- Specified by:
createConstantBufferin interfaceOpExecutioner
-
createConstantBuffer
public DataBuffer createConstantBuffer(double[] values, DataType desiredType)
- Specified by:
createConstantBufferin interfaceOpExecutioner
-
useCount
public int useCount(DataBuffer buffer)
Description copied from interface:OpExecutionerThis method returns reference use count from the Buffer- Specified by:
useCountin interfaceOpExecutioner- Returns:
-
-