Simple image processing on GPU with CUDA

Simple image processing on GPU with CUDA


Disclaimer: This article is not an extensive explanation of the inner workings of the GPU or the details of CUDA. For more information on these look here and here

In the spring 2020 semester, I took a course in parallel algorithms here at UTC and one of the topics was GPU Programming. I actually thought it was complicated but got a hang of it after few assignments and also reading a blog on medium by Anuradha Karunarathna entitled " CUDA thread Indexing".

Below I'd like to show the simplicity of GPU programming with CUDA to convert an image into a simple shade of circles as shown below in order to inspire someone to try it out as well and build other things

No alt text provided for this image

A simple kernel( CUDA function) was built using the formula of a euclidean circle below where r is the radius, a and b are center coordinates in the x and y directions respectively

No alt text provided for this image
The kernel

Do you see how simple the above kernel is? Basically this midpoint_x(y) defines the center coordinates a and b of the circle by halving the height and width of the image, followed by telling find the index of each thread and storing it as global_pixel_col(row).

Next, we ensure that only the threads that are within the image dimension perform the actual work with the first if-statement and then copy all the pixels to a new array rc,gc,bc representing the red, green and blue color channels of the image.

Lastly, we loop through the image 15 times from the center of the image to the edge of its height while only shading the pixels that meet to send if-statement's criteria.

Let's discuss

Hope you get to try it out sometimes, you can contact me here on LinkedIn or by email if you need some assistance or just for discussion. If you like it too feel free to follow me for more posts in the future

I believe if a former chemical engineering graduate can code then everyone can code

要查看或添加评论,请登录

社区洞察

其他会员也浏览了