Using arrayfun is giving me an error

7 ビュー (過去 30 日間)
Ana
Ana 2015 年 11 月 6 日
コメント済み: Ana 2015 年 11 月 6 日
Hello! I have a question about the use of arrayfun and a gpuArray. My function:
function [ pks, locs ] = peakDetector( gpu_signal, freq)
x = (1:numel(gpu_signal));
x = x.';
%%Get All The Peaks
% fetch indices all infinite peaks
iInf = find(isinf(gpu_signal) & gpu_signal>0);
yTemp = gpu_signal;
yTemp(iInf) = NaN;
% Do more stuff
end
And, in my main script, I try to use this function with a gpuArray and arrayfun:
signal_2 = gpuArray(signalCell{2});
[ pks, locs ] = arrayfun(@peakDetector,signal_2, freq);
However, the following error occurs: Function passed as first input argument contains unsupported or unknown function 'colon'. Error in 'peakDetector'
which corresponds to the first line of the function. If I take it off, then there's another error in the 3rd line of the code. If I run the script without a function and declare a lot of variables as gpuArrays, the code works. But it's still not so fast and I wanted do make it faster. According to MATLAB documentation, the built-in functions are overloaded for gpuArrays, so I don't understand what is wrong here. If arrayfun is impossible to use in this situation, would it be doable to parallelize the code with spmd and try to make it faster?

回答 (1 件)

Edric Ellis
Edric Ellis 2015 年 11 月 6 日
arrayfun is designed for purely element-wise operations. Your code appears to be attempting to operate on the whole value of gpu_signal. Does it work simply to call
peakDetector(signal_2, freq);
?
  1 件のコメント
Ana
Ana 2015 年 11 月 6 日
It does. But the thing is, without GPU it takes me almost 15min to run the entire code. With setting a lot of variables as gpuArrauys, takes me 6min. So, I though as a function should be easier, or at least the same time. If I do it like
peakDetector(signal_2, freq);
it takes me 10min to run. Just wanted to see if it was possible to break the code in a faster way. Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGPU Computing in MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by