Class KernelRunner


  • public class KernelRunner
    extends KernelRunnerJNI
    The class is responsible for executing 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:
    Kernel.execute(int _globalSize)
    • Field Detail

      • BINARY_CACHING_DISABLED

        public static boolean BINARY_CACHING_DISABLED
      • CODE_GEN_ERROR_MARKER

        private static final java.lang.String CODE_GEN_ERROR_MARKER
      • logger

        private static java.util.logging.Logger logger
      • jniContextHandle

        private long jniContextHandle
      • kernel

        private final Kernel kernel
      • argc

        private int argc
      • executing

        private volatile boolean executing
      • passId

        private volatile int passId
      • inBufferRemote

        private final java.nio.ByteBuffer 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

        private final java.nio.IntBuffer inBufferRemoteInt
      • outBufferRemote

        private final java.nio.ByteBuffer 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

        private final java.nio.IntBuffer outBufferRemoteInt
      • isFallBack

        private boolean isFallBack
      • lowPriorityThreadFactory

        private static final java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory lowPriorityThreadFactory
      • threadPool

        private final java.util.concurrent.ForkJoinPool threadPool
      • openCLCache

        private static java.util.HashMap<java.lang.Class<? extends Kernel>,​java.lang.String> openCLCache
      • seenBinaryKeys

        private static java.util.LinkedHashSet<java.lang.String> seenBinaryKeys
      • kernelIsCompiledForDeviceHash

        private final java.util.Hashtable<Device,​java.lang.Boolean> kernelIsCompiledForDeviceHash
      • kernelNeverExecutedForDeviceHash

        private final java.util.Hashtable<Device,​java.lang.Boolean> kernelNeverExecutedForDeviceHash
      • capabilitiesSet

        private java.util.Set<java.lang.String> capabilitiesSet
      • usesOopConversion

        private boolean usesOopConversion
      • puts

        private final java.util.Set<java.lang.Object> puts
      • explicit

        private boolean explicit
    • Constructor Detail

      • KernelRunner

        public KernelRunner​(Kernel _kernel)
        Create a KernelRunner for a specific Kernel instance.
        Parameters:
        _kernel -
    • Method Detail

      • cleanUpArrays

        public void cleanUpArrays()
      • dispose

        public void dispose()
        Kernel.dispose() delegates to KernelRunner.dispose() which delegates to disposeJNI() to actually close JNI data structures.
        See Also:
        KernelRunnerJNI.disposeJNI(long)
      • 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

        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 OpenCL
      • getClassModelFromArg

        private ClassModel getClassModelFromArg​(KernelArg arg,
                                                java.lang.Class<?> arrayClass)
        Helper method to retrieve the class model from a kernel argument.
        Parameters:
        arg - the kernel argument
        arrayClass - the array Java class for the argument
        Returns:
        the Aparapi ClassModel instance.
      • allocateArrayBufferIfFirstTimeOrArrayChanged

        public boolean allocateArrayBufferIfFirstTimeOrArrayChanged​(KernelArg arg,
                                                                    java.lang.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 argument
        newRef - the actual Java data instance
        objArraySize - the number of elements in the Java array
        totalStructSize - the size of each target array element
        totalBufferSize - 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

        public Kernel execute​(java.lang.String _entrypoint,
                              Range _range,
                              int _passes)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • describeDevice

        private java.lang.String describeDevice()
      • isDeviceCompatible

        private boolean isDeviceCompatible​(Device device)
      • 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 are PASS_ID_PREPARING_EXECUTION to indicate that the Kernel has started executing but not reached the initial pass, or PASS_ID_COMPLETED_EXECUTION to indicate that execution is complete (possibly due to early termination via cancelMultiPass()), 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:
        execute(String, Range, int)
      • isExecuting

        public boolean isExecuting()
        True while any of the execute() methods are in progress.
      • getCurrentPassRemote

        protected int getCurrentPassRemote()
      • getCurrentPassLocal

        private int getCurrentPassLocal()
      • getPrimitiveSize

        private int getPrimitiveSize​(int type)
      • getProfileInfo

        public java.util.List<ProfileInfo> getProfileInfo()
      • setExplicit

        public void setExplicit​(boolean _explicit)
      • isExplicit

        public boolean isExplicit()