How to implement reduce by key using cudpp primitives?

50 views
Skip to first unread message

Lior Zeno

unread,
Sep 16, 2015, 5:17:27 PM9/16/15
to CUDPP
I have two arrays - keys and values, and I would like to implement reduce by key using CUDPP primitives. 

A simple algorithm should be:
1. Sort by key (radix sort)
2. Segmented scan
3. Compact

So basically, there are two main issues here:

1. How to calculate the flags (the binary array which represents the segments' boundaries)?
2. Is it the most efficient way to do that? 

Thanks

John Owens

unread,
Sep 16, 2015, 7:47:00 PM9/16/15
to CUDPP
When there's a CUB primitive that does exactly what you want:

http://nvlabs.github.io/cub/structcub_1_1_device_reduce.html#a3206c7c11b4d894ca176482e86215b02

it's not likely that either CUDPP nor any other library will beat it.
That being said, to answer your Q#1, you could do a map over all
items where each thread fetches its item and the item to its left
and outputs a 1 if those two items are different. That should be
reasonably efficient.

(In an ideal world, that operation would be integrated into the
first segmented-scan kernel.)

JDO

Lior Zeno

unread,
Sep 16, 2015, 11:35:15 PM9/16/15
to CUDPP
Thanks for your reply.

I am aware of CUB, however it does not have a Java interface and I am working with JCuda. Is there a way I could use this implementation using a Java Api?

Mark Harris

unread,
Sep 17, 2015, 1:06:02 AM9/17/15
to cu...@googlegroups.com
You could write an extern "C" function that calls thrust::reduce_by_key(), and then call that from JNI. Or write a Kernel that uses CUB's equivalent, and launch it using JCuda.

Mark

On Thu, Sep 17, 2015 at 1:35 PM, Lior Zeno <lior...@gmail.com> wrote:
Thanks for your reply.

I am aware of CUB, however it does not have a Java interface and I am working with JCuda. Is there a way I could use this implementation using a Java Api?

--
You received this message because you are subscribed to the Google Groups "CUDPP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cudpp+un...@googlegroups.com.
To post to this group, send email to cu...@googlegroups.com.
Visit this group at http://groups.google.com/group/cudpp.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages