MATLAB: Matrix multiply slices of 3d Matricies

gpuarraymatrix multiplicationParallel Computing Toolbox

Given two 3d matricies, A and B with
size(A) = (n, m, k)
and
size(B) = (m, p, k)
perform matrix multiplications on each slice obtained by fixing the last index, yielding a matrix C with
size(C) = (n, p, k).
To clarify, we would have
C(:, :, 1) = A(:, :, 1)*B(:, :, 1), ..., C(:, :, k) = A(:, :, k)*B(:, :, k).
I need to do this with gpuArrays in the most efficient manner possible.

Best Answer

If you have MATLAB R2013b, you can use the new gpuArray pagefun function like so:
C = pagefun(@mtimes, A, B);