Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | 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 ()
 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...
 
- Public Member Functions inherited from rmm::mr::detail::stream_ordered_memory_resource< fixed_size_memory_resource< Upstream >, detail::fixed_size_free_list >
 stream_ordered_memory_resource (stream_ordered_memory_resource const &)=delete
 
 stream_ordered_memory_resource (stream_ordered_memory_resource &&)=delete
 
stream_ordered_memory_resourceoperator= (stream_ordered_memory_resource const &)=delete
 
stream_ordered_memory_resourceoperator= (stream_ordered_memory_resource &&)=delete
 
- Public Member Functions inherited from rmm::mr::detail::crtp< fixed_size_memory_resource< Upstream > >
fixed_size_memory_resource< Upstream > & underlying ()
 
fixed_size_memory_resource< Upstream > const & underlying () const
 
- Public Member Functions inherited from rmm::mr::device_memory_resource
void * allocate (std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
 Allocates memory of size at least bytes. More...
 
void deallocate (void *p, 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
 
static constexpr std::size_t allocation_alignment = 256
 
- Static Public Attributes inherited from rmm::mr::detail::stream_ordered_memory_resource< fixed_size_memory_resource< Upstream >, detail::fixed_size_free_list >
static constexpr size_t allocation_alignment
 

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 >
 
- Protected Types inherited from rmm::mr::detail::stream_ordered_memory_resource< fixed_size_memory_resource< Upstream >, detail::fixed_size_free_list >
using free_list = detail::fixed_size_free_list
 
using block_type = typename free_list::block_type
 
using lock_guard = std::lock_guard< std::mutex >
 

Protected Member Functions

size_t get_maximum_allocation_size () const
 Get the (fixed) size of allocations supported by this memory resource. More...
 
block_type expand_pool (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 &b, size_t size)
 Splits block b if necessary to return a pointer to memory of size bytes. More...
 
block_type free_block (void *p, size_t size) noexcept
 Finds, frees and returns the block associated with pointer p. 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.
 
void print ()
 
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...
 
- Protected Member Functions inherited from rmm::mr::detail::stream_ordered_memory_resource< fixed_size_memory_resource< Upstream >, detail::fixed_size_free_list >
void insert_block (block_type const &b, cuda_stream_view stream)
 Split block b if necessary to return a pointer to memory of size bytes. More...
 
void insert_blocks (free_list &&blocks, cuda_stream_view stream)
 
void print_free_blocks () const
 
std::mutex & get_mutex ()
 Get the mutex object. More...
 
virtual void * do_allocate (std::size_t bytes, cuda_stream_view stream) override
 Allocates memory of size at least bytes. More...
 
virtual void do_deallocate (void *p, std::size_t bytes, cuda_stream_view stream) override
 Deallocate memory pointed to by p. More...
 

Protected Attributes

Upstream * upstream_mr_
 
std::size_t const block_size_
 
std::size_t const upstream_chunk_size_
 
std::vector< block_type > upstream_blocks_
 

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 &  b,
size_t  size 
)
inlineprotected

Splits block b if necessary to return a pointer to memory of size bytes.

If the block is split, the remainder is returned to the pool.

Parameters
bThe block to allocate from.
sizeThe size in bytes of the requested allocation.
stream_eventThe stream and associated event on which the allocation will be used.
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
sizeThe minimum size to allocate
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 ( cuda_stream_view  stream) const
inlineoverrideprotectedvirtual

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

Implements rmm::mr::device_memory_resource.

◆ expand_pool()

template<typename Upstream >
block_type rmm::mr::fixed_size_memory_resource< Upstream >::expand_pool ( 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
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 *  p,
size_t  size 
)
inlineprotectednoexcept

Finds, frees and returns the block associated with pointer p.

Parameters
pThe pointer to the memory to free.
sizeThe size of the memory to free. Must be equal to the original allocation size.
streamThe stream-event pair for the stream on which the memory was last used.
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 >
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
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
inlineoverridevirtualnoexcept

Query whether the resource supports the get_mem_info API.

Returns
bool true if the resource supports get_mem_info, false otherwise.

Implements rmm::mr::device_memory_resource.

◆ supports_streams()

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

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

Returns
true

Implements rmm::mr::device_memory_resource.


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