Block of host memory.
More...
#include <host_buffer.hpp>
Block of host memory.
Definition at line 30 of file host_buffer.hpp.
◆ OwnedStorageDeleter
Type-erased deleter for owned storage.
This deleter holds a callable that releases the underlying storage when invoked. It enables HostBuffer to take ownership of different storage types (e.g., rmm::device_buffer, std::vector<std::uint8_t>) without exposing their types. The deleter captures the owned object and destroys it when the deleter itself is destroyed (the void* parameter is ignored).
Definition at line 41 of file host_buffer.hpp.
◆ HostBuffer() [1/2]
Allocate a new host buffer.
If size is greater than zero, memory is allocated using the provided memory resource and stream. If size is zero, the buffer is created empty.
- Parameters
-
| size | Number of bytes to allocate. |
| stream | CUDA stream on which allocation and deallocation occur. |
| mr | RMM host memory resource used for allocation. |
◆ HostBuffer() [2/2]
| rapidsmpf::HostBuffer::HostBuffer |
( |
HostBuffer && |
other | ) |
|
|
noexcept |
Move constructor.
Transfers ownership of the underlying memory. The moved-from object becomes empty.
- Parameters
-
| other | The buffer to move from. |
◆ copy_to_uint8_vector()
| std::vector<std::uint8_t> rapidsmpf::HostBuffer::copy_to_uint8_vector |
( |
| ) |
const |
Copy the contents of the buffer into a host std::vector.
This is primarily intended for debugging or testing. It performs a stream synchronization before and after the copy.
- Returns
- A vector containing the copied bytes.
◆ data() [1/2]
| std::byte const* rapidsmpf::HostBuffer::data |
( |
| ) |
const |
|
noexcept |
Get a const pointer to the buffer data.
- Returns
- Const pointer to the underlying memory.
◆ data() [2/2]
| std::byte* rapidsmpf::HostBuffer::data |
( |
| ) |
|
|
noexcept |
Get a pointer to the buffer data.
- Returns
- Pointer to the underlying memory.
◆ deallocate_async()
| void rapidsmpf::HostBuffer::deallocate_async |
( |
| ) |
|
|
noexcept |
Stream-ordered deallocates the buffer, if allocated.
After deallocation the buffer becomes empty. It is safe to call this method multiple times.
◆ empty()
| bool rapidsmpf::HostBuffer::empty |
( |
| ) |
const |
|
noexcept |
Check whether the buffer is empty.
- Returns
- True if no memory is allocated.
◆ from_owned_vector()
Construct a HostBuffer by taking ownership of a std::vector<std::uint8_t>.
The buffer takes ownership of the vector's memory. The vector is moved into internal storage and will be destroyed when the HostBuffer is destroyed.
- Parameters
-
| data | Vector to take ownership of (will be moved). |
| stream | CUDA stream to associate with this buffer. |
| mr | Host memory resource used to allocate the buffer. |
- Returns
- A new
HostBuffer owning the vector's memory.
◆ from_rmm_device_buffer()
Construct a HostBuffer by taking ownership of an rmm::device_buffer.
The buffer takes ownership of the device buffer. The caller must ensure that the device buffer contains host-accessible memory (e.g., pinned host memory allocated via a managed or pinned memory resource).
- Warning
- The caller is responsible for ensuring the device buffer's memory is host-accessible. Using this with non-host-accessible device memory will result in a std::invalid_argument exception.
- Parameters
-
| pinned_host_buffer | Device buffer to take ownership of. |
| stream | CUDA stream to associate with this buffer. |
| mr | Pinned host memory resource used to allocate the buffer. |
- Returns
- A new
HostBuffer owning the device buffer's memory.
- Exceptions
-
| std::invalid_argument | if pinned_host_buffer is null. |
| std::logic_error | if pinned_host_buffer is not of pinned memory host memory type (see warning for details). |
- Warning
- The caller is responsible to ensure
pinned_host_buffer is of pinned host memory type. If non-pinned host buffer leads to an irrecoverable condition.
◆ from_uint8_vector()
Construct a HostBuffer by copying data from a std::vector<std::uint8_t>.
A new buffer is allocated using the provided memory resource and stream. This helper is intended for tests and small debug utilities.
- Parameters
-
| data | Source vector containing the bytes to copy. |
| stream | CUDA stream used for allocation and copy. |
| mr | Host memory resource used to allocate the buffer. |
- Returns
- A new
HostBuffer containing a copy of data.
◆ operator=()
Move assignment operator.
Transfers ownership of the underlying memory. The current buffer must be empty before assignment.
- Parameters
-
| other | The buffer to move from. |
- Returns
- Reference to this object.
- Exceptions
-
| std::invalid_argument | if this buffer is already initialized. |
◆ set_stream()
Set the associated CUDA stream.
This function only updates the buffer's associated CUDA stream. It does not perform any stream synchronization or establish ordering guarantees between the previous stream and stream. Callers must ensure that any work previously enqueued on the old stream that may access the buffer has completed or is otherwise properly synchronized before switching streams.
- Parameters
-
| stream | The new CUDA stream. |
◆ size()
| std::size_t rapidsmpf::HostBuffer::size |
( |
| ) |
const |
|
noexcept |
Get the size of the buffer in bytes.
- Returns
- Number of bytes in the buffer.
◆ stream()
Get the CUDA stream associated with this buffer.
- Returns
- CUDA stream view.
The documentation for this class was generated from the following file: