Memory efficient multiplication of large matrices on GPU

3 views (last 30 days)
Dear community,
I would like to use the GPU enabled functions of MATLAB to perform quick matrix multiplications. I already discussed the fundamental idea here: https://uk.mathworks.com/matlabcentral/answers/363627-gpu-enabled-functions-react-slow-on-first-call
Since gDexMat is very big, the GPU quickly runs out of memory. However, gDexMat itself can be calculated on the fly from vectors as follows:
>> x0=400e3;
>> Xs=200e6;
>> n=500;
>> a=gpuArray((x0:x0:Xs/2));
>> b=gpuArray((1/Xs:1/Xs:n/x0)');
>> gDexMat=cos(a*b);
>> whos a b gDexMat
Name Size Bytes Class Attributes
a 1x250 4 gpuArray
b 250000x1 4 gpuArray
gDexMat 50000x250 4 gpuArray
The desired operation is:
>> whos Sig
Name Size Bytes Class Attributes
Sig 100x250000 4 gpuArray
>> Result=Sig*gDexMat;
>> whos Result
Name Size Bytes Class Attributes
Result 100x250 4 gpuArray
which could of course also be written as:
>> Result=Sig*cos(a*b);
In this case however, it appears as if the result of cos(a*b) is calculated first and than multiplied with Sig, causing the GPU to run out of memory again. Even switching to single precision did not help much.
Is there an efficent way to perform this operation on the GPU? Perhaps, the "funarray" functions could solve this issue? If so, could somebody provide me with an example on how to do so?
Thanks for your help,
Ludwig

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!