From 6e7624d6b31c93b0547590929ac63ed8e3a48d24 Mon Sep 17 00:00:00 2001
From: David Wendt <45795991+davidwendt@users.noreply.github.com>
Date: Mon, 29 Jul 2024 14:06:51 -0400
Subject: [PATCH] Add stream parameter to reshape APIs (#16410)
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: https://github.com/rapidsai/cudf/pull/16410
---
cpp/include/cudf/detail/reshape.hpp | 4 ---
cpp/include/cudf/reshape.hpp | 17 ++++++----
cpp/src/reshape/byte_cast.cu | 11 ++-----
cpp/src/reshape/interleave_columns.cu | 3 +-
cpp/src/reshape/tile.cu | 3 +-
cpp/tests/CMakeLists.txt | 1 +
cpp/tests/streams/reshape_test.cpp | 47 +++++++++++++++++++++++++++
7 files changed, 65 insertions(+), 21 deletions(-)
create mode 100644 cpp/tests/streams/reshape_test.cpp
diff --git a/cpp/include/cudf/detail/reshape.hpp b/cpp/include/cudf/detail/reshape.hpp
index 30f8b88b116..68a856373bf 100644
--- a/cpp/include/cudf/detail/reshape.hpp
+++ b/cpp/include/cudf/detail/reshape.hpp
@@ -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
tile(table_view const& input,
size_type count,
@@ -38,8 +36,6 @@ std::unique_ptr tile(table_view const& input,
/**
* @copydoc cudf::interleave_columns
- *
- * @param stream CUDA stream used for device memory operations and kernel launches
*/
std::unique_ptr interleave_columns(table_view const& input,
rmm::cuda_stream_view,
diff --git a/cpp/include/cudf/reshape.hpp b/cpp/include/cudf/reshape.hpp
index a0a7fe694bb..07aaf6488ad 100644
--- a/cpp/include/cudf/reshape.hpp
+++ b/cpp/include/cudf/reshape.hpp
@@ -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 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());
/**
@@ -68,15 +69,17 @@ std::unique_ptr 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 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());
/**
@@ -95,6 +98,7 @@ 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
@@ -102,6 +106,7 @@ enum class flip_endianness : bool { NO, YES };
std::unique_ptr 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
diff --git a/cpp/src/reshape/byte_cast.cu b/cpp/src/reshape/byte_cast.cu
index 3dfa0b65814..2a03a5504c1 100644
--- a/cpp/src/reshape/byte_cast.cu
+++ b/cpp/src/reshape/byte_cast.cu
@@ -167,11 +167,6 @@ struct byte_list_conversion_fn byte_cast(column_view const& input,
flip_endianness endian_configuration,
rmm::cuda_stream_view stream,
@@ -183,15 +178,13 @@ std::unique_ptr 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 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
diff --git a/cpp/src/reshape/interleave_columns.cu b/cpp/src/reshape/interleave_columns.cu
index 79124508b11..7473b6045af 100644
--- a/cpp/src/reshape/interleave_columns.cu
+++ b/cpp/src/reshape/interleave_columns.cu
@@ -264,10 +264,11 @@ std::unique_ptr interleave_columns(table_view const& input,
} // namespace detail
std::unique_ptr 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
diff --git a/cpp/src/reshape/tile.cu b/cpp/src/reshape/tile.cu
index 29996aa2152..3d4fb73c000 100644
--- a/cpp/src/reshape/tile.cu
+++ b/cpp/src/reshape/tile.cu
@@ -64,10 +64,11 @@ std::unique_ptr tile(table_view const& in,
std::unique_ptr 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
diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt
index 22827484f9a..4dffcb41ba2 100644
--- a/cpp/tests/CMakeLists.txt
+++ b/cpp/tests/CMakeLists.txt
@@ -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)
diff --git a/cpp/tests/streams/reshape_test.cpp b/cpp/tests/streams/reshape_test.cpp
new file mode 100644
index 00000000000..d7c5da91bca
--- /dev/null
+++ b/cpp/tests/streams/reshape_test.cpp
@@ -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
+#include
+#include
+
+#include
+#include
+
+class ReshapeTest : public cudf::test::BaseFixture {};
+
+TEST_F(ReshapeTest, InterleaveColumns)
+{
+ auto a = cudf::test::fixed_width_column_wrapper({0, 3, 6});
+ auto b = cudf::test::fixed_width_column_wrapper({1, 4, 7});
+ auto c = cudf::test::fixed_width_column_wrapper({2, 5, 8});
+ cudf::table_view in(std::vector{a, b, c});
+ cudf::interleave_columns(in, cudf::test::get_default_stream());
+}
+
+TEST_F(ReshapeTest, Tile)
+{
+ auto a = cudf::test::fixed_width_column_wrapper({-1, 0, 1});
+ cudf::table_view in(std::vector{a});
+ cudf::tile(in, 2, cudf::test::get_default_stream());
+}
+
+TEST_F(ReshapeTest, ByteCast)
+{
+ auto a = cudf::test::fixed_width_column_wrapper({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());
+}