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

[REVIEW] Define and implement new stream compaction APIs copy_if, drop_nulls, apply_boolean_mask, drop_duplicate and unique_count. #3303

Merged
merged 49 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
86b05ec
changes
rgsl888prabhu Oct 31, 2019
470d7a2
Merge branch 'branch-0.11' of https://github.com/rapidsai/cudf into 2…
rgsl888prabhu Oct 31, 2019
0c6ad10
primary changes
rgsl888prabhu Nov 1, 2019
8331791
files are compiling
rgsl888prabhu Nov 4, 2019
f46ae31
changes for test cases
rgsl888prabhu Nov 4, 2019
d055987
merge 0.11
rgsl888prabhu Nov 4, 2019
216b367
changes to filter
rgsl888prabhu Nov 5, 2019
26b1b32
changes to return column
rgsl888prabhu Nov 5, 2019
8e755fb
ahh working
rgsl888prabhu Nov 5, 2019
b743175
All set
rgsl888prabhu Nov 5, 2019
7cfccc1
documentation
rgsl888prabhu Nov 5, 2019
a0d0e61
code changes and test cases
rgsl888prabhu Nov 5, 2019
a72ebe7
CHANGELOG
rgsl888prabhu Nov 5, 2019
ca97b2e
adding apply_boolean_mask
rgsl888prabhu Nov 7, 2019
8a1cea6
Adding apply_boolean_mask with test case
rgsl888prabhu Nov 7, 2019
8dd75d8
documentation
rgsl888prabhu Nov 7, 2019
664afea
review changes
rgsl888prabhu Nov 7, 2019
8c4f556
changes
rgsl888prabhu Nov 7, 2019
eb457ed
Merge branch 'branch-0.11' into 2948_adding_copy_if
harrism Nov 8, 2019
f15905a
unique_count and test cases
rgsl888prabhu Nov 11, 2019
4f710c7
added string test for unique count
rgsl888prabhu Nov 11, 2019
07d48c5
Added drop_duplicate test cases
rgsl888prabhu Nov 11, 2019
f75ad3a
documentation
rgsl888prabhu Nov 11, 2019
fa74c22
merge
rgsl888prabhu Nov 11, 2019
2ae0095
documentation
rgsl888prabhu Nov 11, 2019
3801ddd
cosmetic changes
rgsl888prabhu Nov 12, 2019
a544d09
doc changes
rgsl888prabhu Nov 12, 2019
00a6c6f
review changes including wrapper
rgsl888prabhu Nov 12, 2019
b20edc9
drop_duplicate to use vector of index values as keys
rgsl888prabhu Nov 13, 2019
0ffbf41
Changes apart from scatter in copy_if
rgsl888prabhu Nov 13, 2019
257b07d
documentation
rgsl888prabhu Nov 13, 2019
e076c09
addressed final set of review comments
rgsl888prabhu Nov 14, 2019
4551a99
review changes
rgsl888prabhu Nov 15, 2019
1fad669
code changes to support string in copy_if
rgsl888prabhu Nov 15, 2019
eb0641f
merge with 0.11
rgsl888prabhu Nov 15, 2019
3bb2666
missed changes
rgsl888prabhu Nov 15, 2019
c5d2f9f
merge with 0.11
rgsl888prabhu Nov 18, 2019
e9d3298
review changes
rgsl888prabhu Nov 18, 2019
653799f
specialization for gather
rgsl888prabhu Nov 18, 2019
703221a
removing the factory method
rgsl888prabhu Nov 18, 2019
856794d
review changes
rgsl888prabhu Nov 18, 2019
df0d9aa
review changes
rgsl888prabhu Nov 19, 2019
8a77cfb
review changes
rgsl888prabhu Nov 19, 2019
a1e1259
Merge branch 'branch-0.11' into 2948_adding_copy_if
harrism Nov 20, 2019
f5687b2
string test for drop_duplicates
rgsl888prabhu Nov 20, 2019
4129ed5
adding string test for cudf::gather
rgsl888prabhu Nov 21, 2019
91ef036
review changes
rgsl888prabhu Nov 21, 2019
ae85f57
Merge branch 'branch-0.11' of https://github.com/rapidsai/cudf into 2…
rgsl888prabhu Nov 21, 2019
5e64ad3
review changes
rgsl888prabhu Nov 21, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
- PR #3309 Add java and JNI bindings for search bounds
- PR #3382 Add fill function for strings column
- PR #3391 Move device_atomics_tests.cu files to legacy
- PR #3303 Define and implement new stream compaction APIs `copy_if`, `drop_nulls`, `apply_boolean_mask`, `drop_duplicate` and `unique_count`.

## Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions conda/recipes/libcudf/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ test:
- test -f $PREFIX/include/cudf/legacy/replace.hpp
- test -f $PREFIX/include/cudf/legacy/rolling.hpp
- test -f $PREFIX/include/cudf/legacy/search.hpp
- test -f $PREFIX/include/cudf/stream_compaction.hpp
- test -f $PREFIX/include/cudf/legacy/stream_compaction.hpp
- test -f $PREFIX/include/cudf/transpose.hpp
- test -f $PREFIX/include/cudf/legacy/transform.hpp
Expand Down
3 changes: 3 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ add_library(cudf
src/transform/legacy/nans_to_nulls.cu
src/transform/transform.cpp
src/bitmask/legacy/bitmask_ops.cu
src/stream_compaction/apply_boolean_mask.cu
src/stream_compaction/drop_nulls.cu
src/stream_compaction/drop_duplicates.cu
src/stream_compaction/legacy/apply_boolean_mask.cu
src/stream_compaction/legacy/drop_nulls.cu
src/stream_compaction/legacy/drop_duplicates.cu
Expand Down
384 changes: 384 additions & 0 deletions cpp/include/cudf/detail/copy_if.cuh

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions cpp/include/cudf/detail/gather.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cudf/table/table_device_view.cuh>
#include <cudf/detail/utilities/release_assert.cuh>
#include <cudf/detail/utilities/cuda.cuh>
#include <cudf/strings/detail/gather.cuh>

#include <rmm/thrust_rmm_allocator.h>

Expand Down Expand Up @@ -50,24 +51,24 @@ struct bounds_checker {
template <bool ignore_out_of_bounds, typename MapIterator>
__global__ void gather_bitmask_kernel(table_device_view source_table,
MapIterator gather_map,
mutable_table_device_view destination_table,
bitmask_type * masks[],
harrism marked this conversation as resolved.
Show resolved Hide resolved
size_type destination_table_num_rows,
size_type* valid_counts) {

for (size_type i = 0; i < source_table.num_columns(); i++) {

constexpr int warp_size = 32;

column_device_view source_col = source_table.column(i);
mutable_column_device_view destination_col = destination_table.column(i);

if (source_col.has_nulls()) {
trevorsm7 marked this conversation as resolved.
Show resolved Hide resolved
size_type destination_row_base = blockIdx.x * blockDim.x;
cudf::size_type valid_count_accumulate = 0;

while (destination_row_base < destination_table.num_rows()) {
while (destination_row_base < destination_table_num_rows) {
size_type destination_row = destination_row_base + threadIdx.x;

const bool thread_active = destination_row < destination_col.size();
const bool thread_active = destination_row < destination_table_num_rows;
size_type source_row =
thread_active ? gather_map[destination_row] : 0;

Expand All @@ -84,7 +85,7 @@ __global__ void gather_bitmask_kernel(table_device_view source_table,

// Only one thread writes output
if (0 == threadIdx.x % warp_size) {
destination_col.set_mask_word(valid_index, valid_warp);
masks[i][valid_index] = valid_warp;
}
valid_count_accumulate += single_lane_block_popc_reduce(valid_warp);
destination_row_base += blockDim.x * gridDim.x;
Expand Down Expand Up @@ -150,14 +151,24 @@ struct column_gatherer
}

template <typename Element, typename MapIterator,
std::enable_if_t<not is_fixed_width<Element>()>* = nullptr>
std::enable_if_t<std::is_same<Element, cudf::string_view>::value>* = nullptr>
std::unique_ptr<column> operator()(column_view const& source_column,
MapIterator gather_map_begin,
MapIterator gather_map_end,
bool ignore_out_of_bounds,
rmm::mr::device_memory_resource *mr,
cudaStream_t stream) {
CUDF_FAIL("Column type must be numeric");
if (true == ignore_out_of_bounds) {
return cudf::strings::detail::gather<true>(
strings_column_view(source_column),
gather_map_begin, gather_map_end,
mr, stream);
} else {
return cudf::strings::detail::gather<false>(
strings_column_view(source_column),
gather_map_begin, gather_map_end,
mr, stream);
}
}

};
Expand Down Expand Up @@ -263,13 +274,20 @@ gather(table_view const& source_table, MapIterator gather_map_begin,
CUDA_TRY(cudaOccupancyMaxPotentialBlockSize(
&gather_grid_size, &gather_block_size, bitmask_kernel));


auto source_table_view = table_device_view::create(source_table);
auto destination_table_view = mutable_table_device_view::create(destination_table->mutable_view());
std::vector<bitmask_type*> host_masks(destination_table->num_columns());
auto mutable_destination_table = destination_table->mutable_view();
std::transform(mutable_destination_table.begin(), mutable_destination_table.end(),
host_masks.begin(), [] (auto col){
return col.nullable()?col.null_mask():nullptr;
});

rmm::device_vector<bitmask_type*> masks(host_masks);

bitmask_kernel<<<gather_grid_size, gather_block_size, 0, stream>>>(*source_table_view,
gather_map_begin,
*destination_table_view,
masks.data().get(),
destination_table->num_rows(),
valid_counts.data().get());

thrust::host_vector<cudf::size_type> h_valid_counts(valid_counts);
Expand Down
52 changes: 52 additions & 0 deletions cpp/include/cudf/detail/sorting.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cudf/types.hpp>

#include <memory>
#include <vector>

namespace cudf {
namespace experimental {
namespace detail {

/**---------------------------------------------------------------------------*
* @brief Computes the row indices that would produce `input` in a
* lexicographical sorted order.
*
* @param input The table to sort
* @param column_order The desired sort order for each column. Size must be
* equal to `input.num_columns()` or empty. If empty, all columns will be sorted
* in ascending order.
* @param null_precedence The desired order of null compared to other elements
* for each column. Size must be equal to `input.num_columns()` or empty.
* If empty, all columns will be sorted in `null_order::BEFORE`.
* @param[in] stream Optional CUDA stream on which to execute kernels
* @param[in] mr Optional, The resource to use for all allocations
* @return std::unique_ptr<column> A non-nullable column of INT32 elements
* containing the permuted row indices of `input` if it were sorted
*---------------------------------------------------------------------------**/
std::unique_ptr<column> sorted_order(
table_view input, std::vector<order> const& column_order = {},
std::vector<null_order> const& null_precedence = {},
cudaStream_t stream = 0,
rgsl888prabhu marked this conversation as resolved.
Show resolved Hide resolved
rmm::mr::device_memory_resource* mr = rmm::mr::get_default_resource());

} // namespace detail
} // namespace experimental
} // namespace cudf
Loading