error with arrayfun and GPU computing part 2.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mikhail
am 31 Okt. 2014
Kommentiert: Mikhail
am 3 Nov. 2014
I am tring to compute simple example on GPU:
function C=myf(A,B,N)
for i=1:N
C(:,:,i)=(A(:,:,i)*B)^10;
end
end
With CPU it works:
M = 100;
K = 100;
N = 1000;
A=rand(M,K,N);
B=rand(K,M);
C=myf(A,B,N);
With GPU:
if true
Aongpu=gpuArray(A);
Bongpu=gpuArray(B);
C=arrayfun(@myf,Aongpu,Bongpu,N);
end
It doesn't:
Error using parallel.gpu.GPUArray/arrayfun Matrix dimensions must agree.
Why?? Thanks in advance
1 Kommentar
Geoff Hayes
am 31 Okt. 2014
Mikhail - I'm not sure if using arrayfun in this manner is appropriate/correct. The documentation indicates
Nonsingleton dimensions of input arrays must match each other. In other words, the corresponding dimensions of arguments B, C, etc., must be equal to each other, or equal to one. Whenever a dimension of an input array is singleton (equal to 1), arrayfun uses singleton expansion to virtually replicate the array along that dimension to match the largest of the other arrays in that dimension…
Given the examples (from the above link), this seems to suggest that your B and N would be expanded to MxKxN arrays, and your myf function would be then applied to each element within these identically sized inputs. (This is similar to the non-GPU version of arrayfun where each array input must be of the same dimension.)
Akzeptierte Antwort
Edric Ellis
am 31 Okt. 2014
When working with gpuArray data, the function that you pass to the arrayfun will be called with scalar values. In other words, your myf needs to accept scalars and return scalars, like so:
M = 100;
K = 100;
N = 1000;
A=rand(M,K,N);
B=rand(K,M);
myf = @(a, b, n) a + b + n % or something more appropriate
arrayfun(myf, gpuArray(A), gpuArray(B), N);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu GPU Computing in MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!