CUDA : Thread and (of course) Synchronization
Today, I’m learning some new techniques in CUDA Programming. The topic was Thread Handling. It discussed about how we span the parallel processing into some threads, instead of using blocks. The fun example that I was trying to code is such as below.
With this sample, I’m gonna animate the fluid ripple effects, but of course using threads. With parallel processing, there is no barrier to process the function to create the ripple, in this case such as cosinus, for all the pixel. And what you will see is the smooth ripple animation.
OMG, now, I such lose the Operating System course. You know, I was quite “play” in the class, so I felt like forgetting the lesson about Threads.
Ok, if we talk about threads, there will be something called with synchronization. Why synchronization? So, just imagine that you have a team of ambitious friends to win some kind of competition. You team goal is to build something like miniature, puzzle or something else. It is ok if the parts can be build separately and you can submit them separately too, because there is no need to communicate with others and yourself can think only for your part. How about if the rule’s changed into build a unit of the puzzle, so it’s gonna have to be submitted into one piece. And you know, if your team use the same way, your team will ruin it. All you need is to communicate among others.
Back to the topic. Let you imagine again, all your team members are the threads and the goal is only one piece. Your team, of course, need a convention, the convention to build the piece together, no matter how. In this case, the convention is called synchronization. I hope you get it.
Thus, I try a sample program which show what happens if the threads do and don’t synchronize. This sample was presented into bitmaps, so that we can look the differences easily.
The left one shows the threads which build the scrabbled bitmaps don’t synchronize, while the right one shows the threads which build the nice bitmaps do synchronize.
So the last words, CUDA has the feature such that the programmer don’t need to worry about the threads managing implementation. That’s all.