cuda::experimental::shared_resource#
-
template<class _Resource>
struct shared_resource : public cuda::experimental::__copy_default_queries<_Resource># Resource wrapper to share ownership of a resource#
shared_resource
holds 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_resource
satisfies thecuda::mr::resource
concept iff tparam _Resource satisfies it. @tparam _Resource The resource type to hold.Public Functions
-
template<class ..._Args>
inline explicit shared_resource(
)# Constructs a
shared_resource
referring to an object of type_Resource
that has been constructed with arguments__args
.The
_Resource
object is dynamically allocated withnew
.- Parameters:
__args – The arguments to be passed to the
_Resource
constructor.
-
inline shared_resource(const shared_resource &__other) noexcept#
Copy-constructs a
shared_resource
object resulting in an copy that shares ownership of the wrapped resource with__other
.- Parameters:
__other – The
shared_resource
object to copy from.
-
inline shared_resource(shared_resource &&__other) noexcept#
Move-constructs a
shared_resource
assuming ownership of the resource stored in__other
.- Parameters:
__other – The
shared_resource
object to move from.- Post:
__other
is left in a valid but unspecified state.
-
inline ~shared_resource()#
Releases the reference held by this
shared_resource
object.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_resource
object is released and a new reference is acquired to the wrapped resource of__other
, if any.- Parameters:
__other – The
shared_resource
object 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_resource
object is released, while the reference held by__other
is transferred to this object.- Parameters:
__other – The
shared_resource
object to move from.- Post:
__other
is left in a valid but unspecified state.
-
inline void swap(shared_resource &__other) noexcept#
Swaps a
shared_resource
with 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
__bytes
using 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
__ptr
using the stored resource.- Parameters:
__ptr – Pointer to be deallocated. Must have been allocated through a call to
allocate
orallocate_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
__bytes
using 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:
_Resource
must 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
allocate
orallocate_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:
_Resource
must satisfyresource
.
Friends
- inline friend void swap(
- shared_resource &__left,
- shared_resource &__right,
Swaps a
shared_resource
with 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>