Good day all.
I have written a particle simulator and would like to try improving speed using parallel processing on a GPU.
APARAPI is something used to run Java on GPU, but will it work with Processing?
I have no experience with Java or any of the technical stuff that happens under the hood with Processing. Below is a link to the APARAPI user guide. I have implemented threads in my code for multithreading on the CPU so I understand there is some similarity between launching new threads and launching new kernels, but I have no idea what to make of the rest.
For what it is worth, I tried out a simple sketch with elements from the “Squares” example that comes with the download. I somehow managed to get it running but only after doing the following:
In the aparapi zip file “dist_windows_x86_64” I found the files “aparapi.jar” and “aparapi_x86_64.dll”. I placed a copy of the dll file in Processing-4.3 > core > library > windows-amd64.
I made a folder called “code” in the same folder as the sketch and copied the jar file into that folder.
import com.amd.aparapi.Kernel;
import com.amd.aparapi.Range;
int numBalls = 100;
float dx = 0.2;
float balldiameter = 20;
float[] values = new float[numBalls];
Ball[] balls = new Ball[numBalls];
void setup() {
size(1500, 300);
for (int i = 0; i < numBalls; i++) {
values[i] = i;
balls[i] = new Ball(20*i, 20);
}
}
void draw() {
background(205);
kernel.execute(Range.create(numBalls));
for (int i=0; i<numBalls; i++) {
if (i%2 ==0 )balls[i].show();
}
kernel.dispose();
}
Kernel kernel = new Kernel() {
@Override void run() {
int gid = getGlobalId();
if (gid<numBalls-1 ) balls[gid].posy += dx;
}
};
class Ball {
float posx;
float posy;
float dx;
Ball(float pos1, float pos2) {
posx = pos1;
posy = pos2;
dx = 0.2;
}
void show() {
circle(posx, posy, balldiameter);
}
}
It gave the following message in the console but at least my little circles were being drawn.
Apr 15, 2025 5:21:20 PM com.amd.aparapi.internal.model.ClassModel$AttributePool
WARNING: Found unexpected Attribute (name = NestHost)
clone of 26 aaload
Apr 15, 2025 5:21:20 PM com.amd.aparapi.internal.model.ClassModel$AttributePool
WARNING: Found unexpected Attribute (name = NestMembers)
Apr 15, 2025 5:21:20 PM com.amd.aparapi.internal.model.ClassModel$AttributePool
WARNING: Found unexpected Attribute (name = NestMembers)
Apr 15, 2025 5:21:20 PM com.amd.aparapi.internal.model.ClassModel$AttributePool
WARNING: Found unexpected Attribute (name = NestHost)
Apr 15, 2025 5:21:20 PM com.amd.aparapi.internal.kernel.KernelRunner warnFallBackAndExecute
WARNING: Reverting to Java Thread Pool (JTP) for class Aparapi_test4$1: Kernel array object member class must be final.
com.amd.aparapi.internal.exception.ClassParseException: Kernel array object member class must be final.
at com.amd.aparapi.internal.model.Entrypoint.(Entrypoint.java:604)
at com.amd.aparapi.internal.model.ClassModel.getEntrypoint(ClassModel.java:2720)
at com.amd.aparapi.internal.model.ClassModel.getEntrypoint(ClassModel.java:2728)
at com.amd.aparapi.internal.kernel.KernelRunner.execute(KernelRunner.java:947)
at com.amd.aparapi.Kernel.execute(Kernel.java:2028)
at com.amd.aparapi.Kernel.execute(Kernel.java:1962)
at com.amd.aparapi.Kernel.execute(Kernel.java:1933)
at Aparapi_test4.draw(Aparapi_test4.java:57)
at processing.core.PApplet.handleDraw(PApplet.java:2094)
at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1386)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)