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 CenterFile Exchange에서 GPU Computing in MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by