I am creating a program that needs to run many calculations simultaneously so i looked for a gpu solution to make it run faster. I implemented the code found here: https://github.com/Syncleus/aparapi-examples/tree/master/src/main/java/com/aparapi/examples/add into this function that would add 2 arrays of values on the GPU:
public static double[] addWithGPU(double[] a, double[] b) {
final double[] sum = new double[a.length];
Kernel kernel = new Kernel(){
@Override
public void run() {
int gid = getGlobalId();
sum[gid] = a[gid] + b[gid];
}
};
kernel.execute(Range.create(a.length));
kernel.dispose();
return sum;
}
I used this code in my main class:
public Main() {
GPU.addWithGPU(new double[] {1, 2, 3}, new double[] {3, 2, 1});
thread = new Thread(() -> {
// Code here
});
thread.start();
}
public static void main(String[] args) {
new Main();
}
I also tried this:
final double[] a1 = {1, 2, 3};
final double[] a2 = {3, 2, 1};
public Main() {
GPU.addWithGPU(a1, a2);
thread = new Thread(() -> {
// Code here
});
thread.start();
}
public static void main(String[] args) {
new Main();
}
I also tried to make the "addWithGPU" function non static however i still got the error of:
com.aparapi.internal.model.ClassModel$AttributePool WARNING: Found unexpected Attribute (name = NestHost)
Somtimes the code just continues running after the error however sometimes the program just hangs, and it is inconsistent, I belive it may be based on if any other programs are using my GPU at the time however I am not sure.
My PC specs are: GPU: Nvidia RTX 3060, CPU: Intel Core i9 12900KF, Motherboard: ASUS PRIME Z690-P d4 wifi and the software I am using is IntelliJ IDEA CE
I also would prefer and answer using the aparapi api since I am not great at low level programming, but i will be open so swiching api's if the aparapi api is simply out of date or has a complicated solution where it would just be simpler to swap api's.