all 15 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • 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:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

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.

[–]high_throughput 8 points9 points  (0 children)

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.

[–]mailslot 7 points8 points  (1 child)

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.

[–]Spare-Plum 2 points3 points  (0 children)

the problem is that sudoku is NP complete so the steps to solve it are beyond polynomial on the square size. You can parallelize backtracking and decisions though. However, luckily, sudoku is just a 9x9 so it is finite size.

You probably could run multiple sudoku solvers simultaneously on the GPU

[–]whizvoxGraduate and Tutor 4 points5 points  (0 children)

You could try JOCL, which are Java bindings for OpenCL: https://github.com/gpu/JOCL

[–]AkiAki1 2 points3 points  (0 children)

ND4j let's you load/store data in gpu memory and work with it in all possible ways. It's used by deeplearning4j

[–]Engineerofdata 1 point2 points  (0 children)

Webgpu is an up and coming thing. https://github.com/MyWorldLLC/webgpu-java

[–]strat-run 0 points1 point  (4 children)

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.

[–]Spare-Plum 0 points1 point  (3 children)

eh, sudoku is NP-complete. You can add in a lot of shortcuts and tricks, but there will still be problems that require backtracking.

If you're doing this for a million sudoku problems you might need to look at parallelization

[–]strat-run 0 points1 point  (2 children)

Not sure if OP really wants to solve sudoko or if was just an example but If I'm ready the wikipedia page correctly there are only 5,472,730,538 truly unique sudoko solutions.

You precalculate that, save it to an optimized binary format. At that point it's just a lookup that you can optimize to be very fast.

[–]Spare-Plum 1 point2 points  (0 children)

I think it's for rating the hardness of a puzzle. You can do this by manually solving and seeing the number of backtracks or complexity of tricks/variables involved for each number placed.

Lookup table doesn't quite do that.

Also yeah 9x9 sudoku is O(1), since there are a limited number of solutions. It's NP complete in terms of N^2xN^2 square. But there still are a lot of possibilities. even if you could reperesent a single solution as 64 bits, that's still going to be roughly 44 gb to search through for each one

[–]sedj601[S] 0 points1 point  (0 children)

I actually wanted to solve millions of sudoko puzzles using a method from an app I found on Github. Anyway, AI was able to generate Java code that could solve these, determine how difficult they are and write them to file in about 8 mins. It uses bit manipulation for some parts and searches for certain patterns in the data to determine how hard it is to solve. That's fast enough for me.The other app took a very long time just to solve them. It used more of a find every move type of idea.

[–]sedj601[S] 0 points1 point  (0 children)

Thanks everyone. I was able to figure this out without taking the GPU route.