3

Thrust has the thrust::reduce_by_key algorithm which works well for a problem of mine. I wanted to try to use CUB for finer control of memory and streams as well as interaction with my own kernels, but there doesn't seem to be a reduce_by_key equivalent in CUB. There is cub::DeviceSegmentedReduce but it doesn't seem to output a key order, and I would need to find the start of each consecutive segment of keys beforehand which is its own problem.

The problem is to reduce an array of key-value pairs into an array where all keys are unique, and each value has the reduction of all same-key values.

Is there an easy way to do this with CUB that I am not seeing?

0

1 Answer 1

3

Yes, the algorithm you are searching for is called cub::DeviceReduce::ReduceByKey. For some reason* it is categorized as reduction instead of as segmented reduction which is certainly confusing.


*: Maybe cub::DeviceSegmentedReduce is a more recent addition and they didn't want to break backward compatibility by moving ReduceByKey out of DeviceReduce.

1
  • I completely missed that DeviceReduce had a lot of other algorithms hidden further down the page... thanks.
    – Treeman
    Commented Nov 15, 2024 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.