error with arrayfun and GPU computing part 2.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Geoff Hayes
il 31 Ott 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.)
Risposta accettata
Edric Ellis
il 31 Ott 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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su GPU Computing in MATLAB in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!