cuda::experimental::basic_resource_ref#

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

Type erased wrapper around a reference to an object that satisfies the resource concept and that provides the requested _Properties.

basic_resource_ref models the cuda::std::copyable and cuda::std::equality_comparable concepts.

Template Parameters:

_Properties – The properties that any resource wrapped within the basic_resource_ref needs to provide.

Public Functions

basic_resource_ref(const basic_resource_ref &__other)#

Copy constructs a basic_resource_ref.

Post:

*this and __other both refer to the same resource object.

template<class _Resource>
basic_resource_ref(_Resource &__res)#

Constructs a basic_resource_ref from a reference to a type that satisfies the resource concept and that supports all of the specified properties.

Parameters:

__res – The resource reference to be wrapped.

Pre:

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

Pre:

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

Pre:

If __res refers to a specialization of basic_any_resource or a type derived from such, __res.has_value() is true.

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

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

Parameters:

__res – The other 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:

*this and __res both refer to the same resource object.

basic_resource_ref &operator=(const basic_resource_ref &__other)#

Rebinds *this to refer to the object to which __other refers.

Post:

*this and __other both refer to the same resource object.

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

Rebinds the wrapped reference to an object whose type satisfies the resource concept and that supports all of the specified properties.

Parameters:

__res – The reference to the resource to be wrapped by the basic_resource_ref.

Pre:

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

Pre:

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

Pre:

If __res refers to a specialization of basic_any_resource or a type derived from such, __res.has_value() is true.

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

Rebinds *this to refer to the object to which __other refers.

Parameters:

__res – The other 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:

*this and __res both refer to the same resource object.

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

Equality comparison between two type-erased resource references.

Parameters:

__rhs – The other type-erased resource reference.

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 refer to objects of the same type and those objects compare equal. Otherwise, returns false.

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

Calls allocate_sync on the wrapped reference with the specified arguments.

Returns:

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

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

Calls deallocate_sync on the wrapped reference with the specified arguments.

Pre:

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

Returns:

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

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

Calls allocate on the wrapped reference with the specified arguments.

Warning

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

Pre:

_Kind is _ResourceKind::_Asynchronous.

Returns:

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

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 reference with the specified arguments.

Pre:

_Kind is _ResourceKind::_Asynchronous.

Pre:

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

Returns:

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

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

Equivalent to

deallocate(__stream, __pv, __size,

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

.

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

A reference to the type_info object for the type of the object to which *this refers.

Friends

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

Forwards a property query to the type-erased reference.

Template Parameters:

_Property

Parameters:
Pre:

_Property is a type in _Properties....

Returns:

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

template<class _Property>
friend auto try_get_property(
const basic_resource_ref &__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:
  • __res – The any_synchronous_resource object

  • __prop – The property to query

Pre:

has_value() is true.

Returns:

Let:

  • obj be the wrapped reference.

  • 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 wrapper type that first type-erased obj. [Note: _OtherProperties is different than _Properties when *this is the result of an interface-narrowing conversion. &#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.