Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
bbfaf7f
add wrapper for cub::device_segmented_reduce
isVoid Oct 27, 2021
1368645
Merge branch 'branch-21.12' of https://github.com/rapidsai/cudf into …
isVoid Nov 4, 2021
2153108
passes compiles and actually produces correct result for non-null num…
isVoid Nov 5, 2021
329eb39
add todo
isVoid Nov 5, 2021
a8a6d90
Revert "add todo"
isVoid Nov 9, 2021
a9a7b2c
Revert "passes compiles and actually produces correct result for non-…
isVoid Nov 9, 2021
7ccdeb8
Initial pass for reduce sums
isVoid Nov 10, 2021
5072c67
prod, max, min, any, all scaffolding
isVoid Nov 10, 2021
5c4ddb7
Merge branch 'branch-22.02' of github.com:rapidsai/cudf into 9135
isVoid Dec 13, 2021
39db304
Added null_policy handling to segmented reductions
isVoid Dec 14, 2021
51538aa
extend test coverage to NULL_POLICY::INCLUDE and all ops
isVoid Dec 15, 2021
a017223
Moved null mask compute logic to null_mask.cuh with a new helper.
isVoid Jan 6, 2022
ea652c9
Initial pass for benchmark segment reduce
isVoid Jan 8, 2022
5dae89e
Minor doc fixes.
isVoid Jan 11, 2022
7db8c23
Cast return value from std::distance to size_type
isVoid Jan 11, 2022
189c156
Merge branch 'branch-22.04' of github.com:rapidsai/cudf into 9135
isVoid Jan 21, 2022
edd8838
rev: order by alphebets for new entries in CMakeList.txt
isVoid Jan 22, 2022
c02a5b9
Update cpp/benchmarks/reduction/segment_reduce_benchmark.cpp
isVoid Jan 22, 2022
95a5873
Merge branch '9135' of github.com:isVoid/cudf into 9135
isVoid Jan 22, 2022
a1d3be0
rev: reorder benchmark headers
isVoid Jan 22, 2022
7b76179
rev: computes output null count
isVoid Jan 22, 2022
b3767f8
rev: reduction.cuh docstring
isVoid Jan 22, 2022
a951d60
rev: use negate of SFINAE
isVoid Jan 22, 2022
d019de9
rev: Add null_handling param docstring
isVoid Jan 22, 2022
544ee36
rev: fix bad wording in docstring
isVoid Jan 22, 2022
109e3db
Update cpp/include/cudf/reduction.hpp
isVoid Jan 22, 2022
f3d7ae9
Merge branch '9135' of github.com:isVoid/cudf into 9135
isVoid Jan 22, 2022
183098b
rev: docstring fix
isVoid Jan 22, 2022
ee32feb
Docstring updates
isVoid Jan 22, 2022
329120b
Merge branch '9135' of github.com:isVoid/cudf into 9135
isVoid Jan 22, 2022
007c093
rev: docstrings, license fix
isVoid Jan 22, 2022
93c92a9
Update cpp/src/reductions/simple_segmented.cuh
isVoid Jan 22, 2022
8da60f8
Update cpp/src/reductions/simple_segmented.cuh
isVoid Jan 22, 2022
d85ed1a
rev: cleanup includes, docstring fixes
isVoid Jan 22, 2022
c981323
Merge branch '9135' of github.com:isVoid/cudf into 9135
isVoid Jan 22, 2022
61d7942
.
isVoid Jan 22, 2022
61fbdc8
rev: add compute precision todo
isVoid Jan 22, 2022
fc36453
rev: fix includes
isVoid Jan 22, 2022
38221d3
Merge branch 'branch-22.04' of github.com:rapidsai/cudf into 9135
isVoid Jan 28, 2022
71b7211
Rename benchmark file
isVoid Jan 28, 2022
5552c12
fix broken trait usage.
isVoid Jan 28, 2022
0fc27a0
doc fixes
isVoid Jan 28, 2022
75cab7a
Change to lists_column_view interface
isVoid Jan 29, 2022
af08473
add todo
isVoid Jan 29, 2022
26e97e1
Partially Revert "Change to lists_column_view interface", but use `de…
isVoid Feb 3, 2022
11d5b19
Reverting list_column_view interface, expose device_span at public le…
isVoid Feb 3, 2022
6e42663
Merge branch '9135' of github.com:isVoid/cudf into 9135
isVoid Feb 3, 2022
7f2f796
Use aggregation reference
isVoid Feb 3, 2022
1a787a3
Check offset size
isVoid Feb 3, 2022
53e203d
rewrites benchmark with nvbench
isVoid Feb 9, 2022
69cf3a1
Add todo; merge SFINAE checks into `is_supported`.
isVoid Feb 9, 2022
24bb406
A bit more cleanups for benchmark code.
isVoid Feb 14, 2022
32efb1b
Merge branch 'branch-22.04' of github.com:rapidsai/cudf into 9135
isVoid Feb 14, 2022
0846d82
Fix license years
isVoid Feb 14, 2022
71e6753
Header cleanups.
isVoid Feb 14, 2022
f0d9eac
Fixing up wrong license dates. Minor doc improvements.
isVoid Feb 14, 2022
7b49675
Fix doc bug.
isVoid Feb 14, 2022
1911103
Add partial reduction test case; Improve docs
isVoid Feb 17, 2022
5699047
Address clang-tidy
isVoid Feb 17, 2022
70cd617
Remove 1 todo, add 1 todo.
isVoid Feb 17, 2022
4147f48
out of bound index description in docstring.
isVoid Feb 17, 2022
a4317a9
Multiple docstring, error message, todo comment updates.
isVoid Feb 17, 2022
262bb66
Introduce `segmented_reduce_aggregation`.
isVoid Feb 23, 2022
c99a05d
Update cpp/include/cudf/detail/null_mask.cuh
isVoid Feb 23, 2022
282e5d7
Refactors `segmented_null_reduction` based on reviews.
isVoid Feb 23, 2022
8408b48
Update cpp/include/cudf/detail/null_mask.cuh
isVoid Mar 10, 2022
2570f4a
Merge branch 'branch-22.04' of github.com:rapidsai/cudf into 9135
isVoid Mar 10, 2022
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
83 changes: 83 additions & 0 deletions cpp/include/cudf/detail/reduction.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "reduction_operators.cuh"

#include <cudf/column/column_factories.hpp>
#include <cudf/utilities/type_dispatcher.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand All @@ -26,6 +27,7 @@
#include <rmm/exec_policy.hpp>

#include <cub/device/device_reduce.cuh>
#include <cub/device/device_segmented_reduce.cuh>

#include <thrust/for_each.h>
#include <thrust/iterator/iterator_traits.h>
Expand Down Expand Up @@ -218,6 +220,87 @@ std::unique_ptr<scalar> reduce(InputIterator d_in,
return std::unique_ptr<scalar>(result);
}

/**
* @brief Compute the specified simple reduction over each of the segments in the
* input range of elements.
*
* @param[in] d_in the begin iterator to input
* @param[in] d_offset the begin iterator to offset
* @param[in] num_items the number of items
* @param[in] num_segments the number of segments
* @param[in] op the reduction operator
* @param[in] stream CUDA stream used for device memory operations and kernel launches.
* @returns Output scalar in device memory
Comment thread
isVoid marked this conversation as resolved.
Outdated
*
* @tparam Op the reduction operator with device binary operator
* @tparam InputIterator the input column iterator
* @tparam OutputType the output type of reduction
Comment thread
isVoid marked this conversation as resolved.
Outdated
*/
template <typename Op,
typename InputIterator,
typename OffsetIterator,
typename OutputType = typename thrust::iterator_value<InputIterator>::type,
typename std::enable_if_t<is_fixed_width<OutputType>() &&
not cudf::is_fixed_point<OutputType>()>* = nullptr>
std::unique_ptr<column> segmented_reduce(InputIterator d_in,
OffsetIterator d_offset_begin,
cudf::size_type num_segments,
op::simple_op<Op> sop,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
auto binary_op = sop.get_binary_op();
auto identity = sop.template get_identity<OutputType>();
// auto dev_result = rmm::device_scalar<OutputType>{identity, stream, mr};
auto dev_result = make_fixed_width_column(
data_type{type_to_id<OutputType>()}, num_segments, mask_state::UNALLOCATED, stream, mr);
auto dev_result_mview = dev_result->mutable_view();

// Allocate temporary storage
rmm::device_buffer d_temp_storage;
size_t temp_storage_bytes = 0;
cub::DeviceSegmentedReduce::Reduce(d_temp_storage.data(),
temp_storage_bytes,
d_in,
dev_result_mview.data<OutputType>(),
num_segments,
d_offset_begin,
d_offset_begin + 1,
binary_op,
identity,
stream.value());
d_temp_storage = rmm::device_buffer{temp_storage_bytes, stream};

// Run reduction
cub::DeviceSegmentedReduce::Reduce(d_temp_storage.data(),
temp_storage_bytes,
d_in,
dev_result_mview.data<OutputType>(),
num_segments,
d_offset_begin,
d_offset_begin + 1,
binary_op,
identity,
stream.value());

return dev_result;
}

template <typename Op,
typename InputIterator,
typename OffsetIterator,
typename OutputType = typename thrust::iterator_value<InputIterator>::type,
typename std::enable_if_t<std::is_same_v<OutputType, string_view>>* = nullptr>
Comment thread
isVoid marked this conversation as resolved.
Outdated
std::unique_ptr<column> segmented_reduce(InputIterator d_in,
OffsetIterator d_offset_begin,
cudf::size_type num_segments,
op::simple_op<Op> sop,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
CUDF_FAIL("Not supported.");
}

} // namespace detail
} // namespace reduction
} // namespace cudf
14 changes: 11 additions & 3 deletions cpp/include/cudf/detail/reduction_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@

#include <rmm/cuda_stream_view.hpp>

#include <optional>
#include <variant>
namespace cudf {
namespace reduction {

using scalar_or_column_ptr = std::variant<std::unique_ptr<scalar>, std::unique_ptr<column>>;

/**
* @brief Computes sum of elements in input column
*
Expand All @@ -37,8 +42,9 @@ namespace reduction {
* @param mr Device memory resource used to allocate the returned scalar's device memory
* @return Sum as scalar of type `output_dtype`.
*/
std::unique_ptr<scalar> sum(
scalar_or_column_ptr sum(
column_view const& col,
std::optional<std::reference_wrapper<column_view const>> offsets,
data_type const output_dtype,
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
Expand Down Expand Up @@ -135,8 +141,9 @@ std::unique_ptr<scalar> all(
* @param mr Device memory resource used to allocate the returned scalar's device memory
* @return Product as scalar of type `output_dtype`.
*/
std::unique_ptr<scalar> product(
scalar_or_column_ptr product(
column_view const& col,
std::optional<std::reference_wrapper<column_view const>> offsets,
data_type const output_dtype,
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
Expand All @@ -155,8 +162,9 @@ std::unique_ptr<scalar> product(
* @param mr Device memory resource used to allocate the returned scalar's device memory
* @return Sum of squares as scalar of type `output_dtype`.
*/
std::unique_ptr<scalar> sum_of_squares(
scalar_or_column_ptr sum_of_squares(
column_view const& col,
std::optional<std::reference_wrapper<column_view const>> offsets,
data_type const output_dtype,
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
Expand Down
7 changes: 7 additions & 0 deletions cpp/include/cudf/reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ std::unique_ptr<scalar> reduce(
data_type output_dtype,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

std::unique_ptr<column> segment_reduce(
column_view const& col,
column_view const& offsets,
std::unique_ptr<aggregation> const& agg,
Comment thread
isVoid marked this conversation as resolved.
Outdated
data_type output_dtype,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Computes the scan of a column.
*
Expand Down
11 changes: 7 additions & 4 deletions cpp/src/reductions/product.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
namespace cudf {
namespace reduction {

std::unique_ptr<cudf::scalar> product(column_view const& col,
cudf::data_type const output_dtype,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
std::variant<std::unique_ptr<scalar>, std::unique_ptr<column>> product(
column_view const& col,
std::optional<std::reference_wrapper<column_view const>> offsets,
cudf::data_type const output_dtype,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
return cudf::type_dispatcher(
cudf::is_dictionary(col.type()) ? dictionary_column_view(col).keys().type() : col.type(),
simple::element_type_dispatcher<cudf::reduction::op::product>{},
col,
offsets,
output_dtype,
stream,
mr);
Expand Down
34 changes: 26 additions & 8 deletions cpp/src/reductions/reductions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,42 @@
#include <cudf/scalar/scalar_factories.hpp>

#include <cudf/structs/structs_column_view.hpp>
#include <functional>
#include <rmm/cuda_stream_view.hpp>

namespace cudf {
namespace detail {
struct reduce_dispatch_functor {
column_view const col;
std::optional<std::reference_wrapper<column_view const>> offsets;
data_type output_dtype;
rmm::mr::device_memory_resource* mr;
rmm::cuda_stream_view stream;

reduce_dispatch_functor(column_view const& col,
std::optional<std::reference_wrapper<column_view const>> offsets,
data_type output_dtype,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
: col(col), output_dtype(output_dtype), mr(mr), stream(stream)
: col(col), offsets(offsets), output_dtype(output_dtype), mr(mr), stream(stream)
{
}

template <aggregation::Kind k>
std::unique_ptr<scalar> operator()(std::unique_ptr<aggregation> const& agg)
std::variant<std::unique_ptr<scalar>, std::unique_ptr<column>> operator()(
std::unique_ptr<aggregation> const& agg)
{
switch (k) {
case aggregation::SUM: return reduction::sum(col, output_dtype, stream, mr); break;
case aggregation::PRODUCT: return reduction::product(col, output_dtype, stream, mr); break;
case aggregation::SUM: return reduction::sum(col, offsets, output_dtype, stream, mr); break;
case aggregation::PRODUCT:
return reduction::product(col, offsets, output_dtype, stream, mr);
break;
case aggregation::MIN: return reduction::min(col, output_dtype, stream, mr); break;
case aggregation::MAX: return reduction::max(col, output_dtype, stream, mr); break;
case aggregation::ANY: return reduction::any(col, output_dtype, stream, mr); break;
case aggregation::ALL: return reduction::all(col, output_dtype, stream, mr); break;
case aggregation::SUM_OF_SQUARES:
return reduction::sum_of_squares(col, output_dtype, stream, mr);
return reduction::sum_of_squares(col, offsets, output_dtype, stream, mr);
break;
case aggregation::MEAN: return reduction::mean(col, output_dtype, stream, mr); break;
case aggregation::VARIANCE: {
Expand Down Expand Up @@ -107,8 +113,9 @@ struct reduce_dispatch_functor {
}
};

std::unique_ptr<scalar> reduce(
std::variant<std::unique_ptr<scalar>, std::unique_ptr<column>> reduce(
column_view const& col,
std::optional<std::reference_wrapper<column_view const>> offsets,
std::unique_ptr<aggregation> const& agg,
data_type output_dtype,
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
Expand All @@ -124,7 +131,7 @@ std::unique_ptr<scalar> reduce(
}

return aggregation_dispatcher(
agg->kind, reduce_dispatch_functor{col, output_dtype, stream, mr}, agg);
agg->kind, reduce_dispatch_functor{col, offsets, output_dtype, stream, mr}, agg);
}
} // namespace detail

Expand All @@ -134,7 +141,18 @@ std::unique_ptr<scalar> reduce(column_view const& col,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::reduce(col, agg, output_dtype, rmm::cuda_stream_default, mr);
return std::get<0>(
detail::reduce(col, std::nullopt, agg, output_dtype, rmm::cuda_stream_default, mr));
}

std::unique_ptr<column> segment_reduce(column_view const& col,
column_view const& offsets,
std::unique_ptr<aggregation> const& agg,
data_type output_dtype,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return std::get<1>(detail::reduce(col, offsets, agg, output_dtype, rmm::cuda_stream_default, mr));
}

} // namespace cudf
Loading