Why numel() is not accepted with a gpuArray
显示 更早的评论
pcGpu = gpuArray(5:100);
r = arrayfun( @numel, pcGpu );
simple line of code above, although numel is supported with gpuArray, I still get following feedback:
Function passed as first input argument contains unsupported or unknown function 'numel'.
For more information see Tips.
Am I doing sth. wrong?
Thanks, Song
5 个评论
Walter Roberson
2022-9-14
Why would you want to apply numel to each entry in a gpu Array? It would be asking for numel() of a scalar at each step, so the effect would be the same as ones(size(pcGpu), 'gpuArray')
Song Decn
2022-9-15
Song Decn
2022-9-15
编辑:Walter Roberson
2022-9-15
Walter Roberson
2022-9-15
Are you applying numel to the entire array, or are you applying numel to each element of an array? When you use arrayfun then by definition the function is passed one element of the array.
arrayfun over a gpuArray does not support anonymous functions with captured variables.
Walter Roberson
2022-9-15
for i = 1:numel(a)
f = pcGpu + i;
end
That overwrites all of f each iteration, so if you could get it to work, the result would be the same as if you had done
i = numel(a);
f = pcGpu + numel(a);
Reminder: you can pass numel(a) in as a parameter.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 GPU Computing in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!