Skip to content

Commit

Permalink
Expose stream-ordering in public transpose API (#17294)
Browse files Browse the repository at this point in the history
Adds stream parameter to `cudf::transpose`.
Verifies correct stream forwarding with stream gtests.

Reference: #13744

Authors:
  - Shruti Shivakumar (https://github.com/shrshi)

Approvers:
  - Nghia Truong (https://github.com/ttnghia)
  - David Wendt (https://github.com/davidwendt)

URL: #17294
  • Loading branch information
shrshi authored Nov 13, 2024
1 parent 76a5e32 commit f5c0e5c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
12 changes: 7 additions & 5 deletions cpp/include/cudf/transpose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ namespace CUDF_EXPORT cudf {
* @throw cudf::logic_error if column types are non-homogeneous
* @throw cudf::logic_error if column types are non-fixed-width
*
* @param[in] input A table (M cols x N rows) to be transposed
* @param[in] mr Device memory resource used to allocate the device memory of returned value
* @return The transposed input (N cols x M rows) as a `column` and
* `table_view`, representing the owner and transposed table,
* respectively.
* @param[in] input A table (M cols x N rows) to be transposed
* @param[in] stream CUDA stream used for device memory operations and kernel launches
* @param[in] mr Device memory resource used to allocate the device memory of returned value
* @return The transposed input (N cols x M rows) as a `column` and
* `table_view`, representing the owner and transposed table,
* respectively.
*/
std::pair<std::unique_ptr<column>, table_view> transpose(
table_view const& input,
rmm::cuda_stream_view stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());

/** @} */ // end of group
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/transpose/transpose.cu
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ std::pair<std::unique_ptr<column>, table_view> transpose(table_view const& input
} // namespace detail

std::pair<std::unique_ptr<column>, table_view> transpose(table_view const& input,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::transpose(input, cudf::get_default_stream(), mr);
return detail::transpose(input, 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 @@ -750,6 +750,7 @@ ConfigureTest(
testing
)
ConfigureTest(STREAM_TRANSFORM_TEST streams/transform_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_TRANSPOSE_TEST streams/transpose_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_UNARY_TEST streams/unary_test.cpp STREAM_MODE testing)

# ##################################################################################################
Expand Down
67 changes: 67 additions & 0 deletions cpp/tests/streams/transpose_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 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_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/transpose.hpp>

#include <algorithm>
#include <random>
#include <string>

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

TEST_F(TransposeTest, StringTest)
{
using ColumnWrapper = cudf::test::strings_column_wrapper;
size_t ncols = 10;
size_t nrows = 10;

std::mt19937 rng(1);

auto const values = [&rng, nrows, ncols]() {
std::vector<std::vector<std::string>> values(ncols);
std::for_each(values.begin(), values.end(), [&rng, nrows](std::vector<std::string>& col) {
col.resize(nrows);
std::generate(col.begin(), col.end(), [&rng]() { return std::to_string(rng()); });
});
return values;
}();

auto input_cols = [&values]() {
std::vector<ColumnWrapper> columns;
columns.reserve(values.size());
for (auto const& value_col : values) {
columns.emplace_back(value_col.begin(), value_col.end());
}
return columns;
}();

auto input_view = [&input_cols]() {
std::vector<cudf::column_view> views(input_cols.size());
std::transform(input_cols.begin(), input_cols.end(), views.begin(), [](auto const& col) {
return static_cast<cudf::column_view>(col);
});
return cudf::table_view(views);
}();

auto result = transpose(input_view, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()

0 comments on commit f5c0e5c

Please sign in to comment.