Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose stream-ordering in public transpose API #17294

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -749,6 +749,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()
Loading