Buffer representing device or host memory. More...
#include <buffer.hpp>
Public Types | |
| using | DeviceStorageT = std::unique_ptr< rmm::device_buffer > |
| Storage type for the device buffer. | |
| using | HostStorageT = std::unique_ptr< std::vector< uint8_t > > |
| Storage type for the host buffer. | |
| using | StorageT = std::variant< DeviceStorageT, HostStorageT > |
| Storage type in Buffer, which could be either host or device memory. | |
Public Member Functions | |
| HostStorageT const & | host () const |
| Access the underlying host memory buffer (const). More... | |
| DeviceStorageT const & | device () const |
| Access the underlying device memory buffer (const). More... | |
| std::byte const * | data () const |
| Access the underlying memory buffer (host or device memory). More... | |
| template<typename F > | |
| auto | write_access (F &&f) -> std::invoke_result_t< F, std::byte *, rmm::cuda_stream_view > |
| Provides stream-ordered write access to the buffer. More... | |
| std::byte * | exclusive_data_access () |
| Acquire non-stream-ordered exclusive access to the buffer's memory. More... | |
| void | unlock () |
Release the exclusive lock acquired by exclusive_data_access(). | |
| constexpr MemoryType | mem_type () const |
| Get the memory type of the buffer. More... | |
| constexpr rmm::cuda_stream_view | stream () const noexcept |
| Get the associated CUDA stream. More... | |
| bool | is_latest_write_done () const |
| Check whether the buffer's most recent write has completed. More... | |
| Buffer (Buffer &&)=delete | |
| Delete move and copy constructors and assignment operators. | |
| Buffer (Buffer const &)=delete | |
| Buffer & | operator= (Buffer &o)=delete |
| Buffer & | operator= (Buffer &&o)=delete |
Public Attributes | |
| std::size_t const | size |
| The size of the buffer in bytes. | |
Friends | |
| class | BufferResource |
Buffer representing device or host memory.
BufferResource to construct buffers. stream()). All work (host and device) that reads or writes the buffer must either be enqueued on that stream or be synchronized with it before accessing the memory. stream().synchronize()) or verify completion via is_latest_write_done(). Definition at line 53 of file buffer.hpp.
| std::byte const* rapidsmpf::Buffer::data | ( | ) | const |
Access the underlying memory buffer (host or device memory).
| std::logic_error | if the buffer does not manage any memory. |
| std::logic_error | If the buffer is locked. |
| DeviceStorageT const& rapidsmpf::Buffer::device | ( | ) | const |
Access the underlying device memory buffer (const).
| std::logic_error | if the buffer does not manage device memory. |
| std::logic_error | If the buffer is locked. |
| std::byte* rapidsmpf::Buffer::exclusive_data_access | ( | ) |
Acquire non-stream-ordered exclusive access to the buffer's memory.
Alternative to write_access(). Acquires an internal exclusive lock so that any other access through the Buffer API (including write_access()) will fail with std::logic_error while the lock is held. The lock remains held until unlock() is called. This lock is not a concurrency mechanism; it only prevents accidental access to the Buffer through the rest of the Buffer API while locked.
Use this when integrating with non-stream-aware consumer APIs that require a raw pointer and cannot be expressed as work on a CUDA stream (e.g., MPI, blocking host I/O).
write_access(...) if you can express the operation as a single callable on a stream, even if that requires manually synchronizing the stream before the callable returns.| std::logic_error | If the buffer is already locked. |
| std::logic_error | If is_latest_write_done() != true. |
| HostStorageT const& rapidsmpf::Buffer::host | ( | ) | const |
Access the underlying host memory buffer (const).
| std::logic_error | if the buffer does not manage host memory. |
| std::logic_error | If the buffer is locked. |
| bool rapidsmpf::Buffer::is_latest_write_done | ( | ) | const |
Check whether the buffer's most recent write has completed.
Returns whether the CUDA event that tracks the most recent write into this buffer has been signaled.
Use this to guard non-stream-ordered consumer-APIs that do not accept a CUDA stream (e.g., MPI sends/receives, host-side reads).
true. Ensure no further writes are enqueued, or establish stronger synchronization (e.g., synchronize the buffer's stream) before using the buffer.true if the last recorded write event has completed; false otherwise.| std::logic_error | If the buffer is locked. |
|
inlineconstexpr |
Get the memory type of the buffer.
| std::logic_error | if the buffer is not initialized. |
Definition at line 200 of file buffer.hpp.
|
inlineconstexprnoexcept |
Get the associated CUDA stream.
All operations must either use this stream or synchronize with it before accessing the underlying data (both host and device memory).
Definition at line 218 of file buffer.hpp.
|
inline |
Provides stream-ordered write access to the buffer.
Calls f with a pointer to the buffer's memory and the buffer's stream (i.e., this->stream()).
The callable must be invocable as:
R(std::byte*, rmm::cuda_stream_view).All work performed by f must be stream-ordered on the buffer's stream. Enqueuing work on any other stream without synchronizing with the buffer's stream before and after the call is undefined behavior. In other words, f must behave as a single stream-ordered operation, similar to issuing one cudaMemcpyAsync on the buffer's stream. For non-stream-aware integrations, use exclusive_data_access().
After f returns, an event is recorded on the buffer's stream, establishing the new "latest write" for this buffer.
f is undefined behavior.| F | Callable type. |
| f | Callable that accepts (std::byte*, rmm::cuda_stream_view). |
f returns (void if none).| std::logic_error | If the buffer is locked. |
Definition at line 141 of file buffer.hpp.