user2649681
user2649681

Reputation: 848

Perform Calculations on GPU in Java

I'm looking to see if there's a way one can make part of a Java program, specifically the need for many repeated, slightly complex calculations, execute on a computer's GPU rather than solely on the CPU. I know that libraries like LWJGL allow Java programs to utilize the GPU, but I've not found a straightforward way to simply perform calculations on it that are not necessarily related to graphics.

Is there a way to, for example speed up the following code using a computer's GPU?

    long t = System.currentTimeMillis();
    double x;
    for(int i=0; i < 1080; i++){
        for(int j=0; j<1920; j++){
            x = Math.sqrt(Math.tan(1d - Math.sin(i * j)));
        }
    }
    System.out.println(System.currentTimeMillis() - t);

When I test the above, solely-CPU operated, function, it takes about 1.25 seconds for it to complete.

Upvotes: 1

Views: 1558

Answers (1)

user158037
user158037

Reputation: 2603

You might want to try aparapi. Other than that any Java wrappers around native OpenCL/CUDA might be useful.

Upvotes: 1

Related Questions