-
Notifications
You must be signed in to change notification settings - Fork 913
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
Extend device_scalar
to optionally use pinned bounce buffer
#16947
Merged
rapids-bot
merged 33 commits into
rapidsai:branch-24.12
from
vuule:fea-pinned-aware-device_scalar
Oct 18, 2024
Merged
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e542de1
class with overridden value(); single use
vuule 0216948
Merge branch 'branch-24.12' of https://github.com/rapidsai/cudf into …
vuule b74a4d0
clean up + ctor
vuule b955404
stop using to_device
vuule 20633fe
use in cuIO
vuule fccd97d
rest of src
vuule ab18eb9
include
vuule a272fe7
initial impl
vuule 7c1c918
Merge branch 'branch-24.12' of https://github.com/rapidsai/cudf into …
vuule c0a2e71
rework API
vuule db97c3d
impl fix
vuule 80047eb
docs
vuule 6cf40b3
throw when mismatched sizes
vuule 7414926
Merge branch 'branch-24.12' into fea-host-device-copy
vuule 4957e27
Merge branch 'fea-host-device-copy' into fea-pinned-aware-device_scalar
vuule 5997049
Merge branch 'branch-24.12' of https://github.com/rapidsai/cudf into …
vuule 4030a89
fix
vuule 243e12e
bounce buffer
vuule 09b329a
Merge branch 'branch-24.12' into fea-pinned-aware-device_scalar
vuule 381a49a
style
vuule 7e9eb33
Merge branch 'fea-pinned-aware-device_scalar' of https://github.com/v…
vuule ac13130
Merge branch 'branch-24.12' of https://github.com/rapidsai/cudf into …
vuule a052495
style
vuule d584fcc
Merge branch 'branch-24.12' of https://github.com/rapidsai/cudf into …
vuule f6a9266
remove impl namespace
vuule d14f371
Merge branch 'fea-host-device-copy' into fea-pinned-aware-device_scalar
vuule 2056834
Merge branch 'branch-24.12' of https://github.com/rapidsai/cudf into …
vuule 931265b
fix minmax with move ctor definition
vuule e287b89
Merge branch 'branch-24.12' into fea-pinned-aware-device_scalar
vuule 2468636
Merge branch 'branch-24.12' into fea-pinned-aware-device_scalar
vyasr 483ce19
Merge branch 'branch-24.12' into fea-pinned-aware-device_scalar
vuule 80dc0e5
code review
vuule 3d63126
Merge branch 'branch-24.12' into fea-pinned-aware-device_scalar
vuule File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cudf/detail/utilities/cuda_memcpy.hpp> | ||
#include <cudf/detail/utilities/host_vector.hpp> | ||
#include <cudf/detail/utilities/vector_factories.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/device_scalar.hpp> | ||
#include <rmm/resource_ref.hpp> | ||
|
||
namespace CUDF_EXPORT cudf { | ||
namespace detail { | ||
|
||
template <typename T> | ||
class device_scalar : public rmm::device_scalar<T> { | ||
public: | ||
~device_scalar() = default; | ||
|
||
device_scalar(device_scalar&&) noexcept = default; | ||
device_scalar& operator=(device_scalar&&) noexcept = default; | ||
|
||
device_scalar(device_scalar const&) = delete; | ||
device_scalar& operator=(device_scalar const&) = delete; | ||
|
||
device_scalar() = delete; | ||
|
||
explicit device_scalar( | ||
rmm::cuda_stream_view stream, | ||
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref()) | ||
: rmm::device_scalar<T>(stream, mr), bounce_buffer{make_host_vector<T>(1, stream)} | ||
{ | ||
} | ||
|
||
explicit device_scalar( | ||
T const& initial_value, | ||
rmm::cuda_stream_view stream, | ||
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref()) | ||
: rmm::device_scalar<T>(stream, mr), bounce_buffer{make_host_vector<T>(1, stream)} | ||
{ | ||
bounce_buffer[0] = initial_value; | ||
cuda_memcpy_async<T>(device_span<T>{this->data(), 1}, bounce_buffer, stream); | ||
} | ||
|
||
device_scalar(device_scalar const& other, | ||
rmm::cuda_stream_view stream, | ||
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref()) | ||
: rmm::device_scalar<T>(other, stream, mr), bounce_buffer{make_host_vector<T>(1, stream)} | ||
{ | ||
} | ||
|
||
[[nodiscard]] T value(rmm::cuda_stream_view stream) const | ||
{ | ||
cuda_memcpy<T>(bounce_buffer, device_span<T const>{this->data(), 1}, stream); | ||
return bounce_buffer[0]; | ||
} | ||
|
||
void set_value_async(T const& value, rmm::cuda_stream_view stream) | ||
{ | ||
bounce_buffer[0] = value; | ||
cuda_memcpy_async<T>(device_span<T>{this->data(), 1}, bounce_buffer, stream); | ||
} | ||
|
||
void set_value_async(T&& value, rmm::cuda_stream_view stream) | ||
{ | ||
bounce_buffer[0] = std::move(value); | ||
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. bonus feature from having a bounce buffer - we don't need to worry about the |
||
cuda_memcpy_async<T>(device_span<T>{this->data(), 1}, bounce_buffer, stream); | ||
} | ||
|
||
void set_value_to_zero_async(rmm::cuda_stream_view stream) { set_value_async(T{}, stream); } | ||
|
||
private: | ||
mutable cudf::detail::host_vector<T> bounce_buffer; | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace CUDF_EXPORT cudf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Curious why the move ctor required code but this did not?
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.
Default implementations should be fine in both cases. Compiled fine on 12.5 🤷
I suspect it's an 11.8 compiler bug, but really didn't want to dig into it, with a handy workaround available.