Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
c22b11c
Test passed
ttnghia Jun 4, 2022
5a6602c
Cleanup
ttnghia Jun 4, 2022
79fa051
Add bench
ttnghia Jun 4, 2022
a7e3463
Add comments
ttnghia Jun 4, 2022
3b7124e
Add unique bench
ttnghia Jun 4, 2022
4f933bf
Rewrite benchs
ttnghia Jun 4, 2022
bf2a717
Add parameter to the API
ttnghia Jun 7, 2022
11f9dd1
Fix compile errors
ttnghia Jun 7, 2022
b8832f7
Switch to use the old atomic ops
ttnghia Jun 7, 2022
f12a509
Add simple tests
ttnghia Jun 7, 2022
edcb612
Revert "Add simple tests"
ttnghia Jun 7, 2022
5b40152
Misc
ttnghia Jun 7, 2022
f2dc1eb
Change doxygen
ttnghia Jun 7, 2022
8a800e9
Cleanup
ttnghia Jun 7, 2022
c0144b3
Revert "Change doxygen"
ttnghia Jun 8, 2022
7d89f4c
Implement `distinct` by `distinct_map`
ttnghia Jun 8, 2022
ae891b3
Rewrite doxygen
ttnghia Jun 8, 2022
1786dbb
Add detail declaration of `distinct_map`
ttnghia Jun 8, 2022
6dfb4f4
Fix bug
ttnghia Jun 8, 2022
3352967
Alias `KEEP_ANY` to `KEEP_FIRST`
ttnghia Jun 8, 2022
52e29b1
Cleanup headers
ttnghia Jun 8, 2022
819a669
Rewrite comments and reorganize code
ttnghia Jun 8, 2022
2e5d41a
Rewrite comments
ttnghia Jun 8, 2022
8393809
Reverse tests
ttnghia Jun 8, 2022
5cdefa3
Fix old tests
ttnghia Jun 8, 2022
3626efb
Add a new overload for `cudf::distinct`
ttnghia Jun 8, 2022
bcc4abe
Reverse back breaking changes
ttnghia Jun 8, 2022
edbcc78
Fix compile error
ttnghia Jun 8, 2022
2f1ce5a
Reverse benchmark
ttnghia Jun 8, 2022
882a67a
Complete `StringKeyColumn` tests
ttnghia Jun 8, 2022
cdae2ac
Fix tests
ttnghia Jun 8, 2022
5b21d88
Fix tests
ttnghia Jun 8, 2022
3f18057
Rename function
ttnghia Jun 9, 2022
21456e7
Add `NonNullTable` tests
ttnghia Jun 9, 2022
8a17581
Add `SlicedNonNullTable` tests
ttnghia Jun 9, 2022
e05ad48
Add `InputWithNulls` tests
ttnghia Jun 9, 2022
03fb093
Change variable
ttnghia Jun 9, 2022
3c12942
Refactor
ttnghia Jun 9, 2022
6ab9673
Add `BasicList` tests
ttnghia Jun 9, 2022
37dfdcb
Add `NullableLists` tests
ttnghia Jun 9, 2022
b78cf5b
Add `ListsOfStructs` tests
ttnghia Jun 9, 2022
8de0948
Add `SlicedStructsOfLists` tests
ttnghia Jun 9, 2022
9e8c4a5
Misc
ttnghia Jun 9, 2022
7fa65ee
Add `ListsOfEmptyStructs` tests
ttnghia Jun 9, 2022
ff6e03e
Modify `EmptyDeepList` tests
ttnghia Jun 9, 2022
374545a
Add `StructsOfLists` tests
ttnghia Jun 9, 2022
9bf540a
Use `distinct` in Cython
ttnghia Jun 9, 2022
e1c3cd5
Merge branch 'branch-22.08' into refactor_stream_compaction
ttnghia Jun 9, 2022
70d3164
Fix Python style
ttnghia Jun 9, 2022
bba15c2
Revert "Fix Python style"
ttnghia Jun 9, 2022
d895f48
Revert "Use `distinct` in Cython"
ttnghia Jun 9, 2022
56e791c
Fix compiling errors due to merging
ttnghia Jun 10, 2022
6ffc9b0
Fix doxygen
ttnghia Jun 10, 2022
dd8c845
Rewrite comment and rename variable
ttnghia Jun 10, 2022
d9c0ab9
Address review comments
ttnghia Jun 15, 2022
7770265
Remove one overload
ttnghia Jun 15, 2022
96a36c4
Fix benchmark
ttnghia Jun 16, 2022
0210228
Rename struct, and use CTAD
ttnghia Jun 16, 2022
65190cc
Add comment
ttnghia Jun 16, 2022
a4db720
Rename variable
ttnghia Jun 16, 2022
6c90c53
Add a parameter
ttnghia Jun 16, 2022
4cc2f2e
Fix compiling errors
ttnghia Jun 16, 2022
55895e7
WIP
ttnghia Jun 16, 2022
df05dc8
Misc
ttnghia Jun 16, 2022
ec48856
Merge branch 'refactor_stream_compaction' into distinct_with_nans_equ…
ttnghia Jun 16, 2022
5f7d778
WIP
ttnghia Jun 16, 2022
154645a
Rewrite doxygen
ttnghia Jun 16, 2022
8f04d50
Remove `keys` parameter from `get_distinct_indices`
ttnghia Jun 16, 2022
d806278
Rewrite doxygen
ttnghia Jun 16, 2022
3734344
Use another version of `gather`
ttnghia Jun 16, 2022
f731d35
Fix wrong doxygen
ttnghia Jun 16, 2022
e44c85d
Fix wrong doxygen again
ttnghia Jun 16, 2022
a74f71e
Misc
ttnghia Jun 16, 2022
f9de181
Update doxygen
ttnghia Jun 16, 2022
a339d83
Merge branch 'refactor_stream_compaction' into distinct_with_nans_equ…
ttnghia Jun 16, 2022
68652f4
Implementation is complete
ttnghia Jun 16, 2022
6cec1eb
Define hash_map and add todo
ttnghia Jun 16, 2022
661400a
Rename variable
ttnghia Jun 17, 2022
700e465
Fix doxygen
ttnghia Jun 17, 2022
1c783e8
Rename tests
ttnghia Jun 17, 2022
64e03f6
Merge branch 'refactor_stream_compaction' into distinct_with_nans_equ…
ttnghia Jun 17, 2022
13ad653
Add `NoNullsTableWithNans` test
ttnghia Jun 17, 2022
7811611
Add `InputWithNullsAndNaNs` tests
ttnghia Jun 17, 2022
47c5eec
Fix a bug when comparing nulls as unequal
ttnghia Jun 18, 2022
4db34db
Add `InputWithNullsUnequal` tests
ttnghia Jun 19, 2022
fab367b
Add `ListsWithNullsUnequal` tests
ttnghia Jun 19, 2022
9ec27af
Rewrite doxygen
ttnghia Jun 19, 2022
1359ee0
Rewrite doxygen for `duplicate_keep_option` and add back performance …
ttnghia Jun 19, 2022
aa0a4ed
Remove redundant docsc
ttnghia Jun 19, 2022
01e03b6
Rename functor
ttnghia Jun 20, 2022
cdc3000
Modify comments
ttnghia Jun 20, 2022
45dec2a
Merge branch 'branch-22.08' into refactor_stream_compaction
ttnghia Jun 20, 2022
16ba20c
Add header
ttnghia Jun 20, 2022
37a23e4
Merge branch 'refactor_stream_compaction' into distinct_with_nans_equ…
ttnghia Jun 20, 2022
38603fc
Merge remote-tracking branch 'nghia/fix_compile_errors' into distinct…
ttnghia Jun 20, 2022
e32daf4
Add `InputWithNaNs*` tests
ttnghia Jun 20, 2022
cba4759
Merge branch 'branch-22.08' into refactor_stream_compaction
ttnghia Jun 20, 2022
7247101
Attempt to split files, not yet cleanup
ttnghia Jun 20, 2022
120377b
Cleanup
ttnghia Jun 20, 2022
68133d4
Change functor name
ttnghia Jun 20, 2022
aefdadf
Add doxygen
ttnghia Jun 20, 2022
faf6778
Reorganize code
ttnghia Jun 20, 2022
e839323
Fix headers
ttnghia Jun 20, 2022
f5646b3
Fix header
ttnghia Jun 20, 2022
538ff08
Fix `mr` usage, and rewrite some comments
ttnghia Jun 21, 2022
a755bea
Pass `std::shared_ptr` by value
ttnghia Jun 21, 2022
f0ee266
Fix doxygen and change function name
ttnghia Jun 22, 2022
0b35671
Update doxygen
ttnghia Jun 22, 2022
db886ea
Merge branch 'refactor_stream_compaction' into distinct_with_nans_equ…
ttnghia Jun 22, 2022
1ac6501
Merge branch 'branch-22.08' into refactor_stream_compaction
ttnghia Jun 22, 2022
d0af0e6
Merge branch 'refactor_stream_compaction' into distinct_with_nans_equ…
ttnghia Jun 22, 2022
be3b2fe
Merge branch 'branch-22.08' into distinct_with_nans_equality
ttnghia Jun 22, 2022
c121268
Remove redundant declaration
ttnghia Jun 22, 2022
2410c08
Change default behavior
ttnghia Jun 22, 2022
3227af9
Fix doxygen/comments and move type alias
ttnghia Jun 22, 2022
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
9 changes: 7 additions & 2 deletions cpp/benchmarks/stream_compaction/distinct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void nvbench_distinct(nvbench::state& state, nvbench::type_list<Type>)
{0},
cudf::duplicate_keep_option::KEEP_ANY,
cudf::null_equality::EQUAL,
cudf::nan_equality::ALL_EQUAL,
stream_view);
});
}
Expand Down Expand Up @@ -90,8 +91,12 @@ void nvbench_distinct_list(nvbench::state& state, nvbench::type_list<Type>)

state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
rmm::cuda_stream_view stream_view{launch.get_stream()};
auto result = cudf::detail::distinct(
*table, {0}, cudf::duplicate_keep_option::KEEP_ANY, cudf::null_equality::EQUAL, stream_view);
auto result = cudf::detail::distinct(*table,
{0},
cudf::duplicate_keep_option::KEEP_ANY,
cudf::null_equality::EQUAL,
cudf::nan_equality::ALL_EQUAL,
stream_view);
});
}

Expand Down
11 changes: 7 additions & 4 deletions cpp/include/cudf/detail/stream_compaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ std::unique_ptr<table> distinct(
std::vector<size_type> const& keys,
duplicate_keep_option keep = duplicate_keep_option::KEEP_ANY,
null_equality nulls_equal = null_equality::EQUAL,
nan_equality nans_equal = nan_equality::ALL_EQUAL,
rmm::cuda_stream_view stream = cudf::default_stream_value,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

Expand All @@ -95,17 +96,19 @@ std::unique_ptr<table> distinct(
* generated. If there are duplicate rows, which index is kept depends on the `keep` parameter.
*
* @param input The input table
* @param keep Get index of the first, last, any, or none row among the found duplicates rows
* @param keep Get index of any, first, last, or none of the found duplicates
* @param nulls_equal Flag to specify whether null elements should be considered as equal
* @param nans_equal Flag to specify whether NaN elements should be considered as equal
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate the returned vector
* @return A device_uvector containing the result indices
*/
rmm::device_uvector<size_type> get_distinct_indices(
table_view const& input,
duplicate_keep_option keep,
null_equality nulls_equal,
rmm::cuda_stream_view stream,
duplicate_keep_option keep = duplicate_keep_option::KEEP_ANY,
null_equality nulls_equal = null_equality::EQUAL,
nan_equality nans_equal = nan_equality::ALL_EQUAL,
rmm::cuda_stream_view stream = cudf::default_stream_value,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
Expand Down
5 changes: 3 additions & 2 deletions cpp/include/cudf/stream_compaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ std::unique_ptr<table> unique(
* @param[in] input input table_view to copy only distinct rows
* @param[in] keys vector of indices representing key columns from `input`
* @param[in] keep keep any, first, last, or none of the found duplicates
* @param[in] nulls_equal flag to denote nulls are equal if null_equality::EQUAL, nulls are not
* equal if null_equality::UNEQUAL
* @param[in] nulls_equal flag to control if nulls are compared equal or not
* @param[in] nans_equal flag to control if floating-point NaN values are compared equal or not
* @param[in] mr Device memory resource used to allocate the returned table's device
* memory
*
Expand All @@ -275,6 +275,7 @@ std::unique_ptr<table> distinct(
std::vector<size_type> const& keys,
duplicate_keep_option keep = duplicate_keep_option::KEEP_ANY,
null_equality nulls_equal = null_equality::EQUAL,
nan_equality nans_equal = nan_equality::ALL_EQUAL,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
Expand Down
1 change: 1 addition & 0 deletions cpp/src/dictionary/add_keys.cu
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ std::unique_ptr<column> add_keys(
std::vector<size_type>{0}, // only one key column
duplicate_keep_option::KEEP_ANY,
null_equality::EQUAL,
nan_equality::ALL_EQUAL,
stream,
mr);
std::vector<order> column_order{order::ASCENDING};
Expand Down
1 change: 1 addition & 0 deletions cpp/src/dictionary/detail/concatenate.cu
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ std::unique_ptr<column> concatenate(host_span<column_view const> columns,
std::vector<size_type>{0},
duplicate_keep_option::KEEP_ANY,
null_equality::EQUAL,
nan_equality::ALL_EQUAL,
stream,
mr);
auto sorted_keys = cudf::detail::sort(table_keys->view(),
Expand Down
1 change: 1 addition & 0 deletions cpp/src/dictionary/set_keys.cu
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ std::unique_ptr<column> set_keys(
std::vector<size_type>{0},
duplicate_keep_option::KEEP_ANY,
null_equality::EQUAL,
nan_equality::ALL_EQUAL,
stream,
mr);
auto sorted_keys = cudf::detail::sort(distinct_keys->view(),
Expand Down
39 changes: 31 additions & 8 deletions cpp/src/stream_compaction/distinct.cu
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace detail {
rmm::device_uvector<size_type> get_distinct_indices(table_view const& input,
duplicate_keep_option keep,
null_equality nulls_equal,
nan_equality nans_equal,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
Expand All @@ -59,12 +60,24 @@ rmm::device_uvector<size_type> get_distinct_indices(table_view const& input,
auto const row_hasher = cudf::experimental::row::hash::row_hasher(preprocessed_input);
auto const key_hasher = experimental::compaction_hash(row_hasher.device_hasher(has_nulls));

auto const row_comp = cudf::experimental::row::equality::self_comparator(preprocessed_input);
auto const key_equal = row_comp.equal_to(has_nulls, nulls_equal);
auto const row_comp = cudf::experimental::row::equality::self_comparator(preprocessed_input);

auto const pair_iter = cudf::detail::make_counting_transform_iterator(
size_type{0}, [] __device__(size_type const i) { return cuco::make_pair(i, i); });
map.insert(pair_iter, pair_iter + input.num_rows(), key_hasher, key_equal, stream.value());

auto const insert_keys = [&](auto const value_comp) {
auto const key_equal = row_comp.equal_to(has_nulls, nulls_equal, value_comp);
map.insert(pair_iter, pair_iter + input.num_rows(), key_hasher, key_equal, stream.value());
};

if (nans_equal == nan_equality::ALL_EQUAL) {
using nan_equal_comparator =
cudf::experimental::row::equality::nan_equal_physical_equality_comparator;
insert_keys(nan_equal_comparator{});
} else {
using nan_unequal_comparator = cudf::experimental::row::equality::physical_equality_comparator;
insert_keys(nan_unequal_comparator{});
}

auto output_indices = rmm::device_uvector<size_type>(map.get_size(), stream, mr);

Expand All @@ -74,9 +87,15 @@ rmm::device_uvector<size_type> get_distinct_indices(table_view const& input,
return output_indices;
}

// For other keep options, perform a (sparse) reduce-by-row on the rows compared equal.
auto const reduction_results = hash_reduce_by_row(
map, std::move(preprocessed_input), input.num_rows(), has_nulls, keep, nulls_equal, stream);
// For other keep options, reduce by row on rows that compare equal.
auto const reduction_results = hash_reduce_by_row(map,
std::move(preprocessed_input),
input.num_rows(),
has_nulls,
keep,
nulls_equal,
nans_equal,
stream);

// Extract the desired output indices from reduction results.
auto const map_end = [&] {
Expand Down Expand Up @@ -111,14 +130,16 @@ std::unique_ptr<table> distinct(table_view const& input,
std::vector<size_type> const& keys,
duplicate_keep_option keep,
null_equality nulls_equal,
nan_equality nans_equal,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
if (input.num_rows() == 0 or input.num_columns() == 0 or keys.empty()) {
return empty_like(input);
}

auto const gather_map = get_distinct_indices(input.select(keys), keep, nulls_equal, stream);
auto const gather_map =
get_distinct_indices(input.select(keys), keep, nulls_equal, nans_equal, stream);
return detail::gather(input,
gather_map,
out_of_bounds_policy::DONT_CHECK,
Expand All @@ -133,10 +154,12 @@ std::unique_ptr<table> distinct(table_view const& input,
std::vector<size_type> const& keys,
duplicate_keep_option keep,
null_equality nulls_equal,
nan_equality nans_equal,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::distinct(input, keys, keep, nulls_equal, cudf::default_stream_value, mr);
return detail::distinct(
input, keys, keep, nulls_equal, nans_equal, cudf::default_stream_value, mr);
}

} // namespace cudf
30 changes: 21 additions & 9 deletions cpp/src/stream_compaction/distinct_reduce.cu
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ rmm::device_uvector<size_type> hash_reduce_by_row(
cudf::nullate::DYNAMIC has_nulls,
duplicate_keep_option keep,
null_equality nulls_equal,
nan_equality nans_equal,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
Expand All @@ -111,15 +112,26 @@ rmm::device_uvector<size_type> hash_reduce_by_row(
auto const row_hasher = cudf::experimental::row::hash::row_hasher(preprocessed_input);
auto const key_hasher = experimental::compaction_hash(row_hasher.device_hasher(has_nulls));

auto const row_comp = cudf::experimental::row::equality::self_comparator(preprocessed_input);
auto const key_equal = row_comp.equal_to(has_nulls, nulls_equal);

thrust::for_each(
rmm::exec_policy(stream),
thrust::make_counting_iterator(0),
thrust::make_counting_iterator(num_rows),
reduce_by_row_fn{
map.get_device_view(), key_hasher, key_equal, keep, reduction_results.begin()});
auto const row_comp = cudf::experimental::row::equality::self_comparator(preprocessed_input);

auto const reduce_by_row = [&](auto const value_comp) {
Copy link
Contributor

@bdice bdice Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along the lines of what @PointKernel was suggesting -- one alternative I considered was making this lambda actually allocate and return the output vector, rather than binding in reduction_results as an output iterator and returning void. That felt like an implicit "output parameter" in the lambda. If the lambda were a real function, we'd avoid the output parameter and return the rmm::device_uvector directly from the function. I don't have strong feelings on this, so feel free to keep it as-is.

edit: Initially wrote "IIFE" where I meant lambda. Fixed.

Copy link
Contributor

@bdice bdice Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did that, however, almost the entire body of hash_reduce_by_row becomes a lambda and the part at the end is just a nans_equal dispatcher. 😛

auto const key_equal = row_comp.equal_to(has_nulls, nulls_equal, value_comp);
thrust::for_each(
rmm::exec_policy(stream),
thrust::make_counting_iterator(0),
thrust::make_counting_iterator(num_rows),
reduce_by_row_fn{
map.get_device_view(), key_hasher, key_equal, keep, reduction_results.begin()});
};

if (nans_equal == nan_equality::ALL_EQUAL) {
using nan_equal_comparator =
cudf::experimental::row::equality::nan_equal_physical_equality_comparator;
reduce_by_row(nan_equal_comparator{});
} else {
using nan_unequal_comparator = cudf::experimental::row::equality::physical_equality_comparator;
reduce_by_row(nan_unequal_comparator{});
}

return reduction_results;
}
Expand Down
1 change: 1 addition & 0 deletions cpp/src/stream_compaction/distinct_reduce.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ rmm::device_uvector<size_type> hash_reduce_by_row(
cudf::nullate::DYNAMIC has_nulls,
duplicate_keep_option keep,
null_equality nulls_equal,
nan_equality nans_equal,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

Expand Down
9 changes: 7 additions & 2 deletions cpp/src/transform/encode.cu
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ std::pair<std::unique_ptr<table>, std::unique_ptr<column>> encode(
std::vector<size_type> drop_keys(num_cols);
std::iota(drop_keys.begin(), drop_keys.end(), 0);

auto distinct_keys = cudf::detail::distinct(
input_table, drop_keys, duplicate_keep_option::KEEP_ANY, null_equality::EQUAL, stream, mr);
auto distinct_keys = cudf::detail::distinct(input_table,
drop_keys,
duplicate_keep_option::KEEP_ANY,
null_equality::EQUAL,
nan_equality::ALL_EQUAL,
stream,
mr);

std::vector<order> column_order(num_cols, order::ASCENDING);
std::vector<null_order> null_precedence(num_cols, null_order::AFTER);
Expand Down
Loading