Column-wise dot-products of two gpuArrays

조회 수: 2 (최근 30일)
Ahmed
Ahmed 2013년 9월 5일
Is there a good way to compute column-wise dot-products of two matrices of same size when stored on the GPU? Specifically, say A and B are n (rows) times m (columns) matrices, I seek to find the 1 (row) times m (columns) row-vector of dot-products of the columns of A and B (i.e. the diagonal elements of the dot-product matrix). Following minimum working example demonstrates the computations:
n = 10;
m = 100;
A = randn(n,m);
B = randn(n,m);
C = bsxfun(@dot,A,B);
However, if A and B are gpuArrays, then this is not possible:
C = bsxfun(@dot,gpuArray(A),gpuArray(B));
% Error using gpuArray/bsxfun
% Use of 'dot' is not supported
Similarly, using anonymous function '@(a,b) a'*b' instead of '@dot' does not work. In my application n is roughly 100 and m roughly 500000. Hope that someone has an idea how C can be computed directly on the GPU and without for loops, as this was very slow for the given problem size.
Ahmed --

채택된 답변

Ahmed
Ahmed 2013년 9월 5일
A possible solution (I hope it will be helpful to someone):
C = sum(gpuArray(A).*gpuArray(B));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by