-
Notifications
You must be signed in to change notification settings - Fork 1k
Use stream pool for gather/scatter. #14162
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION. | ||
| * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #pragma once | ||
|
|
@@ -10,6 +10,7 @@ | |
| #include <cudf/detail/utilities/assert.cuh> | ||
| #include <cudf/detail/utilities/cuda.cuh> | ||
| #include <cudf/detail/utilities/grid_1d.cuh> | ||
| #include <cudf/detail/utilities/stream_pool.hpp> | ||
| #include <cudf/detail/utilities/vector_factories.hpp> | ||
| #include <cudf/detail/valid_if.cuh> | ||
| #include <cudf/dictionary/dictionary_column_view.hpp> | ||
|
|
@@ -644,23 +645,33 @@ std::unique_ptr<table> gather(table_view const& source_table, | |
| rmm::cuda_stream_view stream, | ||
| rmm::device_async_resource_ref mr) | ||
| { | ||
| std::vector<std::unique_ptr<column>> destination_columns; | ||
|
|
||
| // TODO: Could be beneficial to use streams internally here | ||
|
|
||
| for (auto const& source_column : source_table) { | ||
| // The data gather for n columns will be put on the first n streams | ||
| destination_columns.push_back( | ||
| cudf::type_dispatcher<dispatch_storage_type>(source_column.type(), | ||
| column_gatherer{}, | ||
| source_column, | ||
| gather_map_begin, | ||
| gather_map_end, | ||
| bounds_policy == out_of_bounds_policy::NULLIFY, | ||
| stream, | ||
| mr)); | ||
| auto const num_columns = source_table.num_columns(); | ||
| auto result = std::vector<std::unique_ptr<column>>(num_columns); | ||
|
|
||
| // The data gather for n columns will be executed over n streams. If there is | ||
| // only a single column, the fork/join overhead should be avoided. | ||
| auto streams = std::vector<rmm::cuda_stream_view>{}; | ||
| if (num_columns > 1) { | ||
| streams = cudf::detail::fork_streams(stream, num_columns); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will emit a warning when there are more columns than streams in the pool. We can remove with warning; otherwise it's probably good to limit the number of streams to the pool size.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good/recommended number? And is it tuned by hand or automatically computed?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine to use all streams in the pool, I don't think we need to tune this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I knew we did round-robin, I did not know we issued a warning. I think removing the warning would be appropriate.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. opened #18236 |
||
| } else { | ||
| streams.push_back(stream); | ||
| } | ||
|
|
||
| auto it = thrust::make_counting_iterator<size_type>(0); | ||
|
|
||
| std::transform(it, it + num_columns, result.begin(), [&](size_type i) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thrust::tabulate saves a bit of code here |
||
| auto const& source_column = source_table.column(i); | ||
| return cudf::type_dispatcher<dispatch_storage_type>( | ||
| source_column.type(), | ||
| column_gatherer{}, | ||
| source_column, | ||
| gather_map_begin, | ||
| gather_map_end, | ||
| bounds_policy == out_of_bounds_policy::NULLIFY, | ||
| streams[i], | ||
| mr); | ||
| }); | ||
|
|
||
| auto needs_new_bitmask = bounds_policy == out_of_bounds_policy::NULLIFY || | ||
| cudf::has_nested_nullable_columns(source_table); | ||
| if (needs_new_bitmask) { | ||
|
|
@@ -669,15 +680,20 @@ std::unique_ptr<table> gather(table_view const& source_table, | |
| auto const op = bounds_policy == out_of_bounds_policy::NULLIFY | ||
| ? gather_bitmask_op::NULLIFY | ||
| : gather_bitmask_op::DONT_CHECK; | ||
| gather_bitmask(source_table, gather_map_begin, destination_columns, op, stream, mr); | ||
| gather_bitmask(source_table, gather_map_begin, result, op, stream, mr); | ||
| } else { | ||
| for (size_type i = 0; i < source_table.num_columns(); ++i) { | ||
| set_all_valid_null_masks(source_table.column(i), *destination_columns[i], stream, mr); | ||
| set_all_valid_null_masks(source_table.column(i), *result[i], streams[i], mr); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return std::make_unique<table>(std::move(destination_columns)); | ||
| // Join streams as late as possible so that null mask computations can run on | ||
| // the passed in stream while other streams are gathering. Skip joining if | ||
| // only one column, since it used the passed in stream rather than forking. | ||
| if (num_columns > 1) { cudf::detail::join_streams(streams, stream); } | ||
|
|
||
| return std::make_unique<table>(std::move(result)); | ||
| } | ||
|
|
||
| } // namespace detail | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious how this works for per-thread default stream. For spark, we build cuDF with PTDS. Will
streamswill be have number-of-columns vector of the PTDS stream?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
streampassed in would be the PTDS stream. Then a stream pool (for that thread) would be created (or reused), the work would be executed across that stream pool, and then thejoinstep would insert events for all the elements ofstreamsto be synchronized withstreambefore new work onstream(the PTDS stream in Spark's case) would be runnable.