cuda::experimental::buffer#
-
template<class _Tp, class ..._Properties>
class buffer# buffer#
bufferis 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,
bufferalso 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 buffer&, Property).- Template Parameters:
_Tp – the type to be stored in the buffer
_Properties... – The properties the allocated memory satisfies
Public Types
-
using iterator = ::cuda::heterogeneous_iterator<_Tp, _Properties...>#
-
using const_iterator = ::cuda::heterogeneous_iterator<const _Tp, _Properties...>#
-
using const_reverse_iterator = ::cuda::std::reverse_iterator<const_iterator>#
-
using size_type = ::cuda::std::size_t#
-
using difference_type = ::cuda::std::ptrdiff_t#
-
using properties_list = ::cuda::mr::properties_list<_Properties...>#
Public Functions
-
inline buffer(const buffer &__other)#
Copy-constructs from a buffer.
- Parameters:
__other – The other buffer.
-
inline buffer(buffer &&__other) noexcept#
Move-constructs from a buffer.
- Parameters:
__other – The other buffer. After move construction, the other buffer can only be assigned to or destroyed.
-
template<class ..._OtherProperties, ::cuda::std::enable_if_t<__properties_match<_OtherProperties...>, int> = 0>
inline explicit buffer( - const buffer<_Tp, _OtherProperties...> &__other,
Copy-constructs from a buffer with matching properties.
- Parameters:
__other – The other buffer.
-
template<class ..._OtherProperties, ::cuda::std::enable_if_t<__properties_match<_OtherProperties...>, int> = 0>
inline buffer( - buffer<_Tp, _OtherProperties...> &&__other,
Move-constructs from a buffer with matching properties.
- Parameters:
__other – The other buffer. After move construction, the other buffer can only be assigned to or destroyed.
-
template<class _Env = ::cuda::std::execution::env<>, ::cuda::std::enable_if_t<__buffer_compatible_env<_Env>, int> = 0>
inline buffer( - ::cuda::stream_ref __stream,
- __resource_t __resource,
- const _Env &__env = {},
Constructs an empty buffer using an environment.
Note
No memory is allocated.
- Parameters:
__env – The environment providing the needed information
-
template<class _Env = ::cuda::std::execution::env<>>
inline explicit buffer( - ::cuda::stream_ref __stream,
- __resource_t __resource,
- const size_type __size,
- ::cuda::experimental::no_init_t,
- const _Env &__env = {},
Constructs a buffer of size
__sizeusing 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 thebufferall 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 buffer.
-
template<class _Iter, class _Env = ::cuda::std::execution::env<>>
inline buffer( - ::cuda::stream_ref __stream,
- __resource_t __resource,
- _Iter __first,
- _Iter __last,
- const _Env &__env = {},
Constructs a buffer using a memory resource and copy-constructs all elements from the forward range
[__first, __last)Note
If
__first == __lastthen 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.
-
template<class _Env = ::cuda::std::execution::env<>>
inline buffer( - ::cuda::stream_ref __stream,
- __resource_t __resource,
- ::cuda::std::initializer_list<_Tp> __ilist,
- const _Env &__env = {},
Constructs a buffer using a memory resource and copy-constructs all elements from
__ilist.Note
If
__ilist.size() == 0then no memory is allocated- Parameters:
__env – The environment used to query the memory resource.
__ilist – The initializer_list being copied into the buffer.
-
template<class _Range, class _Env = ::cuda::std::execution::env<>>
inline buffer(
)# Constructs a buffer using a memory resource and an input range.
Note
If
__range.size() == 0then no memory is allocated.- Parameters:
__env – The environment used to query the memory resource.
__range – The input range to be moved into the buffer.
-
inline const_iterator begin() const noexcept#
Returns an immutable iterator to the first element of the buffer.
If the 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 buffer.
If the 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 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 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 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 buffer.
It corresponds to the last element of the non-reversed buffer. If the 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 buffer.
It corresponds to the last element of the non-reversed buffer. If the 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 buffer.
It corresponds to the last element of the non-reversed buffer. If the 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 buffer.
It corresponds to the element preceding the first element of the non-reversed 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 buffer.
It corresponds to the element preceding the first element of the non-reversed 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 buffer.
It corresponds to the element preceding the first element of the non-reversed 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 buffer.
If the 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 buffer.
If the buffer has not allocated memory the pointer will be null.
- inline const_reference get_unsynchronized(
- const size_type __n,
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 buffer is empty.
-
inline const __resource_t &memory_resource() const noexcept#
Returns a c const reference to the any_resource that holds the memory resource used to allocate the buffer
-
inline constexpr stream_ref stream() const noexcept#
Returns the stored stream.
Note
Stream used to allocate the buffer is initially stored in the buffer, but can be changed with
set_stream
-
inline constexpr void set_stream(stream_ref __new_stream)#
Replaces the stored stream.
Note
Always synchronizes with the old stream
- Parameters:
__new_stream – the new stream
-
inline void operator=(buffer &&__other)#
Move assignment operator.
- Parameters:
__other – The other buffer. After move assignment, the other buffer can only be assigned to or destroyed.
-
inline void swap(buffer &__other) noexcept#
Swaps the contents of a buffer with those of
__other.- Parameters:
__other – The other buffer.
-
inline void destroy(::cuda::stream_ref __stream)#
Destroys the buffer, deallocates the buffer and destroys the memory resource.
Warning
After this explicit destroy call, the buffer can only be assigned to or destroyed.
- Parameters:
__stream – The stream to deallocate the buffer on.
-
inline void destroy()#
Destroys the buffer, deallocates the buffer and destroys the memory resource.
Note
Uses the stored stream to deallocate the buffer, equivalent to calling buffer.destroy(buffer.stream())
Warning
After this explicit destroy call, the buffer can only be assigned to or destroyed.
Friends
- friend class buffer
-
inline friend void swap(buffer &__lhs, buffer &__rhs) noexcept#
Swaps the contents of two buffers.
- Parameters:
__lhs – One buffer.
__rhs – The other buffer.
-
template<class _DeviceAccessible = ::cuda::mr::device_accessible>
inline friend auto transform_device_argument( - ::cuda::stream_ref,
- buffer &__self,
Causes the buffer to be treated as a span when passed to cudax::launch.
- Pre:
The buffer must have the cuda::mr::device_accessible property.
requires (::cuda::std::__is_included_in_v<_DeviceAccessible, _Properties...>)
-
template<class _DeviceAccessible = ::cuda::mr::device_accessible>
inline friend auto transform_device_argument( - ::cuda::stream_ref,
- const buffer &__self,
Causes the buffer to be treated as a span when passed to cudax::launch.
- Pre:
The buffer must have the cuda::mr::device_accessible property.
requires (::cuda::std::__is_included_in_v<_DeviceAccessible, _Properties...>)