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 thecuda::std::copyable
andcuda::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 theresource
concept and that supports all of the specified properties.- Parameters
__res – The resource reference to be wrapped.
- Pre
resource_with<_Resource, _Properties...>
istrue
.- Pre
If
_Kind
is_ResourceKind::_Asynchronous
,async_resource_with<_Resource, _Properties...>
istrue
.- Pre
If
__res
refers to a specialization ofbasic_any_resource
or a type derived from such,__res.has_value()
istrue
.
-
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...>
istrue
.- Pre
If
_Kind
is_ResourceKind::_Asynchronous
,async_resource_with<_Resource, _Properties...>
istrue
.- Pre
If
__res
refers to a specialization ofbasic_any_resource
or a type derived from such,__res.has_value()
istrue
.
-
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, returnsfalse
.
-
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)
, whereobj
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 toallocate
on the object referenced by*this
.- Returns
obj.deallocate(__pv, __size, __align)
, whereobj
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)
, whereobj
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 toallocate_async
on the object referenced by*this
.- Returns
obj.deallocate_async(__pv, __size, __align, __stream)
, whereobj
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
__res – The
basic_resource_ref
object__prop – The property to query
- 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()
istrue
.- Returns
Let:
obj
be the wrapped reference.ValueType
be the associated value type of__prop
.ReturnType
bebool
ifValueType
isvoid
. Otherwise,ReturnType
iscuda::std::optional<ValueType>
._OtherProperties
be the pack of type parameters of the wrapper type that first type-erasedobj
. [Note:_OtherProperties
is different than_Properties
when*this
is the result of an interface-narrowing conversion. — end note]
try_get_property(__res, __prop)
has typeReturnType
. If_Property
is not in the pack_OtherProperties
, returnsReturnType()
. Otherwise:Returns
true
ifValueType
isvoid
.Returns
ReturnType(get_property(obj, __prop))
otherwise.