Class KernelRunner

java.lang.Object
com.aparapi.internal.jni.KernelRunnerJNI
com.aparapi.internal.kernel.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
Author:
gfrost
See Also:
  • Field Details

  • Constructor Details

    • KernelRunner

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

    • 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)
    • getKernelMinimumPrivateMemSizeInUsePerWorkItem

      public long getKernelMinimumPrivateMemSizeInUsePerWorkItem(Device device) throws QueryFailedException
      Throws:
      QueryFailedException
    • getKernelLocalMemSizeInUse

      public long getKernelLocalMemSizeInUse(Device device) throws QueryFailedException
      Throws:
      QueryFailedException
    • getKernelPreferredWorkGroupSizeMultiple

      public int getKernelPreferredWorkGroupSizeMultiple(Device device) throws QueryFailedException
      Throws:
      QueryFailedException
    • getKernelMaxWorkGroupSize

      public int getKernelMaxWorkGroupSize(Device device) throws QueryFailedException
      Throws:
      QueryFailedException
    • getKernelCompileWorkGroupSize

      public int[] getKernelCompileWorkGroupSize(Device device) throws QueryFailedException
      Throws:
      QueryFailedException
    • 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 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(String _entrypoint, Range _range, int _passes)
    • compile

      public Kernel compile(String _entrypoint, Device device) throws CompileFailedException
      Throws:
      CompileFailedException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 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:
    • isExecuting

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

      public void get(Object array)
      Enqueue a request to return this array from the GPU. This method blocks until the array is available.
      Note that Kernel.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

      public List<ProfileInfo> getProfileInfo()
    • put

      public void put(Object array)
      Tag this array so that it is explicitly enqueued before the kernel is executed.
      Note that Kernel.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()