How to run arrayfun with a GPU?
5 ビュー (過去 30 日間)
古いコメントを表示
Using MATLAB version 7.14.0.739 (R2012a) and the Parallel Computing Toolkit ver 6.0, I've been unable to get a simple test case to run.
The file "getHighRandValue.m" has the code
function [highvalue] = getHighRandValue(outerbound)
dist=randn(outerbound,1);
% dist=parallel.gpu.GPUArray.randn(outerbound,1);
highvalue=max(dist);
end
and the file "testarrayfun.m" has the code
outerbound = parallel.gpu.GPUArray.colon(1,10);
for i=1:length(outerbound)
outerbound(i)=2*i;
end
[highvalue]=arrayfun(@getHighRandValue, outerbound);
highvalue=gather(highvalue)
Running this script gives the message
Error using parallel.gpu.GPUArray/arrayfun
Too many arguments supplied to: 'randn'. error at line: 2
Error in testarrayfun (line 5)
[highvalue]=arrayfun(@getHighRandValue, outerbound);
I don't understand this error messages in this context. The Help file seems to support this usage of randn. Anyway, replacing line #2 in "getHighRandValue.m" (by toggling the comments) with
dist=parallel.gpu.GPUArray.randn(outerbound,1);
Gives a different error message:
Error using parallel.gpu.GPUArray/arrayfun
Undefined function or variable 'outerbound'.
Error in testarrayfun (line 5)
[highvalue]=arrayfun(@getHighRandValue, outerbound);
As before, I don't understand the error message in this context. Any help getting this simple example to work would be most appreciated.
Greg
0 件のコメント
採用された回答
Narfi
2012 年 6 月 2 日
Inside arrayfun, one can only perform computations with scalars, so vector and matrix computations are not supported. In particular, one cannot create random matrices.
Having said that, you can easily write loops, create multiple random numbers, etc., so the equivalent functionality of the example code would be achieved via:
function highvalue = getHighRandValue(outerbound)
highvalue = -inf;
for i = 1:outerbound
highvalue = max(highvalue, randn());
end
end
Best,
Narfi
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で GPU Computing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!