Skip to content

Commit

Permalink
Avoid ::result_type for partial sums in TBB reduce_by_key (NVIDIA#1998
Browse files Browse the repository at this point in the history
)

This allows us to get rid of partial_sum_type, which still uses the C++11-deprecated function object API ::result_type.

Co-authored-by: Georgii Evtushenko <[email protected]>
  • Loading branch information
2 people authored and pciolkosz committed Aug 4, 2024
1 parent 17fa3bb commit 9255c20
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions thrust/thrust/system/tbb/detail/reduce_by_key.inl
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,12 @@ inline L divide_ri(const L x, const R y)
template <typename InputIterator, typename BinaryFunction, typename SFINAE = void>
struct partial_sum_type
{
using type = typename thrust::iterator_value<InputIterator>::type;
};

template <typename InputIterator, typename BinaryFunction>
struct partial_sum_type<InputIterator, BinaryFunction, ::cuda::std::void_t<typename BinaryFunction::result_type>>
{
using type = typename BinaryFunction::result_type;
using type = thrust::iterator_value_t<InputIterator>;
};

template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate, typename BinaryFunction>
thrust::pair<InputIterator1,
thrust::pair<typename thrust::iterator_value<InputIterator1>::type,
thrust::pair<thrust::iterator_value_t<InputIterator1>,
typename partial_sum_type<InputIterator2, BinaryFunction>::type>>
reduce_last_segment_backward(
InputIterator1 keys_first,
Expand All @@ -90,7 +84,7 @@ reduce_last_segment_backward(
thrust::reverse_iterator<InputIterator1> keys_last_r(keys_first);
thrust::reverse_iterator<InputIterator2> values_first_r(values_first + n);

typename thrust::iterator_value<InputIterator1>::type result_key = *keys_first_r;
thrust::iterator_value_t<InputIterator1> result_key = *keys_first_r;
typename partial_sum_type<InputIterator2, BinaryFunction>::type result_value = *values_first_r;

// consume the entirety of the first key's sequence
Expand All @@ -111,7 +105,7 @@ template <typename InputIterator1,
typename BinaryFunction>
thrust::tuple<OutputIterator1,
OutputIterator2,
typename thrust::iterator_value<InputIterator1>::type,
thrust::iterator_value_t<InputIterator1>,
typename partial_sum_type<InputIterator2, BinaryFunction>::type>
reduce_by_key_with_carry(
InputIterator1 keys_first,
Expand All @@ -124,8 +118,7 @@ reduce_by_key_with_carry(
{
// first, consume the last sequence to produce the carry
// XXX is there an elegant way to pose this such that we don't need to default construct carry?
thrust::pair<typename thrust::iterator_value<InputIterator1>::type,
typename partial_sum_type<InputIterator2, BinaryFunction>::type>
thrust::pair<thrust::iterator_value_t<InputIterator1>, typename partial_sum_type<InputIterator2, BinaryFunction>::type>
carry;

thrust::tie(keys_last, carry) =
Expand Down Expand Up @@ -215,7 +208,7 @@ struct serial_reduce_by_key_body
Iterator6 my_carry_result = carry_result + interval_idx;

// consume the rest of the interval with reduce_by_key
using key_type = typename thrust::iterator_value<Iterator1>::type;
using key_type = thrust::iterator_value_t<Iterator1>;
using value_type = typename partial_sum_type<Iterator2, BinaryFunction>::type;

// XXX is there a way to pose this so that we don't require default construction of carry?
Expand Down

0 comments on commit 9255c20

Please sign in to comment.