Skip to content

Commit

Permalink
Add stream parameter to reshape APIs (#16410)
Browse files Browse the repository at this point in the history
Adds `stream` parameter to reshape APIs:
- `cudf::interleave_columns`
- `cudf::tile`
- `cudf::byte_cast`

Found while working #15983

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Nghia Truong (https://github.com/ttnghia)

URL: #16410
  • Loading branch information
davidwendt authored Jul 29, 2024
1 parent 58f4724 commit 6e7624d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
4 changes: 0 additions & 4 deletions cpp/include/cudf/detail/reshape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace CUDF_EXPORT cudf {
namespace detail {
/**
* @copydoc cudf::tile
*
* @param stream CUDA stream used for device memory operations and kernel launches
*/
std::unique_ptr<table> tile(table_view const& input,
size_type count,
Expand All @@ -38,8 +36,6 @@ std::unique_ptr<table> tile(table_view const& input,

/**
* @copydoc cudf::interleave_columns
*
* @param stream CUDA stream used for device memory operations and kernel launches
*/
std::unique_ptr<column> interleave_columns(table_view const& input,
rmm::cuda_stream_view,
Expand Down
17 changes: 11 additions & 6 deletions cpp/include/cudf/reshape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ namespace CUDF_EXPORT cudf {
* @throws cudf::logic_error if input contains no columns.
* @throws cudf::logic_error if input columns dtypes are not identical.
*
* @param[in] input Table containing columns to interleave
* @param[in] mr Device memory resource used to allocate the returned column's device memory
*
* @param input Table containing columns to interleave
* @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
* @return The interleaved columns as a single column
*/
std::unique_ptr<column> interleave_columns(
table_view const& input,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/**
Expand All @@ -68,15 +69,17 @@ std::unique_ptr<column> interleave_columns(
* return = [[8, 4, 7, 8, 4, 7], [5, 2, 3, 5, 2, 3]]
* ```
*
* @param[in] input Table containing rows to be repeated
* @param[in] count Number of times to tile "rows". Must be non-negative
* @param[in] mr Device memory resource used to allocate the returned table's device memory
* @param input Table containing rows to be repeated
* @param count Number of times to tile "rows". Must be non-negative
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate the returned table's device memory
*
* @return The table containing the tiled "rows"
*/
std::unique_ptr<table> tile(
table_view const& input,
size_type count,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/**
Expand All @@ -95,13 +98,15 @@ enum class flip_endianness : bool { NO, YES };
*
* @param input_column Column to be converted to lists of bytes
* @param endian_configuration Whether to retain or flip the endianness of the 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
*
* @return The column containing the lists of bytes
*/
std::unique_ptr<column> byte_cast(
column_view const& input_column,
flip_endianness endian_configuration,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());

/** @} */ // end of group
Expand Down
11 changes: 2 additions & 9 deletions cpp/src/reshape/byte_cast.cu
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ struct byte_list_conversion_fn<T, std::enable_if_t<std::is_same_v<T, cudf::strin

} // namespace

/**
* @copydoc cudf::byte_cast(column_view const&, flip_endianness, rmm::device_async_resource_ref)
*
* @param stream CUDA stream used for device memory operations and kernel launches.
*/
std::unique_ptr<column> byte_cast(column_view const& input,
flip_endianness endian_configuration,
rmm::cuda_stream_view stream,
Expand All @@ -183,15 +178,13 @@ std::unique_ptr<column> byte_cast(column_view const& input,

} // namespace detail

/**
* @copydoc cudf::byte_cast(column_view const&, flip_endianness, rmm::device_async_resource_ref)
*/
std::unique_ptr<column> byte_cast(column_view const& input,
flip_endianness endian_configuration,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::byte_cast(input, endian_configuration, cudf::get_default_stream(), mr);
return detail::byte_cast(input, endian_configuration, stream, mr);
}

} // namespace cudf
3 changes: 2 additions & 1 deletion cpp/src/reshape/interleave_columns.cu
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ std::unique_ptr<column> interleave_columns(table_view const& input,
} // namespace detail

std::unique_ptr<column> interleave_columns(table_view const& input,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::interleave_columns(input, cudf::get_default_stream(), mr);
return detail::interleave_columns(input, stream, mr);
}

} // namespace cudf
3 changes: 2 additions & 1 deletion cpp/src/reshape/tile.cu
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ std::unique_ptr<table> tile(table_view const& in,

std::unique_ptr<table> tile(table_view const& in,
size_type count,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::tile(in, count, cudf::get_default_stream(), mr);
return detail::tile(in, count, stream, mr);
}

} // namespace cudf
1 change: 1 addition & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ ConfigureTest(STREAM_PARQUETIO_TEST streams/io/parquet_test.cpp STREAM_MODE test
ConfigureTest(STREAM_POOL_TEST streams/pool_test.cu STREAM_MODE testing)
ConfigureTest(STREAM_REDUCTION_TEST streams/reduction_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_REPLACE_TEST streams/replace_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_RESHAPE_TEST streams/reshape_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_ROLLING_TEST streams/rolling_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_SEARCH_TEST streams/search_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_SORTING_TEST streams/sorting_test.cpp STREAM_MODE testing)
Expand Down
47 changes: 47 additions & 0 deletions cpp/tests/streams/reshape_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2023-2024, 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_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>

#include <cudf/column/column_view.hpp>
#include <cudf/reshape.hpp>

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

TEST_F(ReshapeTest, InterleaveColumns)
{
auto a = cudf::test::fixed_width_column_wrapper<int32_t>({0, 3, 6});
auto b = cudf::test::fixed_width_column_wrapper<int32_t>({1, 4, 7});
auto c = cudf::test::fixed_width_column_wrapper<int32_t>({2, 5, 8});
cudf::table_view in(std::vector<cudf::column_view>{a, b, c});
cudf::interleave_columns(in, cudf::test::get_default_stream());
}

TEST_F(ReshapeTest, Tile)
{
auto a = cudf::test::fixed_width_column_wrapper<int32_t>({-1, 0, 1});
cudf::table_view in(std::vector<cudf::column_view>{a});
cudf::tile(in, 2, cudf::test::get_default_stream());
}

TEST_F(ReshapeTest, ByteCast)
{
auto a = cudf::test::fixed_width_column_wrapper<int32_t>({0, 100, -100, 1000, 1000});
cudf::byte_cast(a, cudf::flip_endianness::YES, cudf::test::get_default_stream());
cudf::byte_cast(a, cudf::flip_endianness::NO, cudf::test::get_default_stream());
}

0 comments on commit 6e7624d

Please sign in to comment.