CUDA : Constant Memory

Ball, ball, ball, nom nom nom… Here you get.

Normal Ray Tracing

Normal Ray Tracing

Today, I did the Ray Tracing experiment with CUDA. Why Ray Tracing? Ok, the book says if you want to learn what the feel of learning Constant Memory is, you’d better to go with this case. It gonna be fun. Trust me.

What is constant memory? I understood a bit rigid definition about that. It is a kind of memory which have a purpose that the inside data not to be changed during data processing. So, what’s the point? The point is you can, as the developer of CUDA hardware (consider it), build the specialized memory to shorten the processes between writing and reading data. So, Constant Memory is the feature. Because if you use a typical memory, let’s say, RAM, you have to define how to write the data and read the data from it, and of course you have to define synchronization between the two processes so that the data collision won’t occur. It will distribute the writing and the reading time, means, it costs more time. With the constant memory, in the other words, unwrittable memory, you can just only define how to read it, so you won’t have to define the synchronization. No synchronization? Right, if there are more that 1 read processes, we can overcome it with duplication. So, what it means for me? It means that you will need just a little time to manipulate the data. Get it? Right.

So, how can this sample make sense? You must know what is Ray Tracing. Ray Tracing is the way to map the 3D environment into 2D image by tracing the light. The objects which are hit by the light will project it to visual perception, let’s say camera or eyes. So this is the law which can explain why we, human, can see. Yes, the matter reflects the light. Every piece of light from the reflectance contributes to one pixel of the image.

Now the problem, the light can come from everywhere. Can computer compute them? Maybe yes, but slowly. It is complex. Now, let’s make it in reverse. Ray Tracing generates every pixels of an image by evaluating the reflectance. Now, the problem is quite simpler. The method will measure what the light reflectance belongs to and how deep is the reflectance.

Fortunately, as you see, with the condition that the objects won’t change in size, we just need read operation, right? Therefore, we use constant memory. We can recognize an increasing performance by using the constant memory. Here it is.

With Constant Memory

With Constant Memory

It took only 11.7 ms only, while the previous experiment took 14.7 ms. For computer, 3 ms difference is sooo long.

Ok, that’s all. I hope this is good for you.

Posted on Wednesday, 9 January 2013, in Komputer, PORTFOLIO, Programming and tagged , , , , , , . Bookmark the permalink. Leave a comment.

Comments are closed.

%d bloggers like this: