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

Fix memory read/write error in concatenate_lists_ignore_null #8978

Merged
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
42 changes: 18 additions & 24 deletions cpp/src/lists/combine/concatenate_list_elements.cu
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,9 @@ std::unique_ptr<column> concatenate_lists_ignore_null(column_view const& input,
auto out_offsets = make_numeric_column(
data_type{type_id::INT32}, num_rows + 1, mask_state::UNALLOCATED, stream, mr);

// The array of int8_t stores validities for the output list elements.
auto validities = rmm::device_uvector<int8_t>(build_null_mask ? num_rows : 0, stream);

auto const d_out_offsets = out_offsets->mutable_view().template begin<offset_type>();
auto const d_row_offsets = lists_column_view(input).offsets_begin();
auto const d_list_offsets = lists_column_view(lists_column_view(input).child()).offsets_begin();
auto const lists_dv_ptr = column_device_view::create(lists_column_view(input).child());

// Concatenating the lists at the same row by converting the entry offsets from the child column
// into row offsets of the root column. Those entry offsets are subtracted by the first entry
Expand All @@ -67,22 +63,7 @@ std::unique_ptr<column> concatenate_lists_ignore_null(column_view const& input,
iter,
iter + num_rows + 1,
d_out_offsets,
[d_row_offsets,
d_list_offsets,
lists_dv = *lists_dv_ptr,
d_validities = validities.begin(),
build_null_mask,
iter] __device__(auto const idx) {
if (build_null_mask) {
// The output row will be null only if all lists on the input row are null.
auto const is_valid = thrust::any_of(thrust::seq,
iter + d_row_offsets[idx],
iter + d_row_offsets[idx + 1],
[&] __device__(auto const list_idx) {
return lists_dv.is_valid(list_idx);
});
d_validities[idx] = static_cast<int8_t>(is_valid);
}
[d_row_offsets, d_list_offsets] __device__(auto const idx) {
auto const start_offset = d_list_offsets[d_row_offsets[0]];
return d_list_offsets[d_row_offsets[idx]] - start_offset;
});
Expand All @@ -92,10 +73,23 @@ std::unique_ptr<column> concatenate_lists_ignore_null(column_view const& input,
lists_column_view(lists_column_view(input).get_sliced_child(stream)).get_sliced_child(stream));

auto [null_mask, null_count] = [&] {
return build_null_mask
? cudf::detail::valid_if(
validities.begin(), validities.end(), thrust::identity<int8_t>{}, stream, mr)
: std::make_pair(cudf::detail::copy_bitmask(input, stream, mr), input.null_count());
if (!build_null_mask)
return std::make_pair(cudf::detail::copy_bitmask(input, stream, mr), input.null_count());

// The output row will be null only if all lists on the input row are null.
auto const lists_dv_ptr = column_device_view::create(lists_column_view(input).child(), stream);
return cudf::detail::valid_if(
iter,
iter + num_rows,
[d_row_offsets, lists_dv = *lists_dv_ptr, iter] __device__(auto const idx) {
return thrust::any_of(
thrust::seq,
iter + d_row_offsets[idx],
iter + d_row_offsets[idx + 1],
[&] __device__(auto const list_idx) { return lists_dv.is_valid(list_idx); });
},
stream,
mr);
}();

return make_lists_column(num_rows,
Expand Down