-
Notifications
You must be signed in to change notification settings - Fork 927
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
Reapply mixed_semi_join
refactoring and bug fixes
#16859
Merged
rapids-bot
merged 13 commits into
rapidsai:branch-24.12
from
mhaseeb123:make-mixed-semi-join-great-again
Sep 26, 2024
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cca0091
Reapply Refactor mixed_semi_join using cuco::static_set
mhaseeb123 36e1cd7
Fix for mixed_semi_join
mhaseeb123 66b3f88
Perf tuning.
mhaseeb123 32b1f29
Minor improvement
mhaseeb123 37c1e04
Add missing consts
mhaseeb123 6063f75
Perf improvements
mhaseeb123 18c3e20
MInor comments
mhaseeb123 ba4e1e4
Merge branch 'branch-24.10' into make-mixed-semi-join-great-again
mhaseeb123 a2ddf7f
Update cpp/src/join/mixed_join_kernels_semi.cu
mhaseeb123 03e599c
Merge branch 'branch-24.12' into make-mixed-semi-join-great-again
mhaseeb123 4c4821a
Apply suggestions from reviewer comments
mhaseeb123 d618b55
Update cpp/tests/join/mixed_join_tests.cu
mhaseeb123 67ce080
Increase number of rows in tables for better testing.
mhaseeb123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,45 +46,6 @@ | |
namespace cudf { | ||
namespace detail { | ||
|
||
namespace { | ||
/** | ||
* @brief Device functor to create a pair of hash value and index for a given row. | ||
*/ | ||
struct make_pair_function_semi { | ||
__device__ __forceinline__ cudf::detail::pair_type operator()(size_type i) const noexcept | ||
{ | ||
// The value is irrelevant since we only ever use the hash map to check for | ||
// membership of a particular row index. | ||
return cuco::make_pair(static_cast<hash_value_type>(i), 0); | ||
} | ||
}; | ||
|
||
/** | ||
* @brief Equality comparator that composes two row_equality comparators. | ||
*/ | ||
class double_row_equality { | ||
public: | ||
double_row_equality(row_equality equality_comparator, row_equality conditional_comparator) | ||
: _equality_comparator{equality_comparator}, _conditional_comparator{conditional_comparator} | ||
{ | ||
} | ||
|
||
__device__ bool operator()(size_type lhs_row_index, size_type rhs_row_index) const noexcept | ||
{ | ||
using experimental::row::lhs_index_type; | ||
using experimental::row::rhs_index_type; | ||
|
||
return _equality_comparator(lhs_index_type{lhs_row_index}, rhs_index_type{rhs_row_index}) && | ||
_conditional_comparator(lhs_index_type{lhs_row_index}, rhs_index_type{rhs_row_index}); | ||
} | ||
|
||
private: | ||
row_equality _equality_comparator; | ||
row_equality _conditional_comparator; | ||
}; | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<rmm::device_uvector<size_type>> mixed_join_semi( | ||
table_view const& left_equality, | ||
table_view const& right_equality, | ||
|
@@ -96,7 +57,7 @@ std::unique_ptr<rmm::device_uvector<size_type>> mixed_join_semi( | |
rmm::cuda_stream_view stream, | ||
rmm::device_async_resource_ref mr) | ||
{ | ||
CUDF_EXPECTS((join_type != join_kind::INNER_JOIN) && (join_type != join_kind::LEFT_JOIN) && | ||
CUDF_EXPECTS((join_type != join_kind::INNER_JOIN) and (join_type != join_kind::LEFT_JOIN) and | ||
(join_type != join_kind::FULL_JOIN), | ||
"Inner, left, and full joins should use mixed_join."); | ||
|
||
|
@@ -137,7 +98,7 @@ std::unique_ptr<rmm::device_uvector<size_type>> mixed_join_semi( | |
// output column and follow the null-supporting expression evaluation code | ||
// path. | ||
auto const has_nulls = cudf::nullate::DYNAMIC{ | ||
cudf::has_nulls(left_equality) || cudf::has_nulls(right_equality) || | ||
cudf::has_nulls(left_equality) or cudf::has_nulls(right_equality) or | ||
binary_predicate.may_evaluate_null(left_conditional, right_conditional, stream)}; | ||
|
||
auto const parser = ast::detail::expression_parser{ | ||
|
@@ -156,27 +117,20 @@ std::unique_ptr<rmm::device_uvector<size_type>> mixed_join_semi( | |
auto right_conditional_view = table_device_view::create(right_conditional, stream); | ||
|
||
auto const preprocessed_build = | ||
experimental::row::equality::preprocessed_table::create(build, stream); | ||
cudf::experimental::row::equality::preprocessed_table::create(build, stream); | ||
auto const preprocessed_probe = | ||
experimental::row::equality::preprocessed_table::create(probe, stream); | ||
cudf::experimental::row::equality::preprocessed_table::create(probe, stream); | ||
auto const row_comparator = | ||
cudf::experimental::row::equality::two_table_comparator{preprocessed_probe, preprocessed_build}; | ||
cudf::experimental::row::equality::two_table_comparator{preprocessed_build, preprocessed_probe}; | ||
auto const equality_probe = row_comparator.equal_to<false>(has_nulls, compare_nulls); | ||
|
||
semi_map_type hash_table{ | ||
compute_hash_table_size(build.num_rows()), | ||
cuco::empty_key{std::numeric_limits<hash_value_type>::max()}, | ||
cuco::empty_value{cudf::detail::JoinNoneValue}, | ||
cudf::detail::cuco_allocator<char>{rmm::mr::polymorphic_allocator<char>{}, stream}, | ||
stream.value()}; | ||
|
||
// Create hash table containing all keys found in right table | ||
// TODO: To add support for nested columns we will need to flatten in many | ||
// places. However, this probably isn't worth adding any time soon since we | ||
// won't be able to support AST conditions for those types anyway. | ||
auto const build_nulls = cudf::nullate::DYNAMIC{cudf::has_nulls(build)}; | ||
auto const row_hash_build = cudf::experimental::row::hash::row_hasher{preprocessed_build}; | ||
auto const hash_build = row_hash_build.device_hasher(build_nulls); | ||
|
||
// Since we may see multiple rows that are identical in the equality tables | ||
// but differ in the conditional tables, the equality comparator used for | ||
// insertion must account for both sets of tables. An alternative solution | ||
|
@@ -191,39 +145,48 @@ std::unique_ptr<rmm::device_uvector<size_type>> mixed_join_semi( | |
auto const equality_build_equality = | ||
row_comparator_build.equal_to<false>(build_nulls, compare_nulls); | ||
auto const preprocessed_build_condtional = | ||
experimental::row::equality::preprocessed_table::create(right_conditional, stream); | ||
cudf::experimental::row::equality::preprocessed_table::create(right_conditional, stream); | ||
auto const row_comparator_conditional_build = | ||
cudf::experimental::row::equality::two_table_comparator{preprocessed_build_condtional, | ||
preprocessed_build_condtional}; | ||
auto const equality_build_conditional = | ||
row_comparator_conditional_build.equal_to<false>(build_nulls, compare_nulls); | ||
double_row_equality equality_build{equality_build_equality, equality_build_conditional}; | ||
make_pair_function_semi pair_func_build{}; | ||
|
||
auto iter = cudf::detail::make_counting_transform_iterator(0, pair_func_build); | ||
hash_set_type row_set{ | ||
{compute_hash_table_size(build.num_rows())}, | ||
cuco::empty_key{JoinNoneValue}, | ||
{equality_build_equality, equality_build_conditional}, | ||
{row_hash_build.device_hasher(build_nulls)}, | ||
{}, | ||
{}, | ||
cudf::detail::cuco_allocator<char>{rmm::mr::polymorphic_allocator<char>{}, stream}, | ||
{stream.value()}}; | ||
|
||
auto iter = thrust::make_counting_iterator(0); | ||
|
||
// skip rows that are null here. | ||
if ((compare_nulls == null_equality::EQUAL) or (not nullable(build))) { | ||
hash_table.insert(iter, iter + right_num_rows, hash_build, equality_build, stream.value()); | ||
row_set.insert(iter, iter + right_num_rows, stream.value()); | ||
} else { | ||
thrust::counting_iterator<cudf::size_type> stencil(0); | ||
auto const [row_bitmask, _] = | ||
cudf::detail::bitmask_and(build, stream, cudf::get_current_device_resource_ref()); | ||
row_is_valid pred{static_cast<bitmask_type const*>(row_bitmask.data())}; | ||
|
||
// insert valid rows | ||
hash_table.insert_if( | ||
iter, iter + right_num_rows, stencil, pred, hash_build, equality_build, stream.value()); | ||
row_set.insert_if(iter, iter + right_num_rows, stencil, pred, stream.value()); | ||
} | ||
|
||
auto hash_table_view = hash_table.get_device_view(); | ||
|
||
detail::grid_1d const config(outer_num_rows, DEFAULT_JOIN_BLOCK_SIZE); | ||
auto const shmem_size_per_block = parser.shmem_per_thread * config.num_threads_per_block; | ||
detail::grid_1d const config(outer_num_rows * hash_set_type::cg_size, DEFAULT_JOIN_BLOCK_SIZE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug fix (part 2): We need to launch |
||
auto const shmem_size_per_block = | ||
parser.shmem_per_thread * | ||
cuco::detail::int_div_ceil(config.num_threads_per_block, hash_set_type::cg_size); | ||
|
||
auto const row_hash = cudf::experimental::row::hash::row_hasher{preprocessed_probe}; | ||
auto const hash_probe = row_hash.device_hasher(has_nulls); | ||
|
||
hash_set_ref_type const row_set_ref = row_set.ref(cuco::contains).with_hash_function(hash_probe); | ||
|
||
// Vector used to indicate indices from left/probe table which are present in output | ||
auto left_table_keep_mask = rmm::device_uvector<bool>(probe.num_rows(), stream); | ||
|
||
|
@@ -232,9 +195,8 @@ std::unique_ptr<rmm::device_uvector<size_type>> mixed_join_semi( | |
*right_conditional_view, | ||
*probe_view, | ||
*build_view, | ||
hash_probe, | ||
equality_probe, | ||
hash_table_view, | ||
row_set_ref, | ||
cudf::device_span<bool>(left_table_keep_mask), | ||
parser.device_expression_data, | ||
config, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug fix (part 1): This was a simple
if
before so only queryingnelems/cg_size
items instead of allnelems