Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA and MATLAB for loop optimization

I'm going to attempt to optimize some code written in MATLAB, by using CUDA. I recently started programming CUDA, but I've got a general idea of how it works.

So, say I want to add two matrices together. In CUDA, I could write an algorithm that would utilize a thread to calculate the answer for each element in the result matrix. However, isn't this technique probably similar to what MATLAB already does? In that case, wouldn't the efficiency be independent of the technique and attributable only to the hardware level?

like image 641
dnbwise Avatar asked Oct 13 '22 19:10

dnbwise


2 Answers

The technique might be similar but remember with CUDA you have hundreds of threads running simultaneously. If MATLAB is using threads and those threads are running on a Quad core, you are only going to get 4 threads excuted per clock cycle while you might achieve a couple of hundred threads to run on CUDA with that same clock cycle.

So to answer you question, YES, the efficiency in this example is independent of the technique and attributable only to the hardware.

like image 189
Jose Vega Avatar answered Nov 16 '22 09:11

Jose Vega


The answer is unequivocally yes, all the efficiencies are hardware level. I don't how exactly matlab works, but the advantage of CUDA is that mutltiple threads can be executed simultaneously, unlike matlab.

On a side note, if your problem is small, or requires many read write operations, CUDA will probably only be an additional headache.

like image 23
Marm0t Avatar answered Nov 16 '22 10:11

Marm0t