Asked by Aurimas
on 16 Feb 2013

I am calculating an equation A*x=B, where A is a matrix and B is a vector, x is answer (unknown) vector.

Hardware specs: Intel i7 3630QM (4 cores), nVidia GeForce GT 640M (384 CUDA cores)

Here's an example:

>> A=rand(5000);

>> B=rand(5000,1);

>> Agpu=gpuArray(A);

>> Bgpu=gpuArray(B);

>> tic;A\B;toc;

Elapsed time is 1.382281 seconds.

>> tic;Agpu\Bgpu;toc;

Elapsed time is 4.775395 seconds.

Somehow GPU is much slower... Why? It is also slower in FFT, INV, LU calculations, which should be related with matrix division.

However, GPU is much faster in matrix multiplication (with the same data):

>> tic;A*B;toc;

Elapsed time is 0.014700 seconds.

>> tic;Agpu*Bgpu;toc;

Elapsed time is 0.000505 seconds.

The main question is why GPU A\B (mldivide) is so slow comparing to CPU?

Answer by Jill Reese
on 19 Feb 2013

Accepted Answer

To get accurate timings for GPU calculations you need to be sure to wait for the GPU to finish. You should modify all your timings accordingly:

g = gpuDevice();

tic;

f = fft(A);

wait(g);

toc;

Also, not all GPUs are created equal. To get a sense of what performance you can expect from your GPU in relation to other devices out there, you may want to run gpuBench which can be found here:

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Aurimas (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/63692-matlab-cuda-slow-in-solving-matrix-vector-equation-a-x-b#comment_130041

Sign in to comment.