Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: histc for gpu
Replies: 3   Last Post: Feb 20, 2014 8:39 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 8,783
Registered: 7/26/08
Re: histc for gpu
Posted: Feb 20, 2014 8:39 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Christian " <proechri@umich.edu> wrote in message <lc1a97$6tt$1@newscl01ah.mathworks.com>...
> 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
>


The best way is perhaps to sort x and x_grid concatenated together, which has an O(N*log(N)) complexity where N is numel(x)+ numel(xgrid). Furthermore the histc engine is possibly programmed in C and very optimal way.

You won't beat it with the trivial for-loop, even with CUDA.

Bruno



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.