From CPU code to GPU
이전 댓글 표시
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
답변 (2개)
Joss Knight
2021년 9월 16일
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.
카테고리
도움말 센터 및 File Exchange에서 GPU Computing in MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!