From CPU code to GPU
Afficher commentaires plus anciens
Hello Everybody
I have an heavy code, it's a Split-Step Fourier program, with different external function.
The main vector (the propagating one) is 2^16 to 2^18 point. It currently work as a classic CPU program.
My computer has a CUDADevice with properties: Name: 'Quadro RTX 4000'. So I try to tranlate my program.
Before that I test the speed of the GPU vs CPU with some code I found here. And It's faster, Perfect
To translate my program I do this modification
A=gpuArray(A);
B=gpuArray(B);
And I try to do it for the most variable I have, it's quite long and painfull
I also do it in the function I need to use, to be sure that the most part of the variable are GpuArray
BUT, it's slower...
I never use GPU before, so I guess I am doing something wrong..
Thanks for your time
Martin
Réponses (2)
MartinM
le 19 Août 2021
Joss Knight
le 16 Sep 2021
You need to vectorize your code. The GPU is not intended for performing this kind of looping series of operations on scalar variables. For instance use
k = gpuArray(1:num.n);
T=(k-1)*num.dt-num.tspan/2;
to compute every element of T at once.
You do not need to convert every variable to a gpuArray, just your inputs.
Catégories
En savoir plus sur GPU Computing in MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!