This android module uses the Fancier High-Performance library to allow execution of OpenCL kernels on the GPU from Java or Kotlin. It is not just an OpenCL wrapper, since it takes care of all the glue code that is needed to initialize, transfer memory, create programs and kernels and manage the OpenCL execution queue.
To add this module in your android project:
- Add this in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency.
dependencies {
implementation 'com.github.DoMondo:Fancier:Tag'
}
Say we want to add a constant to an existing Java byte array (byte []
):
float kConstant = 95;
for (int i = 0; i < input.length; i++) {
output[i] = input[i] + kConstant;
}
In order to use FancyJCL to execute this in GPU, we would rewrite it like so:
Stage stage = new Stage();
stage.setKernelSource("output[d0] = input[d0] * kConstant;");
stage.setInputs(Map.of("input", input, "kConstant", kConstant));
stage.setOutputs(Map.of("output", output));
stage.setRunConfiguration(new RunConfiguration(new long[]{size}, new long[]{4}));
stage.runSync();
For more complex scenarios, check the tutorials
An application that tests and benchmarks many image filters is located in examples/example_app
.
Check the Javadocs.