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

Update mixed_join to use experimental row hasher and comparator #13028

Merged
merged 49 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4a8085a
building equality::self_comparator
divyegala Feb 2, 2023
f71d161
two table comp
divyegala Feb 2, 2023
3ca298c
copyright years
divyegala Feb 2, 2023
7c167a7
centralizing repeated logic
divyegala Feb 2, 2023
0ceb79e
address review to create functors
divyegala Feb 3, 2023
37e7326
updating has_nested_columns docs
divyegala Feb 3, 2023
b44f603
Merge remote-tracking branch 'upstream/branch-23.04' into equality-co…
divyegala Feb 3, 2023
c2ff1fc
address review for underscore prefixes in structs
divyegala Feb 7, 2023
c2ca8ee
Merge remote-tracking branch 'upstream/branch-23.04' into equality-co…
divyegala Feb 7, 2023
ffdf10c
Merge remote-tracking branch 'upstream/branch-23.04' into equality-co…
divyegala Feb 8, 2023
53e918f
add rank
divyegala Feb 8, 2023
65e2bce
fix compile times for rank
divyegala Feb 8, 2023
c6bc7f5
Merge remote-tracking branch 'upstream/branch-23.04' into equality-co…
divyegala Feb 8, 2023
1344e33
Apply suggestions from code review
divyegala Feb 11, 2023
4123379
address review
divyegala Feb 11, 2023
26f38b3
Merge remote-tracking branch 'upstream/branch-23.04' into equality-co…
divyegala Feb 11, 2023
9d0f7a6
address review, mark members of functors as private
divyegala Feb 11, 2023
fe41be8
removing partitioning
divyegala Feb 11, 2023
02dd5c5
simplify lists/contains since it already has a nested-type dispatch m…
divyegala Feb 12, 2023
5db4d03
Merge branch 'branch-23.04' into equality-comp-fast-path
divyegala Feb 13, 2023
9aa23a5
Merge branch 'branch-23.04' into equality-comp-fast-path
divyegala Feb 15, 2023
73adabc
trying to figure if build and probe switched
divyegala Feb 16, 2023
02edad7
figured out index inversion
divyegala Feb 16, 2023
fa8f639
trying legacy again
divyegala Feb 19, 2023
38464ef
Revert "trying legacy again"
divyegala Feb 20, 2023
0113589
fix slower times in small tables
divyegala Feb 20, 2023
36fc5e9
copyright years
divyegala Feb 20, 2023
5d75db8
Merge remote-tracking branch 'upstream/branch-23.04' into join-row-op…
divyegala Feb 20, 2023
9a787c6
add lists tests
divyegala Feb 21, 2023
a1cb220
explicitly instantiate shared function template
divyegala Feb 21, 2023
d3d4bb6
copyright year
divyegala Feb 21, 2023
cf92f34
address review
divyegala Mar 21, 2023
a6bbf8b
merge upstream
divyegala Mar 21, 2023
47fe8d2
address review
divyegala Mar 23, 2023
45fd37a
merge upstream
divyegala Mar 23, 2023
10b0406
Apply suggestions from code review
divyegala Mar 23, 2023
9c4bdfa
address review
divyegala Mar 23, 2023
e7fb4cd
address review
divyegala Mar 28, 2023
0fe1354
Merge remote-tracking branch 'upstream/branch-23.04' into join-row-op…
divyegala Mar 28, 2023
4f13a6a
semi/anti passing, rest failing
divyegala Mar 28, 2023
ff36a3d
all tests passing
divyegala Mar 28, 2023
d4f0f8f
merge upstream
divyegala Apr 6, 2023
2477695
Merge branch 'branch-23.06' into mixed-join-row-operators
divyegala Apr 7, 2023
09b5262
address review
divyegala Apr 18, 2023
2bdbc73
merge upstream
divyegala Apr 18, 2023
00dc36a
Merge branch 'mixed-join-row-operators' of github.com:divyegala/cudf …
divyegala Apr 18, 2023
69c3905
style check
divyegala Apr 18, 2023
b1a95e0
Merge branch 'branch-23.06' into mixed-join-row-operators
divyegala Apr 20, 2023
f3c5af8
Merge branch 'branch-23.06' into mixed-join-row-operators
divyegala Apr 21, 2023
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
34 changes: 26 additions & 8 deletions cpp/src/join/mixed_join.cu
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ mixed_join(
// If evaluating the expression may produce null outputs we create a nullable
// output column and follow the null-supporting expression evaluation code
// path.
auto const has_nulls =
auto const has_nulls = cudf::nullate::DYNAMIC{
divyegala marked this conversation as resolved.
Show resolved Hide resolved
cudf::has_nulls(left_equality) || cudf::has_nulls(right_equality) ||
binary_predicate.may_evaluate_null(left_conditional, right_conditional, stream);
binary_predicate.may_evaluate_null(left_conditional, right_conditional, stream)};

auto const parser = ast::detail::expression_parser{
binary_predicate, left_conditional, right_conditional, has_nulls, stream, mr};
Expand All @@ -125,8 +125,6 @@ mixed_join(
auto& build = swap_tables ? left_equality : right_equality;
auto probe_view = table_device_view::create(probe, stream);
auto build_view = table_device_view::create(build, stream);
row_equality equality_probe{
cudf::nullate::DYNAMIC{has_nulls}, *probe_view, *build_view, compare_nulls};

// Don't use multimap_type because we want a CG size of 1.
mixed_multimap_type hash_table{
Expand Down Expand Up @@ -168,6 +166,14 @@ mixed_join(
std::optional<rmm::device_uvector<size_type>> matches_per_row{};
device_span<size_type const> matches_per_row_span{};

auto const preprocessed_probe =
experimental::row::equality::preprocessed_table::create(probe, stream);
auto const row_hash = cudf::experimental::row::hash::row_hasher{preprocessed_probe};
auto const hash_probe = row_hash.device_hasher(has_nulls);
auto const row_comparator =
cudf::experimental::row::equality::two_table_comparator{preprocessed_probe, preprocessed_build};
auto const equality_probe = row_comparator.equal_to<false>(has_nulls, compare_nulls);
divyegala marked this conversation as resolved.
Show resolved Hide resolved

if (output_size_data.has_value()) {
join_size = output_size_data->first;
matches_per_row_span = output_size_data->second;
Expand All @@ -190,6 +196,7 @@ mixed_join(
*right_conditional_view,
*probe_view,
*build_view,
hash_probe,
equality_probe,
kernel_join_type,
hash_table_view,
Expand All @@ -204,6 +211,7 @@ mixed_join(
*right_conditional_view,
*probe_view,
*build_view,
hash_probe,
equality_probe,
kernel_join_type,
hash_table_view,
Expand Down Expand Up @@ -247,6 +255,7 @@ mixed_join(
*right_conditional_view,
*probe_view,
*build_view,
hash_probe,
equality_probe,
kernel_join_type,
hash_table_view,
Expand All @@ -262,6 +271,7 @@ mixed_join(
*right_conditional_view,
*probe_view,
*build_view,
hash_probe,
equality_probe,
kernel_join_type,
hash_table_view,
Expand Down Expand Up @@ -364,9 +374,9 @@ compute_mixed_join_output_size(table_view const& left_equality,
// If evaluating the expression may produce null outputs we create a nullable
// output column and follow the null-supporting expression evaluation code
// path.
auto const has_nulls =
auto const has_nulls = cudf::nullate::DYNAMIC{
divyegala marked this conversation as resolved.
Show resolved Hide resolved
cudf::has_nulls(left_equality) || cudf::has_nulls(right_equality) ||
binary_predicate.may_evaluate_null(left_conditional, right_conditional, stream);
binary_predicate.may_evaluate_null(left_conditional, right_conditional, stream)};

auto const parser = ast::detail::expression_parser{
binary_predicate, left_conditional, right_conditional, has_nulls, stream, mr};
Expand All @@ -380,8 +390,6 @@ compute_mixed_join_output_size(table_view const& left_equality,
auto& build = swap_tables ? left_equality : right_equality;
auto probe_view = table_device_view::create(probe, stream);
auto build_view = table_device_view::create(build, stream);
row_equality equality_probe{
cudf::nullate::DYNAMIC{has_nulls}, *probe_view, *build_view, compare_nulls};

// Don't use multimap_type because we want a CG size of 1.
mixed_multimap_type hash_table{
Expand Down Expand Up @@ -417,6 +425,14 @@ compute_mixed_join_output_size(table_view const& left_equality,
// Allocate storage for the counter used to get the size of the join output
rmm::device_scalar<std::size_t> size(0, stream, mr);

auto const preprocessed_probe =
experimental::row::equality::preprocessed_table::create(probe, stream);
auto const row_hash = cudf::experimental::row::hash::row_hasher{preprocessed_probe};
auto const hash_probe = row_hash.device_hasher(has_nulls);
auto const row_comparator =
cudf::experimental::row::equality::two_table_comparator{preprocessed_probe, preprocessed_build};
auto const equality_probe = row_comparator.equal_to<false>(has_nulls, compare_nulls);

// Determine number of output rows without actually building the output to simply
// find what the size of the output will be.
if (has_nulls) {
Expand All @@ -426,6 +442,7 @@ compute_mixed_join_output_size(table_view const& left_equality,
*right_conditional_view,
*probe_view,
*build_view,
hash_probe,
equality_probe,
join_type,
hash_table_view,
Expand All @@ -440,6 +457,7 @@ compute_mixed_join_output_size(table_view const& left_equality,
*right_conditional_view,
*probe_view,
*build_view,
hash_probe,
equality_probe,
join_type,
hash_table_view,
Expand Down
25 changes: 20 additions & 5 deletions cpp/src/join/mixed_join_common_utils.cuh
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 @@ -19,6 +19,7 @@

#include <cudf/ast/detail/expression_evaluator.cuh>
#include <cudf/detail/utilities/cuda.cuh>
#include <cudf/table/experimental/row_operators.cuh>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/device_uvector.hpp>
Expand All @@ -28,6 +29,14 @@
namespace cudf {
namespace detail {

using row_hash_experimental =
cudf::experimental::row::hash::device_row_hasher<default_hash, cudf::nullate::DYNAMIC>;

// // This alias is used by mixed_joins, which support only non-nested types
using row_equality_experimental =
divyegala marked this conversation as resolved.
Show resolved Hide resolved
cudf::experimental::row::equality::strong_index_comparator_adapter<
cudf::experimental::row::equality::device_row_comparator<false, cudf::nullate::DYNAMIC>>;

/**
* @brief Equality comparator for use with cuco map methods that require expression evaluation.
*
Expand All @@ -41,7 +50,7 @@ struct expression_equality {
cudf::ast::detail::expression_evaluator<has_nulls> const& evaluator,
cudf::ast::detail::IntermediateDataType<has_nulls>* thread_intermediate_storage,
bool const swap_tables,
row_equality const& equality_probe)
row_equality_experimental const& equality_probe)
: evaluator{evaluator},
thread_intermediate_storage{thread_intermediate_storage},
swap_tables{swap_tables},
Expand All @@ -52,7 +61,7 @@ struct expression_equality {
cudf::ast::detail::IntermediateDataType<has_nulls>* thread_intermediate_storage;
cudf::ast::detail::expression_evaluator<has_nulls> const& evaluator;
bool const swap_tables;
row_equality const& equality_probe;
row_equality_experimental const& equality_probe;
};

/**
Expand All @@ -79,12 +88,15 @@ struct single_expression_equality : expression_equality<has_nulls> {
__device__ __forceinline__ bool operator()(hash_value_type const build_row_index,
hash_value_type const probe_row_index) const noexcept
{
using cudf::experimental::row::lhs_index_type;
using cudf::experimental::row::rhs_index_type;

auto output_dest = cudf::ast::detail::value_expression_result<bool, has_nulls>();
// Two levels of checks:
// 1. The contents of the columns involved in the equality condition are equal.
// 2. The predicate evaluated on the relevant columns (already encoded in the evaluator)
// evaluates to true.
if (this->equality_probe(probe_row_index, build_row_index)) {
if (this->equality_probe(lhs_index_type{probe_row_index}, rhs_index_type{build_row_index})) {
auto const lrow_idx = this->swap_tables ? build_row_index : probe_row_index;
auto const rrow_idx = this->swap_tables ? probe_row_index : build_row_index;
this->evaluator.evaluate(output_dest,
Expand Down Expand Up @@ -127,14 +139,17 @@ struct pair_expression_equality : public expression_equality<has_nulls> {
__device__ __forceinline__ bool operator()(pair_type const& build_row,
pair_type const& probe_row) const noexcept
{
using cudf::experimental::row::lhs_index_type;
using cudf::experimental::row::rhs_index_type;

auto output_dest = cudf::ast::detail::value_expression_result<bool, has_nulls>();
// Three levels of checks:
// 1. Row hashes of the columns involved in the equality condition are equal.
// 2. The contents of the columns involved in the equality condition are equal.
// 3. The predicate evaluated on the relevant columns (already encoded in the evaluator)
// evaluates to true.
if ((probe_row.first == build_row.first) &&
this->equality_probe(probe_row.second, build_row.second)) {
this->equality_probe(lhs_index_type{probe_row.second}, rhs_index_type{build_row.second})) {
auto const lrow_idx = this->swap_tables ? build_row.second : probe_row.second;
auto const rrow_idx = this->swap_tables ? probe_row.second : build_row.second;
this->evaluator.evaluate(
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/join/mixed_join_kernel.cu
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 @@ -24,7 +24,8 @@ template __global__ void mixed_join<DEFAULT_JOIN_BLOCK_SIZE, false>(
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::mixed_multimap_type::device_view hash_table_view,
size_type* join_output_l,
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/join/mixed_join_kernel.cuh
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 Down Expand Up @@ -42,7 +42,8 @@ __launch_bounds__(block_size) __global__
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::mixed_multimap_type::device_view hash_table_view,
size_type* join_output_l,
Expand Down Expand Up @@ -70,7 +71,6 @@ __launch_bounds__(block_size) __global__
auto evaluator = cudf::ast::detail::expression_evaluator<has_nulls>(
left_table, right_table, device_expression_data);

row_hash hash_probe{nullate::DYNAMIC{has_nulls}, probe};
auto const empty_key_sentinel = hash_table_view.get_empty_key_sentinel();
make_pair_function pair_func{hash_probe, empty_key_sentinel};

Expand Down
5 changes: 3 additions & 2 deletions cpp/src/join/mixed_join_kernel_nulls.cu
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 @@ -24,7 +24,8 @@ template __global__ void mixed_join<DEFAULT_JOIN_BLOCK_SIZE, true>(
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::mixed_multimap_type::device_view hash_table_view,
size_type* join_output_l,
Expand Down
10 changes: 7 additions & 3 deletions cpp/src/join/mixed_join_kernels.cuh
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 Down Expand Up @@ -41,6 +41,7 @@ namespace detail {
* @param[in] right_table The right table
* @param[in] probe The table with which to probe the hash table for matches.
* @param[in] build The table with which the hash table was built.
* @param[in] hash_probe The hasher used for the probe table.
* @param[in] equality_probe The equality comparator used when probing the hash table.
* @param[in] join_type The type of join to be performed
* @param[in] hash_table_view The hash table built from `build`.
Expand All @@ -62,7 +63,8 @@ __global__ void compute_mixed_join_output_size(
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::mixed_multimap_type::device_view hash_table_view,
ast::detail::expression_device_view device_expression_data,
Expand All @@ -87,6 +89,7 @@ __global__ void compute_mixed_join_output_size(
* @param[in] right_table The right table
* @param[in] probe The table with which to probe the hash table for matches.
* @param[in] build The table with which the hash table was built.
* @param[in] hash_probe The hasher used for the probe table.
* @param[in] equality_probe The equality comparator used when probing the hash table.
* @param[in] join_type The type of join to be performed
* @param[in] hash_table_view The hash table built from `build`.
Expand All @@ -105,7 +108,8 @@ __global__ void mixed_join(table_device_view left_table,
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::mixed_multimap_type::device_view hash_table_view,
size_type* join_output_l,
Expand Down
13 changes: 7 additions & 6 deletions cpp/src/join/mixed_join_kernels_semi.cu
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 Down Expand Up @@ -37,7 +37,8 @@ __launch_bounds__(block_size) __global__
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::semi_map_type::device_view hash_table_view,
size_type* join_output_l,
Expand All @@ -64,8 +65,6 @@ __launch_bounds__(block_size) __global__
auto evaluator = cudf::ast::detail::expression_evaluator<has_nulls>(
left_table, right_table, device_expression_data);

row_hash hash_probe{nullate::DYNAMIC{has_nulls}, probe};

if (outer_row_index < outer_num_rows) {
// Figure out the number of elements for this key.
auto equality = single_expression_equality<has_nulls>{
Expand All @@ -83,7 +82,8 @@ template __global__ void mixed_join_semi<DEFAULT_JOIN_BLOCK_SIZE, true>(
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::semi_map_type::device_view hash_table_view,
size_type* join_output_l,
Expand All @@ -96,7 +96,8 @@ template __global__ void mixed_join_semi<DEFAULT_JOIN_BLOCK_SIZE, false>(
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::semi_map_type::device_view hash_table_view,
size_type* join_output_l,
Expand Down
10 changes: 7 additions & 3 deletions cpp/src/join/mixed_join_kernels_semi.cuh
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 Down Expand Up @@ -41,6 +41,7 @@ namespace detail {
* @param[in] right_table The right table
* @param[in] probe The table with which to probe the hash table for matches.
* @param[in] build The table with which the hash table was built.
* @param[in] hash_probe The hasher used for the probe table.
* @param[in] equality_probe The equality comparator used when probing the hash table.
* @param[in] join_type The type of join to be performed
* @param[in] hash_table_view The hash table built from `build`.
Expand All @@ -62,7 +63,8 @@ __global__ void compute_mixed_join_output_size_semi(
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::semi_map_type::device_view hash_table_view,
ast::detail::expression_device_view device_expression_data,
Expand All @@ -87,6 +89,7 @@ __global__ void compute_mixed_join_output_size_semi(
* @param[in] right_table The right table
* @param[in] probe The table with which to probe the hash table for matches.
* @param[in] build The table with which the hash table was built.
* @param[in] hash_probe The hasher used for the probe table.
* @param[in] equality_probe The equality comparator used when probing the hash table.
* @param[in] join_type The type of join to be performed
* @param[in] hash_table_view The hash table built from `build`.
Expand All @@ -104,7 +107,8 @@ __global__ void mixed_join_semi(table_device_view left_table,
table_device_view right_table,
table_device_view probe,
table_device_view build,
row_equality const equality_probe,
row_hash_experimental const hash_probe,
row_equality_experimental const equality_probe,
join_kind const join_type,
cudf::detail::semi_map_type::device_view hash_table_view,
size_type* join_output_l,
Expand Down
Loading