cuda::experimental::uninitialized_async_buffer

Defined in /home/runner/work/cccl/cccl/cudax/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 resposibility 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 value_type = _Tp
using reference = _Tp&
using pointer = _Tp*
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 using __mr.

Note

Depending on the alignment requirements of T the size of the underlying allocation might be larger than count * 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 construction.

Parameters

__other – Another uninitialized_async_buffer

inline uninitialized_async_buffer &operator=(uninitialized_async_buffer &&__other) noexcept

Move assignment.

Parameters

__other – Another uninitialized_async_buffer

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() const noexcept

Returns an aligned pointer to the buffer.

inline constexpr pointer end() const 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 pointer data() const noexcept

Returns an aligned pointer to the buffer.

inline constexpr size_t size() const noexcept

Returns the size of the buffer.

inline const __async_resource &get_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 ::cuda::stream_ref get_stream() const noexcept

Returns the stored stream.

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 swap(uninitialized_async_buffer &__other) noexcept

Swaps the contents with those of another uninitialized_async_buffer.

Parameters

__other – The other uninitialized_async_buffer.