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

Remove UNKNOWN_NULL_COUNT where it can be easily computed #13205

Merged
merged 9 commits into from
Apr 26, 2023
10 changes: 8 additions & 2 deletions cpp/include/cudf/structs/structs_column_view.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-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 @@ -17,6 +17,9 @@

#include <cudf/column/column.hpp>
#include <cudf/column/column_view.hpp>
#include <cudf/utilities/default_stream.hpp>

#include <rmm/cuda_stream_view.hpp>

/**
* @file
Expand Down Expand Up @@ -87,9 +90,12 @@ class structs_column_view : public column_view {
* @throw cudf::logic error if this is an empty column
*
* @param index The index of the child column to return
* @param stream The stream on which to perform the operation. Uses the default CUDF
* stream if none is specified.
vyasr marked this conversation as resolved.
Show resolved Hide resolved
* @return The child column sliced relative to the parent's offset and size
*/
[[nodiscard]] column_view get_sliced_child(int index) const;
[[nodiscard]] column_view get_sliced_child(
int index, rmm::cuda_stream_view stream = cudf::get_default_stream()) const;
vyasr marked this conversation as resolved.
Show resolved Hide resolved
}; // class structs_column_view;
/** @} */ // end of group
} // namespace cudf
8 changes: 6 additions & 2 deletions cpp/src/lists/copying/copying.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
* Copyright (c) 2020-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 @@ -19,6 +19,7 @@
#include <cudf/detail/get_value.cuh>
#include <cudf/detail/null_mask.hpp>
#include <cudf/lists/lists_column_view.hpp>
#include <cudf/types.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>
Expand Down Expand Up @@ -81,10 +82,13 @@ std::unique_ptr<cudf::column> copy_slice(lists_column_view const& lists,
// Compute the null mask of the result:
auto null_mask = cudf::detail::copy_bitmask(lists.null_mask(), start, end, stream, mr);

auto null_count = cudf::detail::null_count(
static_cast<bitmask_type const*>(null_mask.data()), 0, end - start, stream);

return make_lists_column(lists_count,
std::move(offsets),
std::move(child),
cudf::UNKNOWN_NULL_COUNT,
null_count,
std::move(null_mask),
stream,
mr);
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/strings/copying/copying.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, 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 Down Expand Up @@ -73,10 +73,13 @@ std::unique_ptr<cudf::column> copy_slice(strings_column_view const& strings,
auto null_mask = cudf::detail::copy_bitmask(
strings.null_mask(), offsets_offset, offsets_offset + strings_count, stream, mr);

auto null_count = cudf::detail::null_count(
static_cast<bitmask_type const*>(null_mask.data()), 0, strings_count, stream);

return make_strings_column(strings_count,
std::move(offsets_column),
std::move(chars_column),
UNKNOWN_NULL_COUNT,
null_count,
std::move(null_mask));
}

Expand Down
26 changes: 15 additions & 11 deletions cpp/src/structs/structs_column_view.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
* Copyright (c) 2020-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 @@ -15,7 +15,9 @@
*/

#include <cudf/column/column.hpp>
#include <cudf/detail/null_mask.hpp>
#include <cudf/structs/structs_column_view.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/error.hpp>

namespace cudf {
Expand All @@ -27,22 +29,24 @@ structs_column_view::structs_column_view(column_view const& rhs) : column_view{r

column_view structs_column_view::parent() const { return *this; }

column_view structs_column_view::get_sliced_child(int index) const
column_view structs_column_view::get_sliced_child(int index, rmm::cuda_stream_view stream) const
{
std::vector<column_view> children;
children.reserve(child(index).num_children());
for (size_type i = 0; i < child(index).num_children(); i++) {
children.push_back(child(index).child(i));
}
return column_view{child(index).type(),
size(),
child(index).head<uint8_t>(),
child(index).null_mask(),
// TODO: could potentially compute the actual count here, but at
// the moment this interface doesn't take a stream.
UNKNOWN_NULL_COUNT,
offset(),
children};

return column_view{
child(index).type(),
size(),
child(index).head<uint8_t>(),
child(index).null_mask(),
child(index).null_count()
? cudf::detail::null_count(child(index).null_mask(), offset(), offset() + size(), stream)
: 0,
offset(),
children};
}

} // namespace cudf
11 changes: 6 additions & 5 deletions cpp/src/structs/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ std::unique_ptr<column> superimpose_nulls_no_sanitize(bitmask_type const* null_m
auto content = input->release();

// Build new children columns.
std::for_each(
content.children.begin(), content.children.end(), [current_mask, stream, mr](auto& child) {
child = superimpose_nulls_no_sanitize(
current_mask, cudf::UNKNOWN_NULL_COUNT, std::move(child), stream, mr);
});
std::for_each(content.children.begin(),
content.children.end(),
[current_mask, new_null_count, stream, mr](auto& child) {
child = superimpose_nulls_no_sanitize(
current_mask, new_null_count, std::move(child), stream, mr);
});

// Replace the children columns.
return cudf::make_structs_column(num_rows,
Expand Down