Package com.aparapi.internal.kernel
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
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static final class
private class
private static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private KernelArg[]
static boolean
static final int
static final int
private static final String
private Entrypoint
private boolean
private boolean
private final KernelRunner.ThreadDiedHandler
private final ByteBuffer
A direct ByteBuffer used for asynchronous intercommunication between java and JNI C code.private final IntBuffer
private boolean
private long
private final Kernel
private static Logger
private static final ForkJoinPool.ForkJoinWorkerThreadFactory
private static final int
private final ByteBuffer
A direct ByteBuffer used for asynchronous intercommunication between java and JNI C code.private final IntBuffer
static final int
static final int
private int
private static LinkedHashSet
<String> private final ForkJoinPool
private boolean
Fields inherited from class com.aparapi.internal.jni.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 TypeMethodDescriptionboolean
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.void
void
private void
private String
void
dispose()
Kernel.dispose()
delegates toKernelRunner.dispose()
which delegates todisposeJNI()
to actually close JNI data structures.private Kernel
executeInternalInner
(KernelRunner.ExecutionSettings _settings, Device aparapiDevice, boolean compileOnly) private Kernel
protected void
executeJava
(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 OpenCLprivate Kernel
executeOpenCL
(Device device, KernelRunner.ExecutionSettings _settings) private void
private void
private Kernel
private Kernel
fallBackToNextDevice
(Device device, KernelRunner.ExecutionSettings _settings, Exception _exception) private Kernel
fallBackToNextDevice
(Device device, KernelRunner.ExecutionSettings _settings, Exception _exception, boolean _silently) private Kernel
fallBackToNextDevice
(Device device, KernelRunner.ExecutionSettings _settings, String _reason) void
Enqueue a request to return this array from the GPU.int
private ClassModel
getClassModelFromArg
(KernelArg arg, Class<?> arrayClass) Helper method to retrieve the class model from a kernel argument.int
Returns the index of the current pass, or one of two special constants with negative values to indicate special progress states.private int
protected int
int[]
getKernelCompileWorkGroupSize
(Device device) long
getKernelLocalMemSizeInUse
(Device device) int
getKernelMaxWorkGroupSize
(Device device) long
int
private int
getPrimitiveSize
(int type) (package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
private boolean
isDeviceCompatible
(Device device) boolean
True while any of theexecute()
methods are in progress.boolean
private void
maybeReportProfile
(KernelRunner.ExecutionSettings _settings) private boolean
private boolean
void
Tag this array so that it is explicitly enqueued before the kernel is executed.private void
recreateRange
(KernelRunner.ExecutionSettings _settings) private void
void
setExplicit
(boolean _explicit) private void
setMultiArrayType
(KernelArg arg, Class<?> type) toString()
private boolean
Methods inherited from class com.aparapi.internal.jni.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 -
MINIMUM_ARRAY_SIZE
private static final int MINIMUM_ARRAY_SIZE- See Also:
-
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:
-
CODE_GEN_ERROR_MARKER
-
logger
-
jniContextHandle
private long jniContextHandle -
kernel
-
entryPoint
-
argc
private int argc -
executing
private volatile boolean executing -
passId
private volatile int passId -
inBufferRemote
A direct ByteBuffer used for asynchronous intercommunication between java and JNI C code.At present this is a 4 byte buffer to be interpreted as an int[1], used for passing from java to C a single integer interpreted as a cancellation indicator.
-
inBufferRemoteInt
-
outBufferRemote
A direct ByteBuffer used for asynchronous intercommunication between java and JNI C code.At present this is a 4 byte buffer to be interpreted as an int[1], used for passing from C to java a single integer interpreted as a the current pass id.
-
outBufferRemoteInt
-
isFallBack
private boolean isFallBack -
lowPriorityThreadFactory
-
handler
-
threadPool
-
openCLCache
-
seenBinaryKeys
-
kernelIsCompiledForDeviceHash
-
kernelNeverExecutedForDeviceHash
-
capabilitiesSet
-
args
-
usesOopConversion
private boolean usesOopConversion -
puts
-
explicit
private boolean explicit
-
-
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
-
hasFP64Support
boolean hasFP64Support() -
hasSelectFPRoundingModeSupport
boolean hasSelectFPRoundingModeSupport() -
hasGlobalInt32BaseAtomicsSupport
boolean hasGlobalInt32BaseAtomicsSupport() -
hasGlobalInt32ExtendedAtomicsSupport
boolean hasGlobalInt32ExtendedAtomicsSupport() -
hasLocalInt32BaseAtomicsSupport
boolean hasLocalInt32BaseAtomicsSupport() -
hasLocalInt32ExtendedAtomicsSupport
boolean hasLocalInt32ExtendedAtomicsSupport() -
hasInt64BaseAtomicsSupport
boolean hasInt64BaseAtomicsSupport() -
hasInt64ExtendedAtomicsSupport
boolean hasInt64ExtendedAtomicsSupport() -
has3DImageWritesSupport
boolean has3DImageWritesSupport() -
hasByteAddressableStoreSupport
boolean hasByteAddressableStoreSupport() -
hasFP16Support
boolean hasFP16Support() -
hasGLSharingSupport
boolean hasGLSharingSupport() -
executeJava
Execute using a Java thread pool, or sequentially, or using an alternative algorithm, usually as a result of failing to compile or execute OpenCL -
getClassModelFromArg
Helper method to retrieve the class model from a kernel argument.- Parameters:
arg
- the kernel argumentarrayClass
- the array Java class for the argument- Returns:
- the Aparapi ClassModel instance.
-
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
-
prepareOopConversionBuffer
- Parameters:
arg
-- Returns:
- Throws:
AparapiException
-
extractOopConversionBuffer
- Throws:
AparapiException
-
restoreObjects
- Throws:
AparapiException
-
prepareAtomicIntegerConversionBuffer
- Throws:
AparapiException
-
extractAtomicIntegerConversionBuffer
- Throws:
AparapiException
-
updateKernelArrayRefs
- Throws:
AparapiException
-
executeOpenCL
private Kernel executeOpenCL(Device device, KernelRunner.ExecutionSettings _settings) throws AparapiException - Throws:
AparapiException
-
fallBackByExecutionMode
-
recreateRange
-
fallBackToNextDevice
private Kernel fallBackToNextDevice(Device device, KernelRunner.ExecutionSettings _settings, String _reason) -
fallBackToNextDevice
private Kernel fallBackToNextDevice(Device device, KernelRunner.ExecutionSettings _settings, Exception _exception) -
fallBackToNextDevice
private Kernel fallBackToNextDevice(Device device, KernelRunner.ExecutionSettings _settings, Exception _exception, boolean _silently) -
execute
-
compile
- Throws:
CompileFailedException
-
executeInternalOuter
-
executeInternalInner
private Kernel executeInternalInner(KernelRunner.ExecutionSettings _settings, Device aparapiDevice, boolean compileOnly) throws CompileFailedException - Throws:
CompileFailedException
-
toString
-
describeDevice
-
maybeReportProfile
-
isDeviceCompatible
-
getCancelState
public int getCancelState() -
cancelMultiPass
public void cancelMultiPass() -
clearCancelMultiPass
private void clearCancelMultiPass() -
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_EXECUTION
to indicate that the Kernel has started executing but not reached the initial pass, orPASS_ID_COMPLETED_EXECUTION
to indicate that execution is complete (possibly due to early termination viacancelMultiPass()
), i.e. the Kernel is idle.PASS_ID_COMPLETED_EXECUTION
is 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() -
getCurrentPassLocal
private int getCurrentPassLocal() -
getPrimitiveSize
private int getPrimitiveSize(int type) -
setMultiArrayType
- Throws:
AparapiException
-
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()
-