Class Stage

java.lang.Object
es.ull.pcg.hpc.fancyjcl.Stage

public class Stage extends Object
Class representing an algorithm that has a set of parameters (inputs and outputs) and a run configuration for its accelerated execution in GPU via OpenCL.
  • Field Details

    • cl_kernel_ptr

      public long cl_kernel_ptr
      This attribute will be set from JNI when kernel is created in `prepare`. It must be public for this reason.
  • Constructor Details

    • Stage

      public Stage()
      Instantiates a new Stage, setting the stageName, and registering the stage in the Manager.
  • Method Details

    • setKernelSource

      public void setKernelSource(String kernelSource)
      Sets kernel source. The variables used inside the kernel must match those of the input and output parameters. The signature of the kernel will be automatically generated. Also there is a shorthand for variables such that dn will be converted get_global_id(n). For more information on writing kernels check the TUTORIAL.
      Parameters:
      kernelSource - code that will be converted to OpenCL.
    • setInputs

      public void setInputs(Map<String,Object> inputElements) throws Exception
      Sets inputs for the Stage. Each input is an Object with a name. For example, in order to set two input parameters called input and constant, we call the method like so:
      
       stage.setInputs(Map.of("input", input, "constant", constant));
       

      These kind of types are supported and will be zero-copy if initialized as DirectBuffer.

      • ByteBuffer
      • CharBuffer
      • ShortBuffer
      • IntBuffer
      • FloatBuffer
      • DoubleBuffer
      Note that the endianness of the architecture must be matched. So, initialize them as follow:
      
       ByteBuffer input = ByteBuffer.allocateDirect(size);
       input.order(ByteOrder.LITTLE_ENDIAN);
       

      These kind of types are supported but will not be zero-copy:

      • byte []
      • char []
      • short []
      • int []
      • float []
      • double []
      Parameters:
      inputElements - A map where the key is the element name and the value is the input object.
      Throws:
      Exception - the exception
    • setOutputs

      public void setOutputs(Map<String,Object> outputElements) throws Exception
      Sets outputs for the Stage. Each output is an Object with a name. For example, in order to a single output parameter called output, we call the method like so:
      
       stage.setOutputs(Map.of("output", output));
       

      These kind of types are supported and will be zero-copy if initialized as DirectBuffer.

      • ByteBuffer
      • CharBuffer
      • ShortBuffer
      • IntBuffer
      • FloatBuffer
      • DoubleBuffer
      Note that the endianness of the architecture must be matched. So, initialize them as follow:
      
       ByteBuffer input = ByteBuffer.allocateDirect(size);
       input.order(ByteOrder.LITTLE_ENDIAN);
       

      These kind of types are supported but will not be zero-copy:

      • byte []
      • char []
      • short []
      • int []
      • float []
      • double []
      Parameters:
      outputElements - the output elements
      Throws:
      Exception - the exception
    • run

      public void run()
      Enqueues the Stage to be run using the set RunConfiguration. This method is non-blocking.
      It is used whenever several Stages are going to be executed sequentially. Usually all the stages of an algorithm are set to run with this method and then a call to waitUntilExecutionEnds() is placed to ensure all the stages are executed in GPU. For a blocking version of this method see runSync().
    • runSync

      public void runSync() throws Exception
      Synchronizes the inputs to GPU, enqueues this Stage to be run, waits until the execution ends and synchronizes the outputs to CPU. If you are running several Stages sequentially, avoid unneeded synchronizations by calling run() instead.
      Throws:
      Exception
    • syncInputsToGPU

      public void syncInputsToGPU() throws Exception
      Synchronize inputs to GPU.
      Throws:
      Exception
    • syncOutputsToCPU

      public void syncOutputsToCPU() throws Exception
      Synchronize outputs to cpu.
      Throws:
      Exception
    • waitUntilExecutionEnds

      public void waitUntilExecutionEnds()
      Wait until execution ends. This is a blocking call that ensures that all enqueued Stages are finished.
    • setRunConfiguration

      public void setRunConfiguration(RunConfiguration runConfiguration) throws Exception
      Sets run configuration. See RunConfiguration.
      Parameters:
      runConfiguration - the run configuration
      Throws:
      Exception - the exception
    • printSummary

      public void printSummary() throws Exception
      Print a summary showing information about the parameters (inputs and outputs), generated OpenCL kernel and RunConfiguration of the Stage.
      Throws:
      Exception