Repository navigation
Replace OwningResourceAdaptor with a BackRef mixin
#1078
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8436a9e
adding backref mixin
nirandaperera e7ce92b
adding regression test
nirandaperera 4d2927d
adding host and pinned mr
nirandaperera 635af95
addressing comments
nirandaperera 108a438
remove redundant test
nirandaperera 17d1661
Update cpp/include/rapidsmpf/memory/host_memory_resource.hpp
nirandaperera b3fdccc
Merge branch 'main' into back-ref-mixin
nirandaperera 02a0c7f
Merge branch 'main' of github.com:rapidsai/rapidsmpf into back-ref-mixin
nirandaperera 87ab792
forcing empty backref to throw
nirandaperera 9003c17
remove promote
nirandaperera 8fd289d
remove backref from host and pinned MRs
nirandaperera ef65d8d
Merge branch 'main' of github.com:rapidsai/rapidsmpf into back-ref-mixin
nirandaperera 53d3298
disabling BUILD_CUDF_TESTS
nirandaperera 767adc7
Merge branch 'main' of github.com:rapidsai/rapidsmpf into back-ref-mixin
nirandaperera bb3bed5
merge conflict
nirandaperera 115e382
fix rmmresourceadapter python bindings
nirandaperera 18ea832
doc fix
nirandaperera 8854f0e
remove todo
nirandaperera e29e554
Merge branch 'main' of github.com:rapidsai/rapidsmpf into back-ref-mixin
nirandaperera 868f461
making RmmResourceAdapter ctr private
nirandaperera c07ec54
Merge branch 'main' of github.com:rapidsai/rapidsmpf into back-ref-mixin
nirandaperera e063eb6
addressing comments
nirandaperera 61db59d
Merge branch 'main' of github.com:rapidsai/rapidsmpf into back-ref-mixin
nirandaperera 752257b
Merge branch 'main' of github.com:rapidsai/rapidsmpf into back-ref-mixin
nirandaperera 6b14fba
Merge branch 'main' into back-ref-mixin
nirandaperera 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 hidden or 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 hidden or 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,125 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| #include <rapidsmpf/error.hpp> | ||
| #include <rapidsmpf/utils/misc.hpp> | ||
|
|
||
| namespace rapidsmpf { | ||
|
|
||
| /** | ||
| * @brief Mixin that lets copies of the this object keep an external object reference of | ||
| * type @p BackRef alive. | ||
| * | ||
| * @note Copying an instance without calling `set_backref()` throws `std::bad_weak_ptr`. | ||
| * | ||
| * @tparam BackRef Type of the external object reference. | ||
| */ | ||
| template <typename BackRef> | ||
| class BackRefMixin { | ||
| public: | ||
| /// @brief Construct a mixin with no installed back-reference. | ||
| BackRefMixin() noexcept = default; | ||
|
|
||
| /** | ||
| * @brief Acquire shared ownership of @p other's back-referenced owner. | ||
| * | ||
| * After construction, *this* references the same owner as @p other and | ||
| * keeps it alive for as long as *this* lives. | ||
| * | ||
| * @param other Mixin to copy from. | ||
| * @throws std::bad_weak_ptr if @p other is uninstalled, or is installed | ||
| * but its owner has been destroyed. | ||
| */ | ||
| BackRefMixin(BackRefMixin const& other) | ||
| : weak_{other.weak_}, | ||
| strong_{other.strong_ ? other.strong_ : std::shared_ptr<BackRef>{other.weak_}} { | ||
| } | ||
|
|
||
| /** | ||
| * @brief Copy assignment with the same semantics as the copy constructor. | ||
| * | ||
| * If the assignment throws, *this* is left unchanged. | ||
| * | ||
| * @param other Mixin to copy from. | ||
| * @return Reference to this. | ||
| * @throws std::bad_weak_ptr if @p other is uninstalled, or is installed | ||
| * but its owner has been destroyed. | ||
| */ | ||
| BackRefMixin& operator=(BackRefMixin const& other) { | ||
| if (this != &other) { | ||
| // Promote first so a throw leaves *this unchanged. | ||
| auto promoted = | ||
| other.strong_ ? other.strong_ : std::shared_ptr<BackRef>{other.weak_}; | ||
| weak_ = other.weak_; | ||
| strong_ = std::move(promoted); | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| /// @brief Move constructor. | ||
| BackRefMixin(BackRefMixin&&) noexcept = default; | ||
|
|
||
| /** | ||
| * @brief Move assignment operator. | ||
| * @return Reference to this mixin. | ||
| */ | ||
| BackRefMixin& operator=(BackRefMixin&&) noexcept = default; | ||
|
|
||
| ~BackRefMixin() = default; | ||
|
|
||
| /** | ||
| * @brief Owner-based equality. | ||
| * | ||
| * @param other Mixin to compare against. | ||
| * @return `true` if both mixins reference the same back-referenced | ||
| * owner, or are both uninstalled. | ||
| */ | ||
| [[nodiscard]] bool operator==(BackRefMixin const& other) const noexcept { | ||
| return owner_equal(weak_, other.weak_); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Install a back-reference on this instance. | ||
| * | ||
| * After this call, every subsequent copy of *this* will hold shared | ||
| * ownership of @p backref's referent for the lifetime of the copy. | ||
| * | ||
| * Installation only affects *this* and copies made from it afterwards; | ||
| * copies that already exist are not retroactively back-referenced. To | ||
| * guarantee the back-reference is honored by every observable copy, | ||
| * install it before the host object becomes reachable to any code that | ||
| * may copy it. | ||
| * | ||
| * @param backref Non-empty weak reference to the back-referenced owner. | ||
| * @throws std::invalid_argument if @p backref is empty, or if a | ||
| * back-reference is already installed on this instance. | ||
| */ | ||
| void set_backref(std::weak_ptr<BackRef> backref) { | ||
| std::weak_ptr<BackRef> const empty_weak{}; | ||
| RAPIDSMPF_EXPECTS( | ||
| !owner_equal(backref, empty_weak), | ||
| "set_backref: backref must not be empty", | ||
| std::invalid_argument | ||
| ); | ||
| RAPIDSMPF_EXPECTS( | ||
| owner_equal(weak_, empty_weak), | ||
| "set_backref: backref is already set", | ||
| std::invalid_argument | ||
| ); | ||
| weak_ = std::move(backref); | ||
| strong_.reset(); | ||
| } | ||
|
|
||
| private: | ||
| std::weak_ptr<BackRef> weak_{}; | ||
| std::shared_ptr<BackRef> strong_{}; | ||
| }; | ||
|
|
||
| } // namespace rapidsmpf | ||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.