cuda::experimental::shared_resource#
-
template<class _Resource>
struct shared_resource : public cuda::mr::__copy_default_queries<_Resource># Resource wrapper to share ownership of a resource#
shared_resourceholds a reference counted instance of a memory resource. This allows the user to pass a resource around with reference semantics while avoiding lifetime issues.@note
shared_resourcesatisfies thecuda::mr::resourceconcept iff tparam _Resource satisfies it. @tparam _Resource The resource type to hold.Public Functions
-
template<class ..._Args>
inline explicit shared_resource(
)# Constructs a
shared_resourcereferring to an object of type_Resourcethat has been constructed with arguments__args.The
_Resourceobject is dynamically allocated withnew.- Parameters:
__args – The arguments to be passed to the
_Resourceconstructor.
-
inline shared_resource(const shared_resource &__other) noexcept#
Copy-constructs a
shared_resourceobject resulting in an copy that shares ownership of the wrapped resource with__other.- Parameters:
__other – The
shared_resourceobject to copy from.
-
inline shared_resource(shared_resource &&__other) noexcept#
Move-constructs a
shared_resourceassuming ownership of the resource stored in__other.- Parameters:
__other – The
shared_resourceobject to move from.- Post:
__otheris left in a valid but unspecified state.
-
inline ~shared_resource()#
Releases the reference held by this
shared_resourceobject.If this is the last reference to the wrapped resource, the resource is deleted.
- inline shared_resource &operator=(
- const shared_resource &__other,
Copy-assigns from
__other.Self-assignment is a no-op. Otherwise, the reference held by this
shared_resourceobject is released and a new reference is acquired to the wrapped resource of__other, if any.- Parameters:
__other – The
shared_resourceobject to copy from.
- inline shared_resource &operator=(
- shared_resource &&__other,
Move-assigns from
__other.Self-assignment is a no-op. Otherwise, the reference held by this
shared_resourceobject is released, while the reference held by__otheris transferred to this object.- Parameters:
__other – The
shared_resourceobject to move from.- Post:
__otheris left in a valid but unspecified state.
-
inline void swap(shared_resource &__other) noexcept#
Swaps a
shared_resourcewith another one.- Parameters:
__other – The other
shared_resource.
- inline void *allocate_sync(
- size_t __bytes,
- size_t __alignment = alignof(::cuda::std::max_align_t),
Allocate memory of size at least
__bytesusing the stored resource.- Parameters:
__bytes – The size in bytes of the allocation.
__alignment – The requested alignment of the allocation.
- Returns:
Pointer to the newly allocated memory
- inline void deallocate_sync(
- void *__ptr,
- size_t __bytes,
- size_t __alignment = alignof(::cuda::std::max_align_t),
Deallocate memory pointed to by
__ptrusing the stored resource.- Parameters:
__ptr – Pointer to be deallocated. Must have been allocated through a call to
allocateorallocate_sync__bytes – The number of bytes that was passed to the allocation call that returned
__ptr.__alignment – The alignment that was passed to the allocation call that returned
__ptr.
-
template<class _ThisResource = _Resource, ::cuda::std::enable_if_t<::cuda::mr::resource<_ThisResource>, int> = 0>
inline void *allocate( - ::cuda::stream_ref __stream,
- size_t __bytes,
- size_t __alignment,
Enqueues an allocation of memory of size at least
__bytesusing the wrapped resource.The allocation is performed asynchronously on stream
__stream.Note
The caller is responsible for ensuring that the memory is not accessed until the operation has completed.
- Parameters:
__bytes – The size in bytes of the allocation.
__alignment – The requested alignment of the allocation.
- Pre:
_Resourcemust satisfyresource.- Returns:
Pointer to the newly allocated memory.
-
template<class _ThisResource = _Resource, ::cuda::std::enable_if_t<::cuda::mr::resource<_ThisResource>, int> = 0>
inline void deallocate( - ::cuda::stream_ref __stream,
- void *__ptr,
- size_t __bytes,
- size_t __alignment,
Enqueues the deallocation of memory pointed to by
__ptr.The deallocation is performed asynchronously on stream
__stream.Note
The caller is responsible for ensuring that the memory is not accessed after the operation has completed.
- Parameters:
__ptr – Pointer to be deallocated. Must have been allocated through a call to
allocateorallocate_sync__bytes – The number of bytes that was passed to the allocation call that returned
__ptr.__alignment – The alignment that was passed to the allocation call that returned
__ptr.
- Pre:
_Resourcemust satisfyresource.
Friends
- inline friend void swap(
- shared_resource &__left,
- shared_resource &__right,
Swaps a
shared_resourcewith another one.- Parameters:
__other – The other
shared_resource.
- inline friend bool operator==(
- const shared_resource &__lhs,
- const shared_resource &__rhs,
Equality comparison between two
shared_resource.- Parameters:
__lhs – The first
shared_resource__rhs – The other
shared_resource
- Returns:
Checks whether the objects refer to resources that compare equal.
- inline friend bool operator!=(
- const shared_resource &__lhs,
- const shared_resource &__rhs,
Equality comparison between two
shared_resource.- Parameters:
__lhs – The first
shared_resource__rhs – The other
shared_resource
- Returns:
Checks whether the objects refer to resources that compare unequal.
-
template<class ..._Args>