cuda::experimental::uninitialized_async_buffer
Defined in include/cuda/experimental/__container/uninitialized_async_buffer.cuh
-
template<class _Tp, class ..._Properties>
class uninitialized_async_buffer Uninitialized stream-ordered type-safe memory storage
uninitialized_async_buffer
provides a typed buffer allocated in stream order from a given async memory resource. It handles alignment and release of the allocation. The memory is uninitialized, so that a user needs to ensure elements are properly constructed.In addition to being type safe,
uninitialized_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 uninitialized_async_buffer&, Property).Warning
uninitialized_async_buffer
uses stream-ordered allocation. It is the user’s responsibility to ensure the lifetime of both the provided async resource and the stream exceed the lifetime of the buffer.- Template Parameters
_T – the type to be stored in the buffer
_Properties... – The properties the allocated memory satisfies
Public Types
-
using size_type = size_t
Public Functions
-
inline uninitialized_async_buffer(__async_resource __mr, const ::cuda::stream_ref __stream, const size_t __count)
Constructs an
uninitialized_async_buffer
, allocating sufficient storage for__count
elements through__mr
.Note
Depending on the alignment requirements of
T
the size of the underlying allocation might be larger thancount * sizeof(T)
. Only allocates memory when__count
> 0- Parameters
__mr – The async memory resource to allocate the buffer with.
__stream – The CUDA stream used for stream-ordered allocation.
__count – The desired size of the buffer.
-
uninitialized_async_buffer(const uninitialized_async_buffer&) = delete
-
uninitialized_async_buffer &operator=(const uninitialized_async_buffer&) = delete
-
inline uninitialized_async_buffer(uninitialized_async_buffer &&__other) noexcept
Move-constructs a
uninitialized_async_buffer
from__other
.- Parameters
__other – Another
uninitialized_async_buffer
Takes ownership of the allocation in__other
and resets it
-
template<class ..._OtherProperties, ::cuda::std::enable_if_t<__properties_match<_OtherProperties...>, int> = 0>
inline uninitialized_async_buffer(uninitialized_async_buffer<_Tp, _OtherProperties...> &&__other) noexcept Move-constructs a
uninitialized_async_buffer
from__other
.- Parameters
__other – Another
uninitialized_async_buffer
with matching properties Takes ownership of the allocation in__other
and resets it
-
inline uninitialized_async_buffer &operator=(uninitialized_async_buffer &&__other) noexcept
Move-assigns a
uninitialized_async_buffer
from__other
.- Parameters
__other – Another
uninitialized_async_buffer
Deallocates the current allocation and then takes ownership of the allocation in__other
and resets it
-
inline ~uninitialized_async_buffer()
Destroys an
uninitialized_async_buffer
and deallocates the buffer in stream order on the stream that was used to create the buffer.Warning
The destructor does not destroy any objects that may or may not reside within the buffer. It is the user’s responsibility to ensure that all objects within the buffer have been properly destroyed.
-
inline constexpr pointer begin() noexcept
Returns an aligned pointer to the first element in the buffer.
-
inline constexpr const_pointer begin() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline constexpr pointer end() noexcept
Returns an aligned pointer 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 constexpr const_pointer end() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline constexpr pointer data() noexcept
Returns an aligned pointer to the first element in the buffer.
-
inline constexpr const_pointer data() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline const __async_resource &get_memory_resource() const noexcept
Returns a c const reference to the any_async_resource that holds the memory resource used to allocate the 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