Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ::result_type for partial sums in TBB reduce_by_key #1998

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading