cuda::experimental::async_buffer
Defined in include/cuda/experimental/__container/async_buffer.cuh
-
template<class _Tp, class ..._Properties>
class async_buffer async_buffer
async_buffer
is a container that provides resizable typed storage allocated from a given memory resource. It handles alignment, release and growth of the allocation. The elements are initialized during construction, which may require a kernel launch.In addition to being type-safe,
async_buffer
also takes a set of properties to ensure that e.g. execution space constraints are checked at compile time. However, only stateless properties can be forwarded. To use a stateful property, implement get_property(const async_buffer&, Property).- Template Parameters
_Tp – the type to be stored in the buffer
_Properties... – The properties the allocated memory satisfies
Public Types
-
using iterator = heterogeneous_iterator<_Tp, _Properties...>
-
using const_iterator = heterogeneous_iterator<const _Tp, _Properties...>
-
using const_reverse_iterator = cuda::std::reverse_iterator<const_iterator>
Public Functions
-
inline async_buffer(const async_buffer &__other)
Copy-constructs from a async_buffer.
- Parameters
__other – The other async_buffer.
-
inline async_buffer(async_buffer &&__other) noexcept
Move-constructs from a async_buffer.
- Parameters
__other – The other async_buffer.
-
template<class ..._OtherProperties, ::cuda::std::enable_if_t<__properties_match<_OtherProperties...>, int> = 0>
inline explicit async_buffer(const async_buffer<_Tp, _OtherProperties...> &__other) Copy-constructs from a async_buffer with matching properties.
- Parameters
__other – The other async_buffer.
-
template<class ..._OtherProperties, ::cuda::std::enable_if_t<__properties_match<_OtherProperties...>, int> = 0>
inline explicit async_buffer(async_buffer<_Tp, _OtherProperties...> &&__other) noexcept Move-constructs from a async_buffer with matching properties.
- Parameters
__other – The other async_buffer.
-
inline async_buffer(const __env_t &__env)
Constructs an empty async_buffer using an environment.
Note
No memory is allocated.
- Parameters
__env – The environment providing the needed information
-
inline explicit async_buffer(const __env_t &__env, const size_type __size)
Constructs a async_buffer of size
__size
using a memory resource and value-initializes__size
elements.Note
If
__size == 0
then no memory is allocated.- Parameters
__env – The environment used to query the memory resource.
__size – The size of the async_buffer. Defaults to zero
-
inline explicit async_buffer(const __env_t &__env, const size_type __size, const _Tp &__value)
Constructs a async_buffer of size
__size
using a memory resource and copy-constructs__size
elements from__value
.Note
If
__size == 0
then no memory is allocated.- Parameters
__env – The environment used to query the memory resource.
__size – The size of the async_buffer.
__value – The value all elements are copied from.
-
inline explicit async_buffer(const __env_t &__env, const size_type __size, ::cuda::experimental::uninit_t)
Constructs a async_buffer of size
__size
using a memory and leaves all elements uninitialized.Warning
This constructor does NOT initialize any elements. It is the user’s responsibility to ensure that the elements within
[vec.begin(), vec.end())
are properly initialized, e.g withcuda::std::uninitialized_copy
. At the destruction of theasync_buffer
all elements in the range[vec.begin(), vec.end())
will be destroyed.- Parameters
__env – The environment used to query the memory resource.
__size – The size of the async_buffer.
-
template<class _Iter, ::cuda::std::enable_if_t<cuda::std::__is_cpp17_forward_iterator<_Iter>::value, int> = 0>
inline async_buffer(const __env_t &__env, _Iter __first, _Iter __last) Constructs a async_buffer using a memory resource and copy-constructs all elements from the forward range
[__first, __last)
Note
If
__first == __last
then no memory is allocated- Parameters
__env – The environment used to query the memory resource.
__first – The start of the input sequence.
__last – The end of the input sequence.
-
inline async_buffer(const __env_t &__env, cuda::std::initializer_list<_Tp> __ilist)
Constructs a async_buffer using a memory resource and copy-constructs all elements from
__ilist
.Note
If
__ilist.size() == 0
then no memory is allocated- Parameters
__env – The environment used to query the memory resource.
__ilist – The initializer_list being copied into the async_buffer.
-
template<class _Range, ::cuda::std::enable_if_t<__compatible_range<_Range> && cuda::std::ranges::forward_range<_Range> && cuda::std::ranges::sized_range<_Range>, int> = 0>
inline async_buffer(const __env_t &__env, _Range &&__range) Constructs a async_buffer using a memory resource and an input range.
Note
If
__range.size() == 0
then no memory is allocated.- Parameters
__env – The environment used to query the memory resource.
__range – The input range to be moved into the async_buffer.
-
inline const_iterator begin() const noexcept
Returns an immutable iterator to the first element of the async_buffer. If the async_buffer is empty, the returned iterator will be equal to end().
-
inline const_iterator cbegin() const noexcept
Returns an immutable iterator to the first element of the async_buffer. If the async_buffer is empty, the returned iterator will be equal to end().
-
inline iterator end() noexcept
Returns an iterator to the element following the last element of the async_buffer. This element acts as a placeholder; attempting to access it results in undefined behavior.
-
inline const_iterator end() const noexcept
Returns an immutable iterator to the element following the last element of the async_buffer. This element acts as a placeholder; attempting to access it results in undefined behavior.
-
inline const_iterator cend() const noexcept
Returns an immutable iterator to the element following the last element of the async_buffer. This element acts as a placeholder; attempting to access it results in undefined behavior.
-
inline reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed async_buffer. It corresponds to the last element of the non-reversed async_buffer. If the async_buffer is empty, the returned iterator is equal to rend().
-
inline const_reverse_iterator rbegin() const noexcept
Returns an immutable reverse iterator to the first element of the reversed async_buffer. It corresponds to the last element of the non-reversed async_buffer. If the async_buffer is empty, the returned iterator is equal to rend().
-
inline const_reverse_iterator crbegin() const noexcept
Returns an immutable reverse iterator to the first element of the reversed async_buffer. It corresponds to the last element of the non-reversed async_buffer. If the async_buffer is empty, the returned iterator is equal to rend().
-
inline reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed async_buffer. It corresponds to the element preceding the first element of the non-reversed async_buffer. This element acts as a placeholder, attempting to access it results in undefined behavior.
-
inline const_reverse_iterator rend() const noexcept
Returns an immutable reverse iterator to the element following the last element of the reversed async_buffer. It corresponds to the element preceding the first element of the non-reversed async_buffer. This element acts as a placeholder, attempting to access it results in undefined behavior.
-
inline const_reverse_iterator crend() const noexcept
Returns an immutable reverse iterator to the element following the last element of the reversed async_buffer. It corresponds to the element preceding the first element of the non-reversed async_buffer. This element acts as a placeholder, attempting to access it results in undefined behavior.
-
inline pointer data() noexcept
Returns a pointer to the first element of the async_buffer. If the async_buffer has not allocated memory the pointer will be null.
-
inline const_pointer data() const noexcept
Returns a pointer to the first element of the async_buffer. If the async_buffer has not allocated memory the pointer will be null.
-
inline const_reference get(const size_type __n) const noexcept
Returns a reference to the
__n
‘th element of the async_vector.Note
Always synchronizes with the stored stream
- Parameters
__n – The index of the element we want to access
-
inline reference get_unsynchronized(const size_type __n) noexcept
Returns a reference to the
__n
‘th element of the async_vector.Note
Does not synchronize with the stored stream
- Parameters
__n – The index of the element we want to access
-
inline const_reference get_unsynchronized(const size_type __n) const noexcept
Returns a reference to the
__n
‘th element of the async_vector.Note
Does not synchronize with the stored stream
- Parameters
__n – The index of the element we want to access
-
inline bool empty() const noexcept
Returns true if the async_buffer is empty.
-
inline const __resource_t &get_memory_resource() const noexcept
Returns a c const reference to the any_resource that holds the memory resource used to allocate the async_buffer
-
inline constexpr void change_stream(::cuda::stream_ref __new_stream)
Replaces the stored stream.
Note
Always synchronizes with the old stream
- Parameters
__new_stream – the new stream
-
inline constexpr void change_stream_unsynchronized(::cuda::stream_ref __new_stream) noexcept
Replaces the stored stream.
Warning
This does not synchronize between
__new_stream
and the current stream. It is the user’s responsibility to ensure proper stream order going forward- Parameters
__new_stream – the new stream
-
inline constexpr __policy_t get_execution_policy() const noexcept
Returns the execution policy.
-
inline constexpr void set_execution_policy(__policy_t __new_policy) noexcept
Replaces the currently used execution policy.
- Parameters
__new_policy – the new policy
-
inline void wait() const
Waits on the currently stored stream.
-
template<class _Iter, ::cuda::std::enable_if_t<cuda::std::__is_cpp17_forward_iterator<_Iter>::value, int> = 0>
inline void assign(_Iter __first, _Iter __last) Replaces the content of the async_buffer with the sequence
[__first, __last)
Note
Neither frees not allocates memory if
__first == __last
.- Parameters
__first – Iterator to the first element of the input sequence.
__last – Iterator after the last element of the input sequence.
-
inline void assign(cuda::std::initializer_list<_Tp> __ilist)
Replaces the content of the async_buffer with the initializer_list
__ilist
.Note
Neither frees not allocates memory if
__ilist.size() == 0
.- Parameters
__ilist – The initializer_list to be copied into this async_buffer.
-
template<class _Range, ::cuda::std::enable_if_t<__compatible_range<_Range> && cuda::std::ranges::forward_range<_Range> && cuda::std::ranges::sized_range<_Range>, int> = 0>
inline void assign_range(_Range &&__range) Replaces the content of the async_buffer with the range
__range
.Note
Neither frees not allocates memory if
__range.size() == 0
.- Parameters
__range – The range to be copied into this async_buffer.
-
inline void swap(async_buffer &__other) noexcept
Swaps the contents of a async_buffer with those of
__other
.- Parameters
__other – The other async_buffer.
-
inline bool operator==(const async_buffer &__lhs, const async_buffer &__rhs)
Compares two async_buffers for equality.
- Parameters
__lhs – One async_buffer.
__rhs – The other async_buffer.
- Returns
true, if
__lhs
and__rhs
contain equal elements have the same size
Friends
- friend class async_buffer
-
inline friend void swap(async_buffer &__lhs, async_buffer &__rhs) noexcept
Swaps the contents of two async_buffers.
- Parameters
__lhs – One async_buffer.
__rhs – The other async_buffer.