cuda::experimental::basic_any_resource#

template<_ResourceKind _Kind, class ..._Properties>
class basic_any_resource#

Type erased wrapper around a resource or a synchronous_resource#

basic_any_resource wraps any given resource that satisfies the required properties. It owns the contained resource, taking care of construction / destruction. This makes it especially suited for use in e.g. container types that need to ensure that the lifetime of the container exceeds the lifetime of the memory resource used to allocate the storage

basic_any_resource models the cuda::std::regular concept.

See also

any_resource

See also

resource_ref

Template Parameters:
  • _Kind – Either _ResourceKind::_Synchronous for any_synchronous_resource, or _ResourceKind::_Asynchronous for any_resource.

  • _Properties – A pack of property types that a memory resource must provide in order to be storable in instances of this basic_any_resource type.

Public Functions

basic_any_resource() noexcept#

Constructs a basic_any_resource with no value.

Post:

has_value() is false

basic_any_resource(basic_any_resource &&__other) noexcept#

Move constructs a basic_any_resource.

Post:

has_value() is true if __other had a value prior to the move, and false otherwise. __other.has_value() is false.

basic_any_resource(const basic_any_resource &__other)#

Copy constructs a basic_any_resource.

Post:

has_value() is the same as __other.has_value().

template<class _Resource>
basic_any_resource(_Resource __res)#

Constructs a basic_any_resource from a type that satisfies the resource concept.

and that supports all of the specified properties.

Parameters:

__res – The resource to be wrapped by the basic_any_resource.

Pre:

_Resource is not a specialization of basic_any_resource or basic_resource_ref, or a type derived from such.

Pre:

synchronous_resource_with<_Resource, _Properties...> is true.

Pre:

If _Kind is _ResourceKind::_Asynchronous, resource_with<_Resource, _Properties...> is true.

Post:

has_value() is true

template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource(
basic_any_resource<_OtherKind, _OtherProperties...> __res,
)#

Conversion from a type-erased resource with a superset of the required properties.

Parameters:

__res – The object to copy from.

Pre:

_OtherKind is equal to either _Kind or _ResourceKind::_Asynchronous.

Pre:

The set _OtherProperties... is a superset of _Properties....

Post:

has_value() is equal to __res.has_value()

template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource(
basic_resource_ref<_OtherKind, _OtherProperties...> __res,
)#

Deep copy from a type-erased resource reference with a superset of the required properties.

The object to which __res refers is copied into *this.

Parameters:

__res – The reference to copy from.

Pre:

_OtherKind is equal to either _Kind or _ResourceKind::_Asynchronous.

Pre:

The set _OtherProperties... is a superset of _Properties....

basic_any_resource &operator=(basic_any_resource &&__other) noexcept#

Move assigns a basic_any_resource.

Post:

has_value() is true if __other had a value prior to the move, and false otherwise.

Post:

__other.has_value() is false.

basic_any_resource &operator=(const basic_any_resource &__other)#

Copy assigns a basic_any_resource.

Post:

has_value() is the same as __other.has_value().

template<class _Resource>
basic_any_resource &operator=(
_Resource __res,
)#

Assigns from a type that satisfies the resource concept and that supports all of the specified properties.

Parameters:

__res – The resource to be wrapped within the basic_any_resource

Pre:

_Resource is not a specialization of basic_any_resource or basic_resource_ref, or a type derived from such.

Pre:

synchronous_resource_with<_Resource, _Properties...> is true.

Pre:

If _Kind is _ResourceKind::_Asynchronous, resource_with<_Resource, _Properties...> is true.

Post:

has_value() is true

template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource &operator=(
basic_any_resource<_OtherKind, _OtherProperties...> __res,
)#

Assignment from a type-erased resource with a superset of the required properties.

Parameters:

__res – The object to copy from.

Pre:

_OtherKind is equal to either _Kind or _ResourceKind::_Asynchronous.

Pre:

The set _OtherProperties... is a superset of _Properties....

Post:

has_value() is equal to __res.has_value().

template<_ResourceKind _OtherKind, class ..._OtherProperties>
basic_any_resource &operator=(
basic_resource_ref<_OtherKind, _OtherProperties...> __res,
)#

Deep copy from a type-erased resource reference with a superset of the required properties.

Parameters:

__res – The type-erased resource reference to copy from.

Pre:

_OtherKind is equal to either _Kind or _ResourceKind::_Asynchronous.

Pre:

The set _OtherProperties... is a superset of _Properties....

Post:

has_value() is true.

template<_ResourceKind _OtherKind, class ..._OtherProperties>
bool operator==(
const basic_any_resource<_OtherKind, _OtherProperties...> &__rhs,
) const#

Equality comparison between two type-erased memory resource.

Parameters:

__rhs – The type-erased resource to compare with *this.

Pre:

_OtherKind is equal to either _Kind or _ResourceKind::_Asynchronous.

Pre:

The set _Properties... is equal to the set _OtherProperties....

Returns:

true if both resources hold objects of the same type and those objects compare equal, and false otherwise.

template<_ResourceKind _OtherKind, class ..._OtherProperties>
bool operator==(
const basic_resource_ref<_OtherKind, _OtherProperties...> &__rhs,
) const#

Equality comparison between *this and a type-erased resource reference.

Parameters:

__rhs – The type-erased resource reference to compare with *this.

Pre:

_OtherKind is equal to either _Kind or _ResourceKind::_Asynchronous.

Pre:

The set _Properties... is equal to the set _OtherProperties....

Returns:

true if __rhs refers to an object of the same type as that wrapped by *this and those objects compare equal; false otherwise.

void *allocate_sync(
size_t __size,
size_t __align = alignof(cuda::std::max_align_t),
)#

Calls allocate_sync on the wrapped object with the specified arguments.

Pre:

has_value() is true.

Returns:

obj.allocate_sync(__size, __align), where obj is the wrapped object.

void deallocate_sync(
void *__pv,
size_t __size,
size_t __align = alignof(cuda::std::max_align_t),
)#

Calls deallocate_sync on the wrapped object with the specified arguments.

Pre:

has_value() is true.

Pre:

__pv must be a pointer that was previously returned by a call to allocate on the object wrapped by *this.

Returns:

obj.deallocate_sync(__pv, __size, __align), where obj is the wrapped object.

void *allocate(
cuda::stream_ref __stream,
size_t __size,
size_t __align,
)#

Calls allocate on the wrapped object with the specified arguments.

Warning

The returned pointer is not valid until __stream has been synchronized.

Pre:

_Kind is _ResourceKind::_Asynchronous.

Pre:

has_value() is true.

Returns:

obj.allocate(__stream, __size, __align), where obj is the wrapped object.

void *allocate(cuda::stream_ref __stream, size_t __size)#

Equivalent to

allocate(__stream, __size,

alignof(::cuda::std::max_align_t))

.

void deallocate(
cuda::stream_ref __stream,
void *__pv,
size_t __size,
size_t __align,
)#

Calls deallocate on the wrapped object with the specified arguments.

Pre:

_Kind is _ResourceKind::_Asynchronous.

Pre:

has_value() is true.

Pre:

__pv must be a pointer that was previously returned by a call to allocate on the object wrapped by *this.

Returns:

obj.deallocate(__stream, __pv, __size, __align), where obj is the wrapped object.

void deallocate(cuda::stream_ref __stream, void *__pv, size_t __size)#

Equivalent to

deallocate(__stream, __pv, __size,

alignof(::cuda::std::max_align_t), __stream)

.

bool has_value() const noexcept#

Checks if *this holds a value.

Returns:

true if *this holds a value; false otherwise.

void reset() noexcept#

Resets *this to the empty state.

Post:

has_value() == false

const cuda::std::type_info &type() const noexcept#
Returns:

A reference to the type_info object for the wrapped resource, or typeid(void) if has_value() is false.

Friends

template<class _Property>
friend decltype(auto) get_property(
const basic_any_resource &__res,
_Property __prop,
) noexcept#

Forwards a property query to the type-erased object.

Parameters:
Pre:

The type _Property is one of the types in the pack _Properties....

Returns:

The result of calling get_property(__obj, __prop), where __obj is the type-erased object stored in __res.

template<class _Property>
friend auto try_get_property(
const basic_any_resource &__res,
_Property __prop,
) noexcept#

Attempts to forward a property query to the type-erased object and returns a _boolean-testable_ object that contains the result, if any.

Template Parameters:

_Property

Parameters:
Pre:

has_value() is true.

Returns:

Let:

  • obj be the wrapped object.

  • ValueType be the associated value type of __prop.

  • ReturnType be bool if ValueType is void. Otherwise, ReturnType is cuda::std::optional<ValueType>.

  • _OtherProperties be the pack of type parameters of the basic_any_resource object that first type-erased obj. [Note: _OtherProperties is different than _Properties when *this is the result of a conversion from a different __basic_any type. &#8212; end note]

try_get_property(__res, __prop) has type ReturnType. If _Property is not in the pack _OtherProperties, returns ReturnType(). Otherwise:
  • Returns true if ValueType is void.

  • Returns ReturnType(get_property(obj, __prop)) otherwise.