A device_memory_resource
which allocates memory blocks of a single fixed size.
More...
#include <fixed_size_memory_resource.hpp>
Public Member Functions | |
fixed_size_memory_resource (Upstream *upstream_mr, std::size_t block_size=default_block_size, std::size_t blocks_to_preallocate=default_blocks_to_preallocate) | |
Construct a new fixed_size_memory_resource that allocates memory from upstream_resource . More... | |
~fixed_size_memory_resource () override | |
Destroy the fixed_size_memory_resource and free all memory allocated from upstream. | |
fixed_size_memory_resource (fixed_size_memory_resource const &)=delete | |
fixed_size_memory_resource (fixed_size_memory_resource &&)=delete | |
fixed_size_memory_resource & | operator= (fixed_size_memory_resource const &)=delete |
fixed_size_memory_resource & | operator= (fixed_size_memory_resource &&)=delete |
bool | supports_streams () const noexcept override |
Query whether the resource supports use of non-null streams for allocation/deallocation. More... | |
bool | supports_get_mem_info () const noexcept override |
Query whether the resource supports the get_mem_info API. More... | |
Upstream * | get_upstream () const noexcept |
Get the upstream memory_resource object. More... | |
std::size_t | get_block_size () const noexcept |
Get the size of blocks allocated by this memory resource. More... | |
![]() | |
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 |
![]() | |
fixed_size_memory_resource< Upstream > & | underlying () |
fixed_size_memory_resource< Upstream > 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... | |
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... | |
Static Public Attributes | |
static constexpr std::size_t | default_block_size = 1 << 20 |
static constexpr std::size_t | default_blocks_to_preallocate = 128 |
Protected Types | |
using | free_list = detail::fixed_size_free_list |
using | block_type = free_list::block_type |
using | lock_guard = std::lock_guard< std::mutex > |
![]() | |
using | free_list = detail::fixed_size_free_list |
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 | |
std::size_t | get_maximum_allocation_size () const |
Get the (fixed) size of allocations supported by this memory resource. More... | |
block_type | expand_pool (std::size_t size, free_list &blocks, cuda_stream_view stream) |
Allocate a block from upstream to supply the suballocation pool. More... | |
free_list | blocks_from_upstream (cuda_stream_view stream) |
Allocate blocks from upstream to expand the suballocation pool. More... | |
split_block | allocate_from_block (block_type const &block, std::size_t size) |
Splits block if necessary to return a pointer to memory of size bytes. More... | |
block_type | free_block (void *ptr, std::size_t size) noexcept |
Finds, frees and returns the block associated with pointer. More... | |
std::pair< std::size_t, std::size_t > | do_get_mem_info (cuda_stream_view stream) const override |
Get free and available memory for memory resource. More... | |
void | release () |
free all memory allocated using the upstream resource. | |
std::pair< std::size_t, std::size_t > | free_list_summary (free_list const &blocks) |
Get the largest available block size and total free size in the specified free list. More... | |
![]() | |
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... | |
Friends | |
class | detail::stream_ordered_memory_resource< fixed_size_memory_resource< Upstream >, detail::fixed_size_free_list > |
A device_memory_resource
which allocates memory blocks of a single fixed size.
Supports only allocations of size smaller than the configured block_size.
|
inlineexplicit |
Construct a new fixed_size_memory_resource
that allocates memory from upstream_resource
.
When the pool of blocks is all allocated, grows the pool by allocating blocks_to_preallocate
more blocks from upstream_mr
.
upstream_mr | The memory_resource from which to allocate blocks for the pool. |
block_size | The size of blocks to allocate. |
blocks_to_preallocate | The number of blocks to allocate to initialize the pool. |
|
inlineprotected |
Splits block if necessary to return a pointer to memory of size
bytes.
If the block is split, the remainder is returned to the pool.
block | The block to allocate from. |
size | The size in bytes of the requested allocation. |
stream_event | The stream and associated event on which the allocation will be used. |
|
inlineprotected |
Allocate blocks from upstream to expand the suballocation pool.
size | The minimum size to allocate |
stream | The stream on which the memory is to be used. |
|
inlineoverrideprotectedvirtual |
Get free and available memory for memory resource.
std::runtime_error | if we could not get free / total memory |
stream | the stream being executed on |
Implements rmm::mr::device_memory_resource.
|
inlineprotected |
Allocate a block from upstream to supply the suballocation pool.
Note typically the allocated size will be larger than requested, and is based on the growth strategy (see size_to_grow()
).
size | The minimum size to allocate |
stream | The stream on which the memory is to be used. |
|
inlineprotectednoexcept |
Finds, frees and returns the block associated with pointer.
ptr | The pointer to the memory to free. |
size | The size of the memory to free. Must be equal to the original allocation size. |
stream | The stream-event pair for the stream on which the memory was last used. |
p
. The caller is expected to return the block to the pool.
|
inlineprotected |
Get the largest available block size and total free size in the specified free list.
This is intended only for debugging
blocks | The free list from which to return the summary |
|
inlinenoexcept |
Get the size of blocks allocated by this memory resource.
|
inlineprotected |
Get the (fixed) size of allocations supported by this memory resource.
|
inlinenoexcept |
Get the upstream memory_resource object.
|
inlineoverridevirtualnoexcept |
Query whether the resource supports the get_mem_info API.
Implements rmm::mr::device_memory_resource.
|
inlineoverridevirtualnoexcept |
Query whether the resource supports use of non-null streams for allocation/deallocation.
Implements rmm::mr::device_memory_resource.