Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiplying hundreds of matrices using cuda

I am writing a program which requires to multiply hundreds of matrices in parallel using CUDA. Can somebody explain how to perform this operation.

I have seen that Kepler architecture is capable of dynamic parallelism. Has somebody used this architecture and if yes, which Nvidia graphics card.

like image 786
user1771081 Avatar asked Nov 13 '22 19:11

user1771081


1 Answers

The easiest way to get fast performing matrix multiply in parallel using CUDA is through the ArrayFire CUDA library using the GFOR loop. Here's some code that does what you want:

int n = 8, int m = 8;   // dimensions
int t = 10;             // number of different matricies
array A = randu(m,n,t); // many matricies
array B = randu(m,n);   // one matrix
array C = zeros(m,n,t); // destination

// multiply C=A*B for all A, at the same time
gfor (array i, A.dims(2)) {
    C(span,span,i) = matmul(A(span,span,i), B);
}

print( A );
print( B );
print( C );

ArrayFire automatically tiles out the computation efficiently for execution on the GPU. All that is optimized behind the scenes for you. I find it to be faster than trying to write it by hand myself.

like image 60
Ben Stewart Avatar answered Dec 22 '22 02:12

Ben Stewart