diff --git a/cpp/include/cudf/detail/copy_if.cuh b/cpp/include/cudf/detail/copy_if.cuh index 501071cafb7..bb5cfa5c6e0 100644 --- a/cpp/include/cudf/detail/copy_if.cuh +++ b/cpp/include/cudf/detail/copy_if.cuh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, NVIDIA CORPORATION. + * Copyright (c) 2019-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -36,12 +36,15 @@ #include #include #include +#include #include #include -namespace { +namespace cudf { +namespace detail { + // Compute the count of elements that pass the mask within each block template __global__ void compute_block_counts(cudf::size_type* __restrict__ block_counts, @@ -293,9 +296,9 @@ struct scatter_gather_functor { filter); auto output_table = cudf::detail::gather(cudf::table_view{{input}}, - indices.begin(), - indices.end(), + indices, cudf::out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr); @@ -304,10 +307,6 @@ struct scatter_gather_functor { } }; -} // namespace - -namespace cudf { -namespace detail { /** * @brief Filters `input` using a Filter function object * diff --git a/cpp/include/cudf/detail/gather.hpp b/cpp/include/cudf/detail/gather.hpp index b01690f82df..01d9c64ba30 100644 --- a/cpp/include/cudf/detail/gather.hpp +++ b/cpp/include/cudf/detail/gather.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, NVIDIA CORPORATION. + * Copyright (c) 2019-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ #pragma once #include -#include - #include #include +#include +#include #include @@ -55,10 +55,10 @@ enum class negative_index_policy : bool { ALLOWED, NOT_ALLOWED }; * indices. If `policy` is set to `DONT_CHECK` and there are out-of-bounds indices in `gather_map`, * the behavior is undefined. * @param[in] negative_index_policy Interpret each negative index `i` in the - * gathermap as the positive index `i+num_source_rows`. + * `gather_map` as the positive index `i+num_source_rows`. * @param[in] stream CUDA stream used for device memory operations and kernel launches. * @param[in] mr Device memory resource used to allocate the returned table's device memory - * @return cudf::table Result of the gather + * @return Result of the gather */ std::unique_ptr gather( table_view const& source_table, @@ -67,5 +67,21 @@ std::unique_ptr
gather( negative_index_policy neg_indices, rmm::cuda_stream_view stream = rmm::cuda_stream_default, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @copydoc cudf::detail::gather(table_view const&,column_view const&,table_view + * const&,cudf::out_of_bounds_policy,cudf::detail::negative_index_policy,rmm::cuda_stream_view, + * rmm::mr::device_memory_resource*) + * + * @throws cudf::logic_error if `gather_map` span size is larger than max of `size_type`. + */ +std::unique_ptr
gather( + table_view const& source_table, + device_span const gather_map, + out_of_bounds_policy bounds_policy, + negative_index_policy neg_indices, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + } // namespace detail } // namespace cudf diff --git a/cpp/include/cudf/detail/scatter.hpp b/cpp/include/cudf/detail/scatter.hpp index a3b1f95ca0a..e43f8495d07 100644 --- a/cpp/include/cudf/detail/scatter.hpp +++ b/cpp/include/cudf/detail/scatter.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, NVIDIA CORPORATION. + * Copyright (c) 2019-2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include @@ -70,6 +70,20 @@ std::unique_ptr
scatter( rmm::cuda_stream_view stream = rmm::cuda_stream_default, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); +/** + * @copydoc cudf::detail::scatter(table_view const&,column_view const&,table_view + * const&,bool,rmm::cuda_stream_view,rmm::mr::device_memory_resource*) + * + * @throws cudf::logic_error if `scatter_map` span size is larger than max of `size_type`. + */ +std::unique_ptr
scatter( + table_view const& source, + device_span const scatter_map, + table_view const& target, + bool check_bounds = false, + rmm::cuda_stream_view stream = rmm::cuda_stream_default, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + /** * @brief Scatters a row of scalar values into a copy of the target table * according to a scatter map. diff --git a/cpp/src/copying/copy.cu b/cpp/src/copying/copy.cu index 381fad5f96e..2ee3fee4577 100644 --- a/cpp/src/copying/copy.cu +++ b/cpp/src/copying/copy.cu @@ -14,13 +14,12 @@ * limitations under the License. */ -#include #include #include -#include +#include #include #include -#include +#include #include #include #include @@ -168,23 +167,24 @@ std::unique_ptr scatter_gather_based_if_else(cudf::column_view const& lh rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - auto scatter_map = rmm::device_uvector{static_cast(size), stream}; - auto const scatter_map_end = thrust::copy_if(rmm::exec_policy(stream), - thrust::make_counting_iterator(size_type{0}), - thrust::make_counting_iterator(size_type{size}), - scatter_map.begin(), - is_left); + auto gather_map = rmm::device_uvector{static_cast(size), stream}; + auto const gather_map_end = thrust::copy_if(rmm::exec_policy(stream), + thrust::make_counting_iterator(size_type{0}), + thrust::make_counting_iterator(size_type{size}), + gather_map.begin(), + is_left); + + gather_map.resize(thrust::distance(gather_map.begin(), gather_map_end), stream); auto const scatter_src_lhs = cudf::detail::gather(table_view{std::vector{lhs}}, - scatter_map.begin(), - scatter_map_end, + gather_map, out_of_bounds_policy::DONT_CHECK, + negative_index_policy::NOT_ALLOWED, stream); auto result = cudf::detail::scatter( table_view{std::vector{scatter_src_lhs->get_column(0).view()}}, - scatter_map.begin(), - scatter_map_end, + gather_map, table_view{std::vector{rhs}}, false, stream, @@ -214,8 +214,12 @@ std::unique_ptr scatter_gather_based_if_else(cudf::scalar const& lhs, static_cast(scatter_map_size), scatter_map.begin()}; - auto result = cudf::scatter( - scatter_source, scatter_map_column_view, table_view{std::vector{rhs}}, false, mr); + auto result = cudf::detail::scatter(scatter_source, + scatter_map_column_view, + table_view{std::vector{rhs}}, + false, + stream, + mr); return std::move(result->release()[0]); } diff --git a/cpp/src/copying/gather.cu b/cpp/src/copying/gather.cu index 181752d18e8..5c66f67ff0f 100644 --- a/cpp/src/copying/gather.cu +++ b/cpp/src/copying/gather.cu @@ -54,6 +54,21 @@ std::unique_ptr
gather(table_view const& source_table, return gather(source_table, map_begin, map_end, bounds_policy, stream, mr); } +std::unique_ptr
gather(table_view const& source_table, + device_span const gather_map, + out_of_bounds_policy bounds_policy, + negative_index_policy neg_indices, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + CUDF_EXPECTS(gather_map.size() <= std::numeric_limits::max(), + "invalid gather map size"); + auto map_col = column_view(data_type{type_to_id()}, + static_cast(gather_map.size()), + gather_map.data()); + return gather(source_table, map_col, bounds_policy, neg_indices, stream, mr); +} + } // namespace detail std::unique_ptr
gather(table_view const& source_table, diff --git a/cpp/src/copying/scatter.cu b/cpp/src/copying/scatter.cu index 3312316f548..211bc0e1ebe 100644 --- a/cpp/src/copying/scatter.cu +++ b/cpp/src/copying/scatter.cu @@ -16,8 +16,6 @@ #include #include #include -#include -#include #include #include #include @@ -305,6 +303,21 @@ std::unique_ptr
scatter(table_view const& source, return detail::scatter(source, map_begin, map_end, target, check_bounds, stream, mr); } +std::unique_ptr
scatter(table_view const& source, + device_span const scatter_map, + table_view const& target, + bool check_bounds, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) +{ + CUDF_EXPECTS(scatter_map.size() <= std::numeric_limits::max(), + "invalid scatter map size"); + auto map_col = column_view(data_type{type_to_id()}, + static_cast(scatter_map.size()), + scatter_map.data()); + return scatter(source, map_col, target, check_bounds, stream, mr); +} + std::unique_ptr
scatter(std::vector> const& source, column_view const& indices, table_view const& target, diff --git a/cpp/src/groupby/hash/groupby.cu b/cpp/src/groupby/hash/groupby.cu index aa7915e6c8b..247580bb8ee 100644 --- a/cpp/src/groupby/hash/groupby.cu +++ b/cpp/src/groupby/hash/groupby.cu @@ -26,13 +26,14 @@ #include #include #include -#include #include #include +#include #include #include #include #include +#include #include #include #include @@ -167,7 +168,6 @@ class hash_compound_agg_finalizer final : public cudf::detail::aggregation_final cudf::detail::result_cache* sparse_results; cudf::detail::result_cache* dense_results; device_span gather_map; - size_type const map_size; Map const& map; bitmask_type const* __restrict__ row_bitmask; rmm::cuda_stream_view stream; @@ -181,7 +181,6 @@ class hash_compound_agg_finalizer final : public cudf::detail::aggregation_final cudf::detail::result_cache* sparse_results, cudf::detail::result_cache* dense_results, device_span gather_map, - size_type map_size, Map const& map, bitmask_type const* row_bitmask, rmm::cuda_stream_view stream, @@ -191,7 +190,6 @@ class hash_compound_agg_finalizer final : public cudf::detail::aggregation_final sparse_results(sparse_results), dense_results(dense_results), gather_map(gather_map), - map_size(map_size), map(map), row_bitmask(row_bitmask), stream(stream), @@ -203,11 +201,12 @@ class hash_compound_agg_finalizer final : public cudf::detail::aggregation_final auto to_dense_agg_result(cudf::aggregation const& agg) { - auto s = sparse_results->get_result(col_idx, agg); + auto s = sparse_results->get_result(col_idx, agg); + auto dense_result_table = cudf::detail::gather(table_view({std::move(s)}), - gather_map.begin(), - gather_map.begin() + map_size, + gather_map, out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr); return std::move(dense_result_table->release()[0]); @@ -385,7 +384,7 @@ void sparse_to_dense_results(table_view const& keys, cudf::detail::result_cache* sparse_results, cudf::detail::result_cache* dense_results, device_span gather_map, - size_type map_size, + // size_type map_size, Map const& map, bool keys_have_nulls, null_policy include_null_keys, @@ -403,16 +402,8 @@ void sparse_to_dense_results(table_view const& keys, // Given an aggregation, this will get the result from sparse_results and // convert and return dense, compacted result - auto finalizer = hash_compound_agg_finalizer(i, - col, - sparse_results, - dense_results, - gather_map, - map_size, - map, - row_bitmask_ptr, - stream, - mr); + auto finalizer = hash_compound_agg_finalizer( + i, col, sparse_results, dense_results, gather_map, map, row_bitmask_ptr, stream, mr); for (auto&& agg : agg_v) { agg->finalize(finalizer); } @@ -613,15 +604,18 @@ std::unique_ptr
groupby_null_templated(table_view const& keys, &sparse_results, cache, gather_map, - gather_map.size(), *map, keys_have_nulls, include_null_keys, stream, mr); - return cudf::detail::gather( - keys, gather_map.begin(), gather_map.end(), out_of_bounds_policy::DONT_CHECK, stream, mr); + return cudf::detail::gather(keys, + gather_map, + out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, + stream, + mr); } } // namespace diff --git a/cpp/src/groupby/sort/group_collect.cu b/cpp/src/groupby/sort/group_collect.cu index a30d4639af8..43a1674d97f 100644 --- a/cpp/src/groupby/sort/group_collect.cu +++ b/cpp/src/groupby/sort/group_collect.cu @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/cpp/src/groupby/sort/group_nth_element.cu b/cpp/src/groupby/sort/group_nth_element.cu index e7dc57f6c93..f2c57abf54e 100644 --- a/cpp/src/groupby/sort/group_nth_element.cu +++ b/cpp/src/groupby/sort/group_nth_element.cu @@ -20,12 +20,13 @@ #include #include #include -#include +#include #include #include #include #include +#include #include #include @@ -113,10 +114,11 @@ std::unique_ptr group_nth_element(column_view const& values, return (bitmask_iterator[i] && intra_group_index[i] == nth); }); } + auto output_table = cudf::detail::gather(table_view{{values}}, - nth_index.begin(), - nth_index.end(), + nth_index, out_of_bounds_policy::NULLIFY, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr); if (!output_table->get_column(0).has_nulls()) output_table->get_column(0).set_null_mask({}, 0); diff --git a/cpp/src/groupby/sort/group_replace_nulls.cu b/cpp/src/groupby/sort/group_replace_nulls.cu index 86590fc1734..cb954eb7ce5 100644 --- a/cpp/src/groupby/sort/group_replace_nulls.cu +++ b/cpp/src/groupby/sort/group_replace_nulls.cu @@ -14,8 +14,9 @@ * limitations under the License. */ #include -#include +#include #include +#include #include #include @@ -68,9 +69,9 @@ std::unique_ptr group_replace_nulls(cudf::column_view const& grouped_val } auto output = cudf::detail::gather(cudf::table_view({grouped_value}), - gather_map.begin(), - gather_map.end(), + gather_map, cudf::out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr); diff --git a/cpp/src/join/hash_join.cu b/cpp/src/join/hash_join.cu index 636729a735e..07ad2e052f1 100644 --- a/cpp/src/join/hash_join.cu +++ b/cpp/src/join/hash_join.cu @@ -17,11 +17,12 @@ #include #include +#include #include -#include -#include +#include #include +#include #include #include diff --git a/cpp/src/join/hash_join.cuh b/cpp/src/join/hash_join.cuh index dd21a22803b..dfb1af3cef1 100644 --- a/cpp/src/join/hash_join.cuh +++ b/cpp/src/join/hash_join.cuh @@ -16,8 +16,6 @@ #pragma once #include -#include -#include #include #include #include diff --git a/cpp/src/join/join.cu b/cpp/src/join/join.cu index 740431b8563..db79075d864 100644 --- a/cpp/src/join/join.cu +++ b/cpp/src/join/join.cu @@ -16,6 +16,7 @@ #include #include +#include #include #include #include diff --git a/cpp/src/lists/combine/concatenate_list_elements.cu b/cpp/src/lists/combine/concatenate_list_elements.cu index 4b84d80f6a0..4bef312b396 100644 --- a/cpp/src/lists/combine/concatenate_list_elements.cu +++ b/cpp/src/lists/combine/concatenate_list_elements.cu @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -202,9 +202,9 @@ std::unique_ptr gather_list_entries(column_view const& input, }); auto result = cudf::detail::gather(table_view{{entry_col}}, - gather_map.begin(), - gather_map.end(), + gather_map, out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr); return std::move(result->release()[0]); diff --git a/cpp/src/lists/copying/copying.cu b/cpp/src/lists/copying/copying.cu index ff4649f4945..d4a3d5555a6 100644 --- a/cpp/src/lists/copying/copying.cu +++ b/cpp/src/lists/copying/copying.cu @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include #include -#include +#include +#include #include #include diff --git a/cpp/src/lists/drop_list_duplicates.cu b/cpp/src/lists/drop_list_duplicates.cu index cbcb5d6bb1a..c547ca14f2d 100644 --- a/cpp/src/lists/drop_list_duplicates.cu +++ b/cpp/src/lists/drop_list_duplicates.cu @@ -18,13 +18,14 @@ #include #include -#include +#include #include #include #include #include #include #include +#include #include #include @@ -33,6 +34,7 @@ #include #include +#include #include namespace cudf { @@ -543,13 +545,17 @@ std::vector> get_unique_entries_and_list_offsets( all_lists_entries.has_nulls(), stream); + auto gather_map = column_view(data_type{type_to_id()}, + static_cast(thrust::distance(output_begin, output_end)), + unique_indices.data()); + // Collect unique entries and entry list offsets. // The new null_count and bitmask of the unique entries will also be generated // by the gather function. return cudf::detail::gather(table_view{{all_lists_entries, entries_list_offsets}}, - output_begin, - output_end, + gather_map, cudf::out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr) ->release(); diff --git a/cpp/src/lists/extract.cu b/cpp/src/lists/extract.cu index 94b86b670b1..c8ef4912392 100644 --- a/cpp/src/lists/extract.cu +++ b/cpp/src/lists/extract.cu @@ -16,10 +16,11 @@ #include #include #include -#include +#include #include #include +#include #include @@ -97,9 +98,9 @@ std::unique_ptr extract_list_element(lists_column_view lists_column, // call gather on the child column auto result = cudf::detail::gather(table_view({child_column}), - d_gather_map, - d_gather_map + gather_map->size(), + gather_map->view(), out_of_bounds_policy::NULLIFY, // nullify-out-of-bounds + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr) ->release(); diff --git a/cpp/src/partitioning/partitioning.cu b/cpp/src/partitioning/partitioning.cu index 67d71b7a39a..e8c56cdafd8 100644 --- a/cpp/src/partitioning/partitioning.cu +++ b/cpp/src/partitioning/partitioning.cu @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/cpp/src/quantiles/quantile.cu b/cpp/src/quantiles/quantile.cu index 25bf4a436ad..073b318b879 100644 --- a/cpp/src/quantiles/quantile.cu +++ b/cpp/src/quantiles/quantile.cu @@ -16,12 +16,13 @@ #include +#include #include -#include #include #include #include #include +#include #include #include #include @@ -30,6 +31,9 @@ #include #include +#include + +#include #include #include diff --git a/cpp/src/replace/nulls.cu b/cpp/src/replace/nulls.cu index 4fa42021bd2..2145dcc6b91 100644 --- a/cpp/src/replace/nulls.cu +++ b/cpp/src/replace/nulls.cu @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -387,9 +387,9 @@ std::unique_ptr replace_nulls_policy_impl(cudf::column_view const& } auto output = cudf::detail::gather(cudf::table_view({input}), - gather_map.begin(), - gather_map.end(), + gather_map, cudf::out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream, mr); diff --git a/cpp/src/reshape/interleave_columns.cu b/cpp/src/reshape/interleave_columns.cu index 30ff7b0549e..4cc8a84c868 100644 --- a/cpp/src/reshape/interleave_columns.cu +++ b/cpp/src/reshape/interleave_columns.cu @@ -15,11 +15,13 @@ */ #include -#include +#include #include #include +#include #include #include +#include #include #include diff --git a/cpp/src/rolling/lead_lag_nested_detail.cuh b/cpp/src/rolling/lead_lag_nested_detail.cuh index 4cff3053aa2..bde7101b9a9 100644 --- a/cpp/src/rolling/lead_lag_nested_detail.cuh +++ b/cpp/src/rolling/lead_lag_nested_detail.cuh @@ -18,11 +18,18 @@ #include #include +#include #include #include -#include -#include +#include +#include #include + +#include + +#include +#include + #include namespace cudf::detail { @@ -151,13 +158,12 @@ std::unique_ptr compute_lead_lag_for_nested(aggregation::Kind op, }); } - auto output_with_nulls = - cudf::detail::gather(table_view{std::vector{input}}, - gather_map_column->view().template begin(), - gather_map_column->view().end(), - out_of_bounds_policy::NULLIFY, - stream, - mr); + auto output_with_nulls = cudf::detail::gather(table_view{std::vector{input}}, + gather_map_column->view(), + out_of_bounds_policy::NULLIFY, + cudf::detail::negative_index_policy::NOT_ALLOWED, + stream, + mr); if (default_outputs.is_empty()) { return std::move(output_with_nulls->release()[0]); } @@ -172,22 +178,22 @@ std::unique_ptr compute_lead_lag_for_nested(aggregation::Kind op, scatter_map.begin(), is_null_index_predicate(input.size(), gather_map.begin())); + scatter_map.resize(thrust::distance(scatter_map.begin(), scatter_map_end), stream); // Bail early, if all LEAD/LAG computations succeeded. No defaults need be substituted. if (scatter_map.is_empty()) { return std::move(output_with_nulls->release()[0]); } // Gather only those default values that are to be substituted. auto gathered_defaults = cudf::detail::gather(table_view{std::vector{default_outputs}}, - scatter_map.begin(), - scatter_map_end, + scatter_map, out_of_bounds_policy::DONT_CHECK, + cudf::detail::negative_index_policy::NOT_ALLOWED, stream); // Scatter defaults into locations where LEAD/LAG computed nulls. auto scattered_results = cudf::detail::scatter( table_view{std::vector{gathered_defaults->release()[0]->view()}}, - scatter_map.begin(), - scatter_map_end, + scatter_map, table_view{std::vector{output_with_nulls->release()[0]->view()}}, false, stream, diff --git a/docs/cudf/source/api_docs/index.rst b/docs/cudf/source/api_docs/index.rst index 960608d8f3c..0bf1d11bff4 100644 --- a/docs/cudf/source/api_docs/index.rst +++ b/docs/cudf/source/api_docs/index.rst @@ -17,4 +17,5 @@ This page provides a list of all publicly accessible modules, methods and classe general_utilities window io + subword_tokenize diff --git a/docs/cudf/source/api_docs/subword_tokenize.rst b/docs/cudf/source/api_docs/subword_tokenize.rst new file mode 100644 index 00000000000..e8737a9ee0a --- /dev/null +++ b/docs/cudf/source/api_docs/subword_tokenize.rst @@ -0,0 +1,12 @@ +================ +SubwordTokenizer +================ +.. currentmodule:: cudf.core.subword_tokenizer + +Constructor +~~~~~~~~~~~ +.. autosummary:: + :toctree: api/ + :template: autosummary/class_with_autosummary.rst + + SubwordTokenizer