Add a strict Buffer Resource back-reference to Host and Pinned memory resources#1106
Open
nirandaperera wants to merge 1 commit into
Open
Add a strict Buffer Resource back-reference to Host and Pinned memory resources#1106nirandaperera wants to merge 1 commit into
nirandaperera wants to merge 1 commit into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
ebc6a70 to
ec86fe5
Compare
Signed-off-by: niranda perera <niranda.perera@gmail.com>
ec86fe5 to
2db591e
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
HostMemoryResourceandPinnedMemoryResourceare nowBufferResource-only resources that carry a strictBackRefMixin<BufferResource>back-reference. When a copy of one of these resources is made (e.g. when CCCL promoteshost_mr()/pinned_mr()into an owningcuda::mr::any_resourceinside aHostBuffer), the copy promotes the storedweak_ptrto ashared_ptr, keeping the owningBufferResourcealive for as long as any derived buffer lives. This closes a lifetime gap where aBuffercould outlive theBufferResourcethat produced its memory resource.The mixin is strict: copying an instance without an installed back-reference throws
std::bad_weak_ptr. To make that safe, these resources can no longer be constructed as standalone objects — they are created only byBufferResource, which installs the back-reference immediately after construction. This mirrors howRmmResourceAdaptoralready works on this branch.C++ changes
HostMemoryResource: inheritsBackRefMixin<BufferResource>; constructor is private withfriend class BufferResource. Equality remains stateless (always true) since instances are interchangeable and the back-reference is installed exactly once.PinnedMemoryResource: inheritsBackRefMixin<BufferResource>as a second base; constructor is private (friend class BufferResource). Themake_if_available/from_optionsfactories were removed so no back-reference-less instance can ever escape. Equality compares the shared pool state only.PinnedPoolProperties: gained anuma_idfield (defaults to the calling thread's NUMA node) so all pinned configuration flows as one struct. Added a free helperpinned_pool_properties_from_options(...).PinnedMemoryDisabled: newconstexpr std::nullopt_tsentinel used to disable pinned host memory (replaces the oldPinnedMemoryResource::Disabled).BufferResource::create()/from_options(): now takestd::optional<PinnedPoolProperties> pinned_pool_properties(defaultPinnedMemoryDisabled) instead of a pre-built resource. The pinned resource is constructed internally and the back-reference is installed onowning_mr_,host_mr_, andpinned_mr_beforecreate()returns.try_pinned_mr(): now returnsstd::optional<PinnedMemoryResource>(a back-referenced handle) so Python/Statistics get a concrete, lifetime-safe handle.Python changes
PinnedMemoryResource: now an opaque, non-constructible handle (__init__raisesTypeError); obtained viaBufferResource.pinned_mr.PinnedPoolProperties: new@dataclass(initial_pool_size,max_pool_size,numa_id) used to configure pinned memory.BufferResource(...): replaces the oldpinned_mr=argument withpinned_pool_properties: PinnedPoolProperties | None = None(Nonedisables pinned host memory).from_optionsderives this from the config options.Statistics.report(pinned_mr=...): unchanged signature; the handle is now sourced fromBufferResource.pinned_mr.Tests
HostMrKeepsBufferResourceAliveandPinnedMrKeepsBufferResourceAliveregression tests mirroringDeviceMrKeepsBufferResourceAlive.BufferResource(no standalone Host/Pinned MR construction); reworkedtest_host_buffer,test_config,test_memory_resources, andbench_memory_resources.test_config.pyto configure pinned memory viaBufferResourceand assert onBufferResource.pinned_mr.Breaking changes
HostMemoryResource/PinnedMemoryResourcecan no longer be constructed directly;PinnedMemoryResource::make_if_available/from_optionsand theDisabledsentinel are removed.BufferResource::create()takesPinnedPoolPropertiesinstead of aPinnedMemoryResource.PinnedMemoryResource(...)is no longer constructible; theBufferResource(pinned_mr=...)argument is replaced bypinned_pool_properties=.Depends on #1078
Closes #1070