From f102ba810922600008cbf4e0ba9441e93963c7fb Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Mon, 6 Nov 2023 15:56:34 -0800 Subject: [PATCH] Expose streams in public unary APIs (#14342) Contributes to #925 Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Mark Harris (https://github.com/harrism) - Nghia Truong (https://github.com/ttnghia) URL: https://github.com/rapidsai/cudf/pull/14342 --- cpp/include/cudf/detail/unary.hpp | 10 ----- cpp/include/cudf/unary.hpp | 15 ++++++- cpp/src/interop/to_arrow.cu | 8 ++-- cpp/src/unary/cast_ops.cu | 3 +- cpp/src/unary/math_ops.cu | 3 +- cpp/src/unary/nan_ops.cu | 11 ++++-- cpp/src/unary/null_ops.cu | 11 ++++-- cpp/tests/CMakeLists.txt | 9 +++-- cpp/tests/streams/unary_test.cpp | 65 +++++++++++++++++++++++++++++++ 9 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 cpp/tests/streams/unary_test.cpp diff --git a/cpp/include/cudf/detail/unary.hpp b/cpp/include/cudf/detail/unary.hpp index 3fbdf4a5a8f..12f864de572 100644 --- a/cpp/include/cudf/detail/unary.hpp +++ b/cpp/include/cudf/detail/unary.hpp @@ -64,8 +64,6 @@ std::unique_ptr true_if(InputIterator begin, /** * @copydoc cudf::unary_operation - * - * @param stream CUDA stream used for device memory operations and kernel launches. */ std::unique_ptr unary_operation(cudf::column_view const& input, cudf::unary_operator op, @@ -74,8 +72,6 @@ std::unique_ptr unary_operation(cudf::column_view const& input, /** * @copydoc cudf::is_valid - * - * @param stream CUDA stream used for device memory operations and kernel launches. */ std::unique_ptr is_valid(cudf::column_view const& input, rmm::cuda_stream_view stream, @@ -83,8 +79,6 @@ std::unique_ptr is_valid(cudf::column_view const& input, /** * @copydoc cudf::cast - * - * @param stream CUDA stream used for device memory operations and kernel launches. */ std::unique_ptr cast(column_view const& input, data_type type, @@ -93,8 +87,6 @@ std::unique_ptr cast(column_view const& input, /** * @copydoc cudf::is_nan - * - * @param[in] stream CUDA stream used for device memory operations and kernel launches. */ std::unique_ptr is_nan(cudf::column_view const& input, rmm::cuda_stream_view stream, @@ -102,8 +94,6 @@ std::unique_ptr is_nan(cudf::column_view const& input, /** * @copydoc cudf::is_not_nan - * - * @param[in] stream CUDA stream used for device memory operations and kernel launches. */ std::unique_ptr is_not_nan(cudf::column_view const& input, rmm::cuda_stream_view stream, diff --git a/cpp/include/cudf/unary.hpp b/cpp/include/cudf/unary.hpp index 1130c41afe5..64e802d88dd 100644 --- a/cpp/include/cudf/unary.hpp +++ b/cpp/include/cudf/unary.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, NVIDIA CORPORATION. + * Copyright (c) 2018-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. @@ -17,6 +17,7 @@ #pragma once #include +#include #include @@ -65,6 +66,7 @@ enum class unary_operator : int32_t { * * @param input A `column_view` as input * @param op operation to perform + * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned column's device memory * * @returns Column of same size as `input` containing result of the operation @@ -72,6 +74,7 @@ enum class unary_operator : int32_t { std::unique_ptr unary_operation( cudf::column_view const& input, cudf::unary_operator op, + rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** @@ -79,6 +82,7 @@ std::unique_ptr unary_operation( * indicates the value is null and `false` indicates the value is valid. * * @param input A `column_view` as input + * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned column's device memory * * @returns A non-nullable column of `type_id::BOOL8` elements with `true` @@ -86,6 +90,7 @@ std::unique_ptr unary_operation( */ std::unique_ptr is_null( cudf::column_view const& input, + rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** @@ -93,6 +98,7 @@ std::unique_ptr is_null( * indicates the value is valid and `false` indicates the value is null. * * @param input A `column_view` as input + * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned column's device memory * * @returns A non-nullable column of `type_id::BOOL8` elements with `false` @@ -100,6 +106,7 @@ std::unique_ptr is_null( */ std::unique_ptr is_valid( cudf::column_view const& input, + rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** @@ -109,6 +116,7 @@ std::unique_ptr is_valid( * * @param input Input column * @param out_type Desired datatype of output column + * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned column's device memory * * @returns Column of same size as `input` containing result of the cast operation @@ -117,6 +125,7 @@ std::unique_ptr is_valid( std::unique_ptr cast( column_view const& input, data_type out_type, + rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** @@ -127,12 +136,14 @@ std::unique_ptr cast( * @throws cudf::logic_error if `input` is a non-floating point type * * @param input A column of floating-point elements + * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned column's device memory * * @returns A non-nullable column of `type_id::BOOL8` elements with `true` representing `NAN` values */ std::unique_ptr is_nan( cudf::column_view const& input, + rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** @@ -143,6 +154,7 @@ std::unique_ptr is_nan( * @throws cudf::logic_error if `input` is a non-floating point type * * @param input A column of floating-point elements + * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned column's device memory * * @returns A non-nullable column of `type_id::BOOL8` elements with `false` representing `NAN` @@ -150,6 +162,7 @@ std::unique_ptr is_nan( */ std::unique_ptr is_not_nan( cudf::column_view const& input, + rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** @} */ // end of group diff --git a/cpp/src/interop/to_arrow.cu b/cpp/src/interop/to_arrow.cu index 28230cf8e74..3a9fe50d25b 100644 --- a/cpp/src/interop/to_arrow.cu +++ b/cpp/src/interop/to_arrow.cu @@ -382,10 +382,10 @@ std::shared_ptr dispatch_to_arrow::operator()( { // Arrow dictionary requires indices to be signed integer std::unique_ptr dict_indices = - cast(cudf::dictionary_column_view(input).get_indices_annotated(), - cudf::data_type{type_id::INT32}, - stream, - rmm::mr::get_current_device_resource()); + detail::cast(cudf::dictionary_column_view(input).get_indices_annotated(), + cudf::data_type{type_id::INT32}, + stream, + rmm::mr::get_current_device_resource()); auto indices = dispatch_to_arrow{}.operator()( dict_indices->view(), dict_indices->type().id(), {}, ar_mr, stream); auto dict_keys = cudf::dictionary_column_view(input).keys(); diff --git a/cpp/src/unary/cast_ops.cu b/cpp/src/unary/cast_ops.cu index 6fa87b1f709..8421f32056e 100644 --- a/cpp/src/unary/cast_ops.cu +++ b/cpp/src/unary/cast_ops.cu @@ -415,10 +415,11 @@ std::unique_ptr cast(column_view const& input, std::unique_ptr cast(column_view const& input, data_type type, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::cast(input, type, cudf::get_default_stream(), mr); + return detail::cast(input, type, stream, mr); } } // namespace cudf diff --git a/cpp/src/unary/math_ops.cu b/cpp/src/unary/math_ops.cu index d84e0171b49..88922362319 100644 --- a/cpp/src/unary/math_ops.cu +++ b/cpp/src/unary/math_ops.cu @@ -646,10 +646,11 @@ std::unique_ptr unary_operation(cudf::column_view const& input, std::unique_ptr unary_operation(cudf::column_view const& input, cudf::unary_operator op, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::unary_operation(input, op, cudf::get_default_stream(), mr); + return detail::unary_operation(input, op, stream, mr); } } // namespace cudf diff --git a/cpp/src/unary/nan_ops.cu b/cpp/src/unary/nan_ops.cu index 2cf83466b03..092ad3b6731 100644 --- a/cpp/src/unary/nan_ops.cu +++ b/cpp/src/unary/nan_ops.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. + * Copyright (c) 2020-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. @@ -91,17 +91,20 @@ std::unique_ptr is_not_nan(cudf::column_view const& input, } // namespace detail -std::unique_ptr is_nan(cudf::column_view const& input, rmm::mr::device_memory_resource* mr) +std::unique_ptr is_nan(cudf::column_view const& input, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::is_nan(input, cudf::get_default_stream(), mr); + return detail::is_nan(input, stream, mr); } std::unique_ptr is_not_nan(cudf::column_view const& input, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::is_not_nan(input, cudf::get_default_stream(), mr); + return detail::is_not_nan(input, stream, mr); } } // namespace cudf diff --git a/cpp/src/unary/null_ops.cu b/cpp/src/unary/null_ops.cu index e64c68fdae6..6bdd65dd42d 100644 --- a/cpp/src/unary/null_ops.cu +++ b/cpp/src/unary/null_ops.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * Copyright (c) 2019-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. @@ -55,17 +55,20 @@ std::unique_ptr is_valid(cudf::column_view const& input, } // namespace detail -std::unique_ptr is_null(cudf::column_view const& input, rmm::mr::device_memory_resource* mr) +std::unique_ptr is_null(cudf::column_view const& input, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::is_null(input, cudf::get_default_stream(), mr); + return detail::is_null(input, stream, mr); } std::unique_ptr is_valid(cudf::column_view const& input, + rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { CUDF_FUNC_RANGE(); - return detail::is_valid(input, cudf::get_default_stream(), mr); + return detail::is_valid(input, stream, mr); } } // namespace cudf diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index e966ef3fb04..47e266ced71 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -629,14 +629,17 @@ ConfigureTest( ConfigureTest(STREAM_BINARYOP_TEST streams/binaryop_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_CONCATENATE_TEST streams/concatenate_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_COPYING_TEST streams/copying_test.cpp STREAM_MODE testing) +ConfigureTest(STREAM_DICTIONARY_TEST streams/dictionary_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_FILLING_TEST streams/filling_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_GROUPBY_TEST streams/groupby_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_HASHING_TEST streams/hash_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_INTEROP_TEST streams/interop_test.cpp STREAM_MODE testing) +ConfigureTest(STREAM_JSONIO_TEST streams/io/json_test.cpp STREAM_MODE testing) +ConfigureTest(STREAM_LISTS_TEST streams/lists_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_NULL_MASK_TEST streams/null_mask_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_REPLACE_TEST streams/replace_test.cpp STREAM_MODE testing) ConfigureTest(STREAM_SEARCH_TEST streams/search_test.cpp STREAM_MODE testing) -ConfigureTest(STREAM_DICTIONARY_TEST streams/dictionary_test.cpp STREAM_MODE testing) +ConfigureTest(STREAM_SORTING_TEST streams/sorting_test.cpp STREAM_MODE testing) ConfigureTest( STREAM_STRINGS_TEST streams/strings/case_test.cpp @@ -653,12 +656,10 @@ ConfigureTest( STREAM_MODE testing ) -ConfigureTest(STREAM_SORTING_TEST streams/sorting_test.cpp STREAM_MODE testing) ConfigureTest( STREAM_TEXT_TEST streams/text/ngrams_test.cpp streams/text/tokenize_test.cpp STREAM_MODE testing ) -ConfigureTest(STREAM_LISTS_TEST streams/lists_test.cpp STREAM_MODE testing) -ConfigureTest(STREAM_JSONIO_TEST streams/io/json_test.cpp STREAM_MODE testing) +ConfigureTest(STREAM_UNARY_TEST streams/unary_test.cpp STREAM_MODE testing) # ################################################################################################## # Install tests #################################################################################### diff --git a/cpp/tests/streams/unary_test.cpp b/cpp/tests/streams/unary_test.cpp new file mode 100644 index 00000000000..1734c0c4e9f --- /dev/null +++ b/cpp/tests/streams/unary_test.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 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. + * 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. + */ + +#include + +#include +#include +#include + +class UnaryTest : public cudf::test::BaseFixture {}; + +TEST_F(UnaryTest, UnaryOperation) +{ + cudf::test::fixed_width_column_wrapper const column{10, 20, 30, 40, 50}; + + cudf::unary_operation(column, cudf::unary_operator::ABS, cudf::test::get_default_stream()); +} + +TEST_F(UnaryTest, IsNull) +{ + cudf::test::fixed_width_column_wrapper const column{10, 20, 30, 40, 50}; + + cudf::is_null(column, cudf::test::get_default_stream()); +} + +TEST_F(UnaryTest, IsValid) +{ + cudf::test::fixed_width_column_wrapper const column{10, 20, 30, 40, 50}; + + cudf::is_valid(column, cudf::test::get_default_stream()); +} + +TEST_F(UnaryTest, Cast) +{ + cudf::test::fixed_width_column_wrapper const column{10, 20, 30, 40, 50}; + + cudf::cast(column, cudf::data_type{cudf::type_id::INT64}, cudf::test::get_default_stream()); +} + +TEST_F(UnaryTest, IsNan) +{ + cudf::test::fixed_width_column_wrapper const column{10, 20, 30, 40, 50}; + + cudf::is_nan(column, cudf::test::get_default_stream()); +} + +TEST_F(UnaryTest, IsNotNan) +{ + cudf::test::fixed_width_column_wrapper const column{10, 20, 30, 40, 50}; + + cudf::is_not_nan(column, cudf::test::get_default_stream()); +}