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

Optimize left_semi_join by materializing the gather mask #10511

Merged
merged 3 commits into from
May 5, 2022
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
29 changes: 19 additions & 10 deletions cpp/src/join/semi_join.cu
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,28 @@ std::unique_ptr<rmm::device_uvector<cudf::size_type>> left_semi_anti_join(
auto gather_map =
std::make_unique<rmm::device_uvector<cudf::size_type>>(left_num_rows, stream, mr);

// gather_map_end will be the end of valid data in gather_map
auto gather_map_end = thrust::copy_if(
rmm::device_uvector<bool> flagged(left_num_rows, stream, mr);
auto flagged_d = flagged.data();

auto counting_iter = thrust::counting_iterator<size_type>(0);
jrhemstad marked this conversation as resolved.
Show resolved Hide resolved
thrust::for_each(
rmm::exec_policy(stream),
thrust::make_counting_iterator(0),
thrust::make_counting_iterator(left_num_rows),
gather_map->begin(),
[hash_table_view, join_type_boolean, hash_probe, equality_probe] __device__(
size_type const idx) {
// Look up this row. The hash function used here needs to map a (left) row index to the hash
// of the row, so it's a row hash. The equality check needs to verify
return hash_table_view.contains(idx, hash_probe, equality_probe) == join_type_boolean;
counting_iter,
counting_iter + left_num_rows,
[flagged_d, hash_table_view, join_type_boolean, hash_probe, equality_probe] __device__(
const size_type idx) {
flagged_d[idx] =
hash_table_view.contains(idx, hash_probe, equality_probe) == join_type_boolean;
});

// gather_map_end will be the end of valid data in gather_map
auto gather_map_end =
thrust::copy_if(rmm::exec_policy(stream),
counting_iter,
counting_iter + left_num_rows,
gather_map->begin(),
[flagged_d] __device__(size_type const idx) { return flagged_d[idx]; });

auto join_size = thrust::distance(gather_map->begin(), gather_map_end);
gather_map->resize(join_size, stream);
return gather_map;
Expand Down