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

Move detail reduction functions to cudf::reduction::detail namespace #12971

Merged
merged 13 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions conda/recipes/libcudf/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ outputs:
- test -f $PREFIX/include/cudf/detail/nvtx/nvtx3.hpp
- test -f $PREFIX/include/cudf/detail/nvtx/ranges.hpp
- test -f $PREFIX/include/cudf/detail/quantiles.hpp
- test -f $PREFIX/include/cudf/detail/reduction_functions.hpp
- test -f $PREFIX/include/cudf/detail/repeat.hpp
- test -f $PREFIX/include/cudf/detail/replace.hpp
- test -f $PREFIX/include/cudf/detail/reshape.hpp
Expand All @@ -123,7 +122,6 @@ outputs:
- test -f $PREFIX/include/cudf/detail/scan.hpp
- test -f $PREFIX/include/cudf/detail/scatter.hpp
- test -f $PREFIX/include/cudf/detail/search.hpp
- test -f $PREFIX/include/cudf/detail/segmented_reduction_functions.hpp
- test -f $PREFIX/include/cudf/detail/sequence.hpp
- test -f $PREFIX/include/cudf/detail/sorting.hpp
- test -f $PREFIX/include/cudf/detail/stream_compaction.hpp
Expand Down Expand Up @@ -218,6 +216,8 @@ outputs:
- test -f $PREFIX/include/cudf/partitioning.hpp
- test -f $PREFIX/include/cudf/quantiles.hpp
- test -f $PREFIX/include/cudf/reduction.hpp
- test -f $PREFIX/include/cudf/reduction/detail/reduction_functions.hpp
- test -f $PREFIX/include/cudf/reduction/detail/segmented_reduction_functions.hpp
- test -f $PREFIX/include/cudf/replace.hpp
- test -f $PREFIX/include/cudf/reshape.hpp
- test -f $PREFIX/include/cudf/rolling.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include <cudf/detail/reduction_operators.cuh>
#include "reduction_operators.cuh"

#include <cudf/column/column_factories.hpp>
#include <cudf/utilities/type_dispatcher.hpp>
Expand All @@ -31,6 +31,8 @@
#include <thrust/for_each.h>
#include <thrust/iterator/iterator_traits.h>

#include <optional>

namespace cudf {
namespace reduction {
namespace detail {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace cudf {
namespace reduction {
namespace detail {
/**
* @brief Computes sum of elements in input column
*
Expand Down Expand Up @@ -323,5 +324,6 @@ std::unique_ptr<scalar> merge_sets(lists_column_view const& col,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

} // namespace detail
} // namespace reduction
} // namespace cudf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION.
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@

namespace cudf {
namespace reduction {
namespace detail {
// intermediate data structure to compute `var`, `std`
template <typename ResultType>
struct var_std {
Expand Down Expand Up @@ -244,7 +245,7 @@ struct variance : public compound_op<variance> {
using op = cudf::DeviceSum;

template <typename ResultType>
using transformer = cudf::reduction::transformer_var_std<ResultType>;
using transformer = cudf::reduction::detail::transformer_var_std<ResultType>;

template <typename ResultType>
struct intermediate {
Expand All @@ -270,7 +271,7 @@ struct standard_deviation : public compound_op<standard_deviation> {
using op = cudf::DeviceSum;

template <typename ResultType>
using transformer = cudf::reduction::transformer_var_std<ResultType>;
using transformer = cudf::reduction::detail::transformer_var_std<ResultType>;

template <typename ResultType>
struct intermediate {
Expand All @@ -288,7 +289,7 @@ struct standard_deviation : public compound_op<standard_deviation> {
};
};
};

} // namespace op
} // namespace detail
} // namespace reduction
} // namespace cudf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include <cudf/detail/reduction_operators.cuh>
#include "reduction_operators.cuh"

#include <rmm/cuda_stream_view.hpp>
#include <rmm/device_buffer.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace cudf {
namespace reduction {
namespace detail {

/**
* @brief Compute sum of each segment in the input column
Expand All @@ -50,14 +51,13 @@ namespace reduction {
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Sums of segments as type `output_dtype`
*/
std::unique_ptr<column> segmented_sum(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_sum(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Computes product of each segment in the input column
Expand All @@ -81,14 +81,13 @@ std::unique_ptr<column> segmented_sum(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Product of segments as type `output_dtype`
*/
std::unique_ptr<column> segmented_product(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_product(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Compute minimum of each segment in the input column
Expand All @@ -111,14 +110,13 @@ std::unique_ptr<column> segmented_product(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Minimums of segments as type `output_dtype`
*/
std::unique_ptr<column> segmented_min(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_min(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Compute maximum of each segment in the input column
Expand All @@ -141,14 +139,13 @@ std::unique_ptr<column> segmented_min(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Maximums of segments as type `output_dtype`
*/
std::unique_ptr<column> segmented_max(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_max(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Compute if any of the values in the segment are true when typecasted to bool
Expand All @@ -172,14 +169,13 @@ std::unique_ptr<column> segmented_max(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Column of type BOOL8 for the results of the segments
*/
std::unique_ptr<column> segmented_any(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_any(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Compute if all of the values in the segment are true when typecasted to bool
Expand All @@ -203,14 +199,13 @@ std::unique_ptr<column> segmented_any(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Column of BOOL8 for the results of the segments
*/
std::unique_ptr<column> segmented_all(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_all(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
std::optional<std::reference_wrapper<scalar const>> init,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Computes mean of elements of segments in the input column
Expand All @@ -233,13 +228,12 @@ std::unique_ptr<column> segmented_all(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Column of `output_dtype` for the reduction results of the segments
*/
std::unique_ptr<column> segmented_mean(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_mean(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Computes sum of squares of elements of segments in the input column
Expand All @@ -262,13 +256,12 @@ std::unique_ptr<column> segmented_mean(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Column of `output_dtype` for the reduction results of the segments
*/
std::unique_ptr<column> segmented_sum_of_squares(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_sum_of_squares(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Computes the standard deviation of elements of segments in the input column
Expand All @@ -293,14 +286,13 @@ std::unique_ptr<column> segmented_sum_of_squares(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Column of `output_dtype` for the reduction results of the segments
*/
std::unique_ptr<column> segmented_standard_deviation(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
size_type ddof,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_standard_deviation(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
size_type ddof,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @brief Computes the variance of elements of segments in the input column
Expand All @@ -325,14 +317,14 @@ std::unique_ptr<column> segmented_standard_deviation(
* @param mr Device memory resource used to allocate the returned column's device memory
* @return Column of `output_dtype` for the reduction results of the segments
*/
std::unique_ptr<column> segmented_variance(
column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
size_type ddof,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
std::unique_ptr<column> segmented_variance(column_view const& col,
device_span<size_type const> offsets,
data_type const output_dtype,
null_policy null_handling,
size_type ddof,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

} // namespace detail
} // namespace reduction
} // namespace cudf
16 changes: 9 additions & 7 deletions cpp/src/lists/stream_compaction/apply_boolean_mask.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/replace.hpp>
#include <cudf/detail/segmented_reduction_functions.hpp>
#include <cudf/detail/stream_compaction.hpp>
#include <cudf/lists/detail/stream_compaction.hpp>
#include <cudf/lists/stream_compaction.hpp>
#include <cudf/reduction/detail/segmented_reduction_functions.hpp>
#include <cudf/utilities/bit.hpp>
#include <cudf/utilities/default_stream.hpp>

Expand Down Expand Up @@ -65,12 +65,14 @@ std::unique_ptr<column> apply_boolean_mask(lists_column_view const& input,
cudf::detail::slice(
boolean_mask.offsets(), {boolean_mask.offset(), boolean_mask.size() + 1}, stream)
.front();
auto const sizes = cudf::reduction::segmented_sum(boolean_mask_sliced_child,
boolean_mask_sliced_offsets,
offset_data_type,
null_policy::EXCLUDE,
std::nullopt,
stream);
auto const sizes =
cudf::reduction::detail::segmented_sum(boolean_mask_sliced_child,
boolean_mask_sliced_offsets,
offset_data_type,
null_policy::EXCLUDE,
std::nullopt,
stream,
rmm::mr::get_current_device_resource());
auto const d_sizes = column_device_view::create(*sizes, stream);
auto const sizes_begin = cudf::detail::make_null_replacement_iterator(*d_sizes, offset_type{0});
auto const sizes_end = sizes_begin + sizes->size();
Expand Down
Loading