cuda::experimental::basic_resource_ref

Defined in include/cuda/experimental/__memory_resource/any_resource.cuh

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

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

Pre

If _Kind is _ResourceKind::_Asynchronous, async_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

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

Pre

If _Kind is _ResourceKind::_Asynchronous, async_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(size_t __size, size_t __align = alignof(cuda::std::max_align_t))

Calls allocate on the wrapped reference with the specified arguments.

Returns

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

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

Calls deallocate 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(__pv, __size, __align), where obj is the wrapped reference.

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

Calls allocate_async 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_async(__size, __align, __stream), where obj is the wrapped reference.

void *allocate_async(size_t __size, cuda::stream_ref __stream)

Equivalent to allocate_async(__size, alignof(_CUDA_VSTD::max_align_t), __stream).

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

Calls deallocate_async 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_async on the object referenced by *this.

Returns

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

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

Equivalent to deallocate_async(__pv, __size, alignof(_CUDA_VSTD::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.

template<class _Property>
decltype(auto) friend 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.

Friends

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_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.