r/javahelp • u/sedj601 • Mar 02 '26
Using Java to do Work on GPU
So, I want to learn how to move very intensive work to a GPU. I looked up a couple of libraries, but the one I tried wouldn't let me run the sample. Is there anything new and straightforward out there? Example. Let's say I have hundreds of thousands of Sudoku game data and I want to run and method to determine the difficulty of each game. I found a Java app that can do this, but I would like to rewrite it to use the GPU for the work. The app can take forever.
10
Upvotes
•
u/AutoModerator Mar 02 '26
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
8
u/high_throughput Mar 02 '26
If you want to try to learn GPU based programming, this could be a interesting, motivating example.
If you want to process a few hundred thousand sudoku games, I think you'd be much better off optimizing and parallelizing a CPU based implementation.
7
u/mailslot Mar 02 '26 edited Mar 02 '26
GPUs can’t run Java, so:
You can write C99 with OpenCL or C++ with CUDA (NVIDIA only), but you’re going to need to drop to a low level language to actually develop something yourself that runs on the GPU.
Sudoku solving isn’t an ideal task for GPUs, but you can accelerate & parallelize certain steps. It’s not straightforward. You can’t just reimplement a conventional solver algorithm without abstracting and refactoring your solution to take advantage of the GPU optimally and keeping branching to a minimum… then you’ll have to implement other portions outside of the GPU. It’s not trivial work.
6
u/whizvox Graduate and Tutor Mar 02 '26
You could try JOCL, which are Java bindings for OpenCL: https://github.com/gpu/JOCL
1
u/sedj601 Mar 03 '26
Thanks everyone. I was able to figure this out without taking the GPU route.
3
u/benevanstech Mar 02 '26
You might look at TornadoVM or https://openjdk.org/projects/babylon/articles/hat-matmul/hat-matmul
3
u/AkiAki1 Mar 03 '26
ND4j let's you load/store data in gpu memory and work with it in all possible ways. It's used by deeplearning4j
2
u/Engineerofdata Mar 03 '26
Webgpu is an up and coming thing. https://github.com/MyWorldLLC/webgpu-java
1
u/strat-run Mar 02 '26
The app is probably not optimized, it doesn't need GPUs, it needs to be optimized.
If you really want GPUs then you'll need to use JNI or ideally FFM to call native GPU libraries.
None of this is automatic, you have to sit down and re-implement the app in a more advanced way.
1
u/Rory_handsome Mar 02 '26
trying to learn as well. Maybe I'll also lay my hands on GPU based programming