Michael Litvin
Michael Litvin

Reputation: 4126

How to multiply many gpuArray matrices in parallel?

Given the matrices A1,...,An and B1,...,Bn stored as gpuArray, I want to calculate the matrices Ci=Ai*Bi.

All Ai's are of the same size, and all Bi's are of the same (possibly different) size.

How do I do this fast on the GPU, assuming that n is very large and the sizes of the matrices are relatively small? Is it possible to avoid using CUDA?

Upvotes: 2

Views: 999

Answers (2)

Edric
Edric

Reputation: 25140

If you have MATLAB R2013b, you can use the new gpuArray pagefun function.

Upvotes: 2

Sam Roberts
Sam Roberts

Reputation: 24127

If A and B are of class gpuArray, then the operation C = A*B will be carried out on the GPU without you needing to do anything else. You don't need to write any CUDA. The result C will also be a gpuArray, and you can bring it back to a normal array D in the local workspace with D = gather(C).

Upvotes: 1

Related Questions