Skip to content

Commit

Permalink
Expose streams in public unary APIs (#14342)
Browse files Browse the repository at this point in the history
Contributes to #925

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Mark Harris (https://github.com/harrism)
  - Nghia Truong (https://github.com/ttnghia)

URL: #14342
  • Loading branch information
vyasr authored Nov 6, 2023
1 parent 70c4283 commit f102ba8
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 29 deletions.
10 changes: 0 additions & 10 deletions cpp/include/cudf/detail/unary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ std::unique_ptr<column> true_if(InputIterator begin,

/**
* @copydoc cudf::unary_operation
*
* @param stream CUDA stream used for device memory operations and kernel launches.
*/
std::unique_ptr<cudf::column> unary_operation(cudf::column_view const& input,
cudf::unary_operator op,
Expand All @@ -74,17 +72,13 @@ std::unique_ptr<cudf::column> 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<cudf::column> is_valid(cudf::column_view const& input,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @copydoc cudf::cast
*
* @param stream CUDA stream used for device memory operations and kernel launches.
*/
std::unique_ptr<column> cast(column_view const& input,
data_type type,
Expand All @@ -93,17 +87,13 @@ std::unique_ptr<column> 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<column> is_nan(cudf::column_view const& input,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr);

/**
* @copydoc cudf::is_not_nan
*
* @param[in] stream CUDA stream used for device memory operations and kernel launches.
*/
std::unique_ptr<column> is_not_nan(cudf::column_view const& input,
rmm::cuda_stream_view stream,
Expand Down
15 changes: 14 additions & 1 deletion cpp/include/cudf/unary.hpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -17,6 +17,7 @@
#pragma once

#include <cudf/types.hpp>
#include <cudf/utilities/default_stream.hpp>

#include <rmm/mr/device/per_device_resource.hpp>

Expand Down Expand Up @@ -65,41 +66,47 @@ 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
*/
std::unique_ptr<cudf::column> 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());

/**
* @brief Creates a column of `type_id::BOOL8` elements where for every element in `input` `true`
* 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`
* representing `null` values.
*/
std::unique_ptr<cudf::column> 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());

/**
* @brief Creates a column of `type_id::BOOL8` elements where for every element in `input` `true`
* 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`
* representing `null` values.
*/
std::unique_ptr<cudf::column> 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());

/**
Expand All @@ -109,6 +116,7 @@ std::unique_ptr<cudf::column> 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
Expand All @@ -117,6 +125,7 @@ std::unique_ptr<cudf::column> is_valid(
std::unique_ptr<column> 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());

/**
Expand All @@ -127,12 +136,14 @@ std::unique_ptr<column> 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<column> 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());

/**
Expand All @@ -143,13 +154,15 @@ std::unique_ptr<column> 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`
* values
*/
std::unique_ptr<column> 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
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/interop/to_arrow.cu
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ std::shared_ptr<arrow::Array> dispatch_to_arrow::operator()<cudf::dictionary32>(
{
// Arrow dictionary requires indices to be signed integer
std::unique_ptr<column> 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()<int32_t>(
dict_indices->view(), dict_indices->type().id(), {}, ar_mr, stream);
auto dict_keys = cudf::dictionary_column_view(input).keys();
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/unary/cast_ops.cu
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,11 @@ std::unique_ptr<column> cast(column_view const& input,

std::unique_ptr<column> 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
3 changes: 2 additions & 1 deletion cpp/src/unary/math_ops.cu
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,11 @@ std::unique_ptr<cudf::column> unary_operation(cudf::column_view const& input,

std::unique_ptr<cudf::column> 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
11 changes: 7 additions & 4 deletions cpp/src/unary/nan_ops.cu
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -91,17 +91,20 @@ std::unique_ptr<column> is_not_nan(cudf::column_view const& input,

} // namespace detail

std::unique_ptr<column> is_nan(cudf::column_view const& input, rmm::mr::device_memory_resource* mr)
std::unique_ptr<column> 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<column> 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
11 changes: 7 additions & 4 deletions cpp/src/unary/null_ops.cu
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -55,17 +55,20 @@ std::unique_ptr<column> is_valid(cudf::column_view const& input,

} // namespace detail

std::unique_ptr<column> is_null(cudf::column_view const& input, rmm::mr::device_memory_resource* mr)
std::unique_ptr<column> 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<column> 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
9 changes: 5 additions & 4 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ####################################################################################
Expand Down
65 changes: 65 additions & 0 deletions cpp/tests/streams/unary_test.cpp
Original file line number Diff line number Diff line change
@@ -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 <cudf/unary.hpp>

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>

class UnaryTest : public cudf::test::BaseFixture {};

TEST_F(UnaryTest, UnaryOperation)
{
cudf::test::fixed_width_column_wrapper<int32_t> 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<int32_t> 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<int32_t> 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<int32_t> 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<float> 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<float> const column{10, 20, 30, 40, 50};

cudf::is_not_nan(column, cudf::test::get_default_stream());
}

0 comments on commit f102ba8

Please sign in to comment.