Path: news.mathworks.com!not-for-mail
From: "Christian " <proechri@umich.edu>
Newsgroups: comp.soft-sys.matlab
Subject: histc for gpu
Date: Sat, 25 Jan 2014 21:28:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <lc1a97$6tt$1@newscl01ah.mathworks.com>
Reply-To: "Christian " <proechri@umich.edu>
NNTP-Posting-Host: rubyext-03-ls.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1390685287 7101 172.20.102.179 (25 Jan 2014 21:28:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 25 Jan 2014 21:28:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3858030
Xref: news.mathworks.com comp.soft-sys.matlab:808127

Hi,

I hope to use histc on CUDA, but it's not a supported function. So I tried a workaround because I'm actually just interested in the second output argument:

[~,ind] = histc(x,x_grid);

is more or less equivalent to the following code (except for points outside the grid).

ind=ones(size(x));
for j=1:length(x_grid)-1
    ind(x>=x_grid(j) & x<x_grid(j+1)) = j;
end

But this latter code is much slower than histc, probably due to the loop. For instance, for my inputs the first code requires 0.03 seconds, the latter needs 1.8 seconds.

Is it possible to speed up the second code so that I can still run it on CUDA?

Thanks,
Christian