Class KernelRunner
java.lang.Object
com.aparapi.internal.jni.KernelRunnerJNI
com.aparapi.internal.kernel.KernelRunner
The class is responsible for executing
The
The
Kernel implementations. The
KernelRunner is the real workhorse for Aparapi. Each Kernel instance creates a single
KernelRunner to encapsulate state and to help coordinate interactions between the Kernel
and it's execution logic.The
KernelRunner is created lazily as a result of calling Kernel.execute(). A this
time the ExecutionMode is consulted to determine the default requested mode. This will dictate how
the KernelRunner will attempt to execute the Kernel- Author:
- gfrost
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanstatic final intstatic final intstatic final intstatic final intFields inherited from class KernelRunnerJNI
ARG_APARAPI_BUFFER, ARG_ARRAY, ARG_ARRAYLENGTH, ARG_BOOLEAN, ARG_BYTE, ARG_CHAR, ARG_CONSTANT, ARG_DOUBLE, ARG_EXPLICIT, ARG_EXPLICIT_WRITE, ARG_FLOAT, ARG_GLOBAL, ARG_INT, ARG_LOCAL, ARG_LONG, ARG_OBJ_ARRAY_STRUCT, ARG_PRIMITIVE, ARG_READ, ARG_SHORT, ARG_STATIC, ARG_WRITE, JNI_FLAG_USE_ACC, JNI_FLAG_USE_GPU -
Constructor Summary
ConstructorsConstructorDescriptionKernelRunner(Kernel _kernel) Create a KernelRunner for a specific Kernel instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanallocateArrayBufferIfFirstTimeOrArrayChanged(KernelArg arg, Object newRef, int objArraySize, int totalStructSize, int totalBufferSize) Helper method that manages the memory allocation for storing the kernel argument data, so that the data can be exchanged between the host and the OpenCL device.voidvoidvoiddispose()Kernel.dispose()delegates toKernelRunner.dispose()which delegates todisposeJNI()to actually close JNI data structures.protected voidexecuteJava(com.aparapi.internal.kernel.KernelRunner.ExecutionSettings _settings, Device device) Execute using a Java thread pool, or sequentially, or using an alternative algorithm, usually as a result of failing to compile or execute OpenCLvoidEnqueue a request to return this array from the GPU.intintReturns the index of the current pass, or one of two special constants with negative values to indicate special progress states.protected intint[]getKernelCompileWorkGroupSize(Device device) longgetKernelLocalMemSizeInUse(Device device) intgetKernelMaxWorkGroupSize(Device device) longintbooleanTrue while any of theexecute()methods are in progress.booleanvoidTag this array so that it is explicitly enqueued before the kernel is executed.voidsetExplicit(boolean _explicit) toString()Methods inherited from class KernelRunnerJNI
buildProgramJNI, disposeJNI, getExtensionsJNI, getJNI, getKernelCompileWorkGroupSizeJNI, getKernelLocalMemSizeInUseJNI, getKernelMaxWorkGroupSizeJNI, getKernelMinimumPrivateMemSizeInUsePerWorkItemJNI, getKernelPreferredWorkGroupSizeMultipleJNI, getProfileInfoJNI, initJNI, runKernelJNI, setArgsJNI
-
Field Details
-
BINARY_CACHING_DISABLED
public static boolean BINARY_CACHING_DISABLED -
PASS_ID_PREPARING_EXECUTION
public static final int PASS_ID_PREPARING_EXECUTION- See Also:
-
PASS_ID_COMPLETED_EXECUTION
public static final int PASS_ID_COMPLETED_EXECUTION- See Also:
-
CANCEL_STATUS_FALSE
public static final int CANCEL_STATUS_FALSE- See Also:
-
CANCEL_STATUS_TRUE
public static final int CANCEL_STATUS_TRUE- See Also:
-
-
Constructor Details
-
KernelRunner
Create a KernelRunner for a specific Kernel instance.- Parameters:
_kernel-
-
-
Method Details
-
cleanUpArrays
public void cleanUpArrays() -
dispose
public void dispose()Kernel.dispose()delegates toKernelRunner.dispose()which delegates todisposeJNI()to actually close JNI data structures.- See Also:
-
getKernelMinimumPrivateMemSizeInUsePerWorkItem
public long getKernelMinimumPrivateMemSizeInUsePerWorkItem(Device device) throws QueryFailedException - Throws:
QueryFailedException
-
getKernelLocalMemSizeInUse
- Throws:
QueryFailedException
-
getKernelPreferredWorkGroupSizeMultiple
- Throws:
QueryFailedException
-
getKernelMaxWorkGroupSize
- Throws:
QueryFailedException
-
getKernelCompileWorkGroupSize
- Throws:
QueryFailedException
-
executeJava
protected void executeJava(com.aparapi.internal.kernel.KernelRunner.ExecutionSettings _settings, Device device) Execute using a Java thread pool, or sequentially, or using an alternative algorithm, usually as a result of failing to compile or execute OpenCL -
allocateArrayBufferIfFirstTimeOrArrayChanged
public boolean allocateArrayBufferIfFirstTimeOrArrayChanged(KernelArg arg, Object newRef, int objArraySize, int totalStructSize, int totalBufferSize) Helper method that manages the memory allocation for storing the kernel argument data, so that the data can be exchanged between the host and the OpenCL device.- Parameters:
arg- the kernel argumentnewRef- the actual Java data instanceobjArraySize- the number of elements in the Java arraytotalStructSize- the size of each target array elementtotalBufferSize- the total buffer size including memory alignment- Returns:
- true, if internal buffer had to be allocated or reallocated holding the data
- false, if buffer didn't change and is already allocated
-
execute
-
compile
- Throws:
CompileFailedException
-
toString
-
getCancelState
public int getCancelState() -
cancelMultiPass
public void cancelMultiPass() -
getCurrentPass
public int getCurrentPass()Returns the index of the current pass, or one of two special constants with negative values to indicate special progress states. Those constants arePASS_ID_PREPARING_EXECUTIONto indicate that the Kernel has started executing but not reached the initial pass, orPASS_ID_COMPLETED_EXECUTIONto indicate that execution is complete (possibly due to early termination viacancelMultiPass()), i.e. the Kernel is idle.PASS_ID_COMPLETED_EXECUTIONis also returned before the first execution has been invoked.This can be used, for instance, to update a visual progress bar.
- See Also:
-
isExecuting
public boolean isExecuting()True while any of theexecute()methods are in progress. -
getCurrentPassRemote
protected int getCurrentPassRemote() -
get
Enqueue a request to return this array from the GPU. This method blocks until the array is available.
Note thatKernel.put(type [])calls will delegate to this call.
Package public- Parameters:
array- It is assumed that this parameter is indeed an array (of int, float, short etc).- See Also:
-
getProfileInfo
-
put
Tag this array so that it is explicitly enqueued before the kernel is executed.
Note thatKernel.put(type [])calls will delegate to this call.
Package public- Parameters:
array- It is assumed that this parameter is indeed an array (of int, float, short etc).- See Also:
-
setExplicit
public void setExplicit(boolean _explicit) -
isExplicit
public boolean isExplicit()
-