Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Friends | List of all members
rmm::mr::fixed_size_memory_resource< Upstream > Class Template Reference

A device_memory_resource which allocates memory blocks of a single fixed size. More...

#include <fixed_size_memory_resource.hpp>

Inheritance diagram for rmm::mr::fixed_size_memory_resource< Upstream >:
Inheritance graph
[legend]
Collaboration diagram for rmm::mr::fixed_size_memory_resource< Upstream >:
Collaboration graph
[legend]

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_resourceoperator= (fixed_size_memory_resource const &)=delete
 
fixed_size_memory_resourceoperator= (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...
 

Static Public Attributes

static constexpr std::size_t default_block_size = 1 << 20
 Default allocation block size.
 
static constexpr std::size_t default_blocks_to_preallocate = 128
 

Protected Types

using free_list = detail::fixed_size_free_list
 The free list type.
 
using block_type = free_list::block_type
 The type of block managed by the free list.
 
using lock_guard = std::lock_guard< std::mutex >
 Type of lock used to synchronize access.
 

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 ([[maybe_unused]] 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...
 

Friends

class detail::stream_ordered_memory_resource< fixed_size_memory_resource< Upstream >, detail::fixed_size_free_list >
 

Detailed Description

template<typename Upstream>
class rmm::mr::fixed_size_memory_resource< Upstream >

A device_memory_resource which allocates memory blocks of a single fixed size.

Supports only allocations of size smaller than the configured block_size.

Constructor & Destructor Documentation

◆ fixed_size_memory_resource()

template<typename Upstream >
rmm::mr::fixed_size_memory_resource< Upstream >::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 
)
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.

Parameters
upstream_mrThe memory_resource from which to allocate blocks for the pool.
block_sizeThe size of blocks to allocate.
blocks_to_preallocateThe number of blocks to allocate to initialize the pool.

Member Function Documentation

◆ allocate_from_block()

template<typename Upstream >
split_block rmm::mr::fixed_size_memory_resource< Upstream >::allocate_from_block ( block_type const &  block,
std::size_t  size 
)
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.

Parameters
blockThe block to allocate from.
sizeThe size in bytes of the requested allocation.
Returns
A pair comprising the allocated pointer and any unallocated remainder of the input block.

◆ blocks_from_upstream()

template<typename Upstream >
free_list rmm::mr::fixed_size_memory_resource< Upstream >::blocks_from_upstream ( cuda_stream_view  stream)
inlineprotected

Allocate blocks from upstream to expand the suballocation pool.

Parameters
streamThe stream on which the memory is to be used.
Returns
block_type The allocated block

◆ do_get_mem_info()

template<typename Upstream >
std::pair<std::size_t, std::size_t> rmm::mr::fixed_size_memory_resource< Upstream >::do_get_mem_info ( [[maybe_unused] ] cuda_stream_view  stream) const
inlineoverrideprotected

Get free and available memory for memory resource.

Exceptions
std::runtime_errorif we could not get free / total memory
Parameters
streamthe stream being executed on
Returns
std::pair with available and free memory for resource

◆ expand_pool()

template<typename Upstream >
block_type rmm::mr::fixed_size_memory_resource< Upstream >::expand_pool ( std::size_t  size,
free_list blocks,
cuda_stream_view  stream 
)
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()).

Parameters
sizeThe minimum size to allocate
blocksThe set of blocks from which to allocate
streamThe stream on which the memory is to be used.
Returns
block_type The allocated block

◆ free_block()

template<typename Upstream >
block_type rmm::mr::fixed_size_memory_resource< Upstream >::free_block ( void *  ptr,
std::size_t  size 
)
inlineprotectednoexcept

Finds, frees and returns the block associated with pointer.

Parameters
ptrThe pointer to the memory to free.
sizeThe size of the memory to free. Must be equal to the original allocation size.
Returns
The (now freed) block associated with p. The caller is expected to return the block to the pool.

◆ free_list_summary()

template<typename Upstream >
std::pair<std::size_t, std::size_t> rmm::mr::fixed_size_memory_resource< Upstream >::free_list_summary ( free_list const &  blocks)
inlineprotected

Get the largest available block size and total free size in the specified free list.

This is intended only for debugging

Parameters
blocksThe free list from which to return the summary
Returns
std::pair<std::size_t, std::size_t> Pair of largest available block, total free size

◆ get_block_size()

template<typename Upstream >
std::size_t rmm::mr::fixed_size_memory_resource< Upstream >::get_block_size ( ) const
inlinenoexcept

Get the size of blocks allocated by this memory resource.

Returns
std::size_t size in bytes of allocated blocks.

◆ get_maximum_allocation_size()

template<typename Upstream >
std::size_t rmm::mr::fixed_size_memory_resource< Upstream >::get_maximum_allocation_size ( ) const
inlineprotected

Get the (fixed) size of allocations supported by this memory resource.

Returns
std::size_t The (fixed) maximum size of a single allocation supported by this memory resource

◆ get_upstream()

template<typename Upstream >
Upstream* rmm::mr::fixed_size_memory_resource< Upstream >::get_upstream ( ) const
inlinenoexcept

Get the upstream memory_resource object.

Returns
UpstreamResource* the upstream memory resource.

◆ supports_get_mem_info()

template<typename Upstream >
bool rmm::mr::fixed_size_memory_resource< Upstream >::supports_get_mem_info ( ) const
inlineoverridenoexcept

Query whether the resource supports the get_mem_info API.

Returns
false

◆ supports_streams()

template<typename Upstream >
bool rmm::mr::fixed_size_memory_resource< Upstream >::supports_streams ( ) const
inlineoverridenoexcept

Query whether the resource supports use of non-null streams for allocation/deallocation.

Returns
true

Member Data Documentation

◆ default_blocks_to_preallocate

template<typename Upstream >
constexpr std::size_t rmm::mr::fixed_size_memory_resource< Upstream >::default_blocks_to_preallocate = 128
staticconstexpr

The number of blocks that the pool starts out with, and also the number of blocks by which the pool grows when all of its current blocks are allocated


The documentation for this class was generated from the following file: