Fork me on GitHub

Aparapi.github.io

Welcome to the official home of AMD's Aparapi

Please see http://developer.amd.com/tools-and-sdks/open-source for additional AMD open-source contributions.

Refer to the current documentation or the older docs on google code Aparapi Google Code for documentation.

Binary downloads at Maven Central coming soon!

Watch this space!

What is Aparapi?

Aparapi allows Java developers to take advantage of the compute power of GPU and APU devices by executing data parallel code fragments on the GPU rather than being confined to the local CPU. It does this by converting Java bytecode to OpenCL at runtime and executing on the GPU, if for any reason Aparapi can't execute on the GPU it will execute in a Java thread pool.

We like to think that for the appropriate workload this extends Java's 'Write Once Run Anywhere' to include GPU devices.

With Aparapi we can take a sequential loop such as this (which adds each element from inA and inB arrays and puts the result in result).

final float inA[] = .... // get a float array of data from somewhere final float inB[] = .... // get a float array of data from somewhere (inA.length==inB.length) final float result = new float[inA.length];

for (int i=0; i<array.length; i++){ result[i]=intA[i]+inB[i]; }

And refactor the sequential loop to the following form:

Kernel kernel = new Kernel(){ @Override public void run(){ int i= getGlobalId(); result[i]=intA[i]+inB[i]; } }; Range range = Range.create(result.length); kernel.execute(range);

In the above code we extend com.amd.aparapi.Kernel base class and override the Kernel.run() method to express our data parallel algorithm. We initiate the execution of the Kernel(over a specific range 0..results.length) using Kernel.execute(range).

For folks following the new Java 8 lambda extensions. Here is how we expect the above Aparapi code to look when Java 8 arrives.

Device.getBest().forEach(result.length, id -> result[id] = intA[id]+inB[id]);

Because we are also targeting the new "HSA Intermediate Language" https://hsafoundation.app.box.com/s/m6mrsjv8b7r50kqeyyal in the 'lambda' branch, Aparapi users will now be able to access Strings (and other objects) from the Java heap. So given an array of Strings and ints we can extract the lengths in parallel.

Device.hsa().forEach(strings.length, id -> lengths[id] = strings[id].length());

Note that because the example ''only'' works with HSA we need to select a HSA device.

If you would like to download and try Aparapi follow the 'Downloads' link above and read the UsersGuide, alternatively if you would like to contribute or access the code you can check out the code from the SVN repository above and jump right in by reading the DevelopersGuide pages.

Aparapi in the news + upcoming presentations

Useful links

Similar Work

Wiki Pages

About the name

Aparapi is just a contraction of "A PARallel API"

However... "Apa rapi" in Indonesian (the language spoken on the island of Java) translates to "What a neat...". So "Apa rapi Java Project" translates to "What a neat Java Project" How cool is that?