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 the cuda::mr::resource concept iff tparam _Resource satisfies it. @tparam _Resource The resource type to hold.

Public Functions

template<class ..._Args>
inline explicit shared_resource(
::cuda::std::in_place_type_t<_Resource>,
_Args&&... __args,
)#

Constructs a shared_resource referring to an object of type _Resource that has been constructed with arguments __args.

The _Resource object is dynamically allocated with new.

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,
) noexcept#

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,
) noexcept#

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),
) noexcept#

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 or allocate_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 satisfy resource.

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 or allocate_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 satisfy resource.

Friends

inline friend void swap(
shared_resource &__left,
shared_resource &__right,
) noexcept#

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:
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:
Returns:

Checks whether the objects refer to resources that compare unequal.

template<class _Property, ::cuda::std::enable_if_t<(!property_with_value<_Property>) && (has_property<_Resource, _Property>), int> = 0>
inline friend void get_property(
const shared_resource&,
_Property,
) noexcept#

Forwards the stateless properties.

template<class _Property, ::cuda::std::enable_if_t<property_with_value<_Property>&&(has_property<_Resource, _Property>), int> = 0>
inline friend __property_value_t<_Property> get_property(
const shared_resource &__self,
_Property,
) noexcept#

Forwards the stateful properties.