Package es.ull.pcg.hpc.fancyjcl
Class Stage
java.lang.Object
es.ull.pcg.hpc.fancyjcl.Stage
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 Summary
FieldsModifier and TypeFieldDescriptionlong
This attribute will be set from JNI when kernel is created in `prepare`. -
Constructor Summary
ConstructorsConstructorDescriptionStage()
Instantiates a new Stage, setting the stageName, and registering the stage in the Manager. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Print a summary showing information about the parameters (inputs and outputs), generated OpenCL kernel andRunConfiguration
of theStage
.void
run()
Enqueues the Stage to be run using the setRunConfiguration
.void
runSync()
Synchronizes the inputs to GPU, enqueues thisStage
to be run, waits until the execution ends and synchronizes the outputs to CPU.void
Sets inputs for the Stage.void
setKernelSource
(String kernelSource) Sets kernel source.void
setOutputs
(Map<String, Object> outputElements) Sets outputs for the Stage.void
setRunConfiguration
(RunConfiguration runConfiguration) Sets run configuration.void
Synchronize inputs to GPU.void
Synchronize outputs to cpu.void
Wait until execution ends.
-
Field Details
-
cl_kernel_ptr
public long cl_kernel_ptrThis 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
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 thatdn
will be convertedget_global_id(n)
. For more information on writing kernels check the TUTORIAL.- Parameters:
kernelSource
- code that will be converted to OpenCL.
-
setInputs
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
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
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
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 setRunConfiguration
. This method is non-blocking.
It is used whenever severalStage
s are going to be executed sequentially. Usually all the stages of an algorithm are set to run with this method and then a call towaitUntilExecutionEnds()
is placed to ensure all the stages are executed in GPU. For a blocking version of this method seerunSync()
. -
runSync
Synchronizes the inputs to GPU, enqueues thisStage
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 callingrun()
instead.- Throws:
Exception
-
syncInputsToGPU
Synchronize inputs to GPU.- Throws:
Exception
-
syncOutputsToCPU
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
Sets run configuration. SeeRunConfiguration
.- Parameters:
runConfiguration
- the run configuration- Throws:
Exception
- the exception
-
printSummary
Print a summary showing information about the parameters (inputs and outputs), generated OpenCL kernel andRunConfiguration
of theStage
.- Throws:
Exception
-