Base class for a stream-ordered memory resource. More...
#include <stream_ordered_memory_resource.hpp>
Classes | |
struct | stream_event_pair |
Public Member Functions | |
stream_ordered_memory_resource (stream_ordered_memory_resource const &)=delete | |
stream_ordered_memory_resource (stream_ordered_memory_resource &&)=delete | |
stream_ordered_memory_resource & | operator= (stream_ordered_memory_resource const &)=delete |
stream_ordered_memory_resource & | operator= (stream_ordered_memory_resource &&)=delete |
![]() | |
PoolResource & | underlying () |
PoolResource const & | underlying () const |
![]() | |
device_memory_resource (device_memory_resource const &)=default | |
device_memory_resource & | operator= (device_memory_resource const &)=default |
device_memory_resource (device_memory_resource &&) noexcept=default | |
device_memory_resource & | operator= (device_memory_resource &&) noexcept=default |
void * | allocate (std::size_t bytes, cuda_stream_view stream=cuda_stream_view{}) |
Allocates memory of size at least bytes . More... | |
void | deallocate (void *ptr, std::size_t bytes, cuda_stream_view stream=cuda_stream_view{}) |
Deallocate memory pointed to by p . More... | |
bool | is_equal (device_memory_resource const &other) const noexcept |
Compare this resource to another. More... | |
virtual bool | supports_streams () const noexcept=0 |
Query whether the resource supports use of non-null CUDA streams for allocation/deallocation. More... | |
virtual bool | supports_get_mem_info () const noexcept=0 |
Query whether the resource supports the get_mem_info API. More... | |
std::pair< std::size_t, std::size_t > | get_mem_info (cuda_stream_view stream) const |
Queries the amount of free and total memory for the resource. More... | |
Protected Types | |
using | free_list = FreeListType |
using | block_type = typename free_list::block_type |
using | lock_guard = std::lock_guard< std::mutex > |
using | split_block = std::pair< block_type, block_type > |
Pair representing a block that has been split for allocation. | |
Protected Member Functions | |
void | insert_block (block_type const &block, cuda_stream_view stream) |
Returns the block b (last used on stream stream_event ) to the pool. More... | |
void | insert_blocks (free_list &&blocks, cuda_stream_view stream) |
std::mutex & | get_mutex () |
Get the mutex object. More... | |
void * | do_allocate (std::size_t size, cuda_stream_view stream) override |
Allocates memory of size at least bytes . More... | |
void | do_deallocate (void *ptr, std::size_t size, cuda_stream_view stream) override |
Deallocate memory pointed to by p . More... | |
Base class for a stream-ordered memory resource.
This base class uses CRTP (https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern) to provide static polymorphism to enable defining suballocator resources that maintain separate pools per stream. All of the stream-ordering logic is contained in this class, but the logic to determine how memory pools are managed and the type of allocation is implemented in a derived class and in a free list class.
For example, a coalescing pool memory resource uses a coalescing_free_list and maintains data structures for allocated blocks and has functions to allocate and free blocks and to expand the pool.
Classes derived from stream_ordered_memory_resource must implement the following four methods, documented separately:
std::size_t get_maximum_allocation_size() const
block_type expand_pool(std::size_t size, free_list& blocks, cuda_stream_view stream)
split_block allocate_from_block(block_type const& b, std::size_t size)
block_type free_block(void* p, std::size_t size) noexcept
|
inlineoverrideprotectedvirtual |
Allocates memory of size at least bytes
.
The returned pointer has at least 256B alignment.
<tt>std::bad_alloc</tt> | if the requested allocation could not be fulfilled |
size | The size in bytes of the allocation |
stream | The stream in which to order this allocation |
Implements rmm::mr::device_memory_resource.
|
inlineoverrideprotectedvirtual |
Deallocate memory pointed to by p
.
nothing |
p | Pointer to be deallocated |
size | The size in bytes of the allocation to deallocate |
stream | The stream in which to order this deallocation |
Implements rmm::mr::device_memory_resource.
|
inlineprotected |
Get the mutex object.
|
inlineprotected |
Returns the block b
(last used on stream stream_event
) to the pool.
block | The block to insert into the pool. |
stream | The stream on which the memory was last used. |