A Concrete Class for Dynamic Memory Management using first fit. This is a coalescing memory manager. It allocates (possibly) large chunks of heap space and apportions it out as requested. It merges together neighboring chunks on each free(). More...
#include <AMReX_CArena.H>
Classes | |
class | Node |
The nodes in our free list and block list. More... | |
Public Member Functions | |
CArena (std::size_t hunk_size=0, ArenaInfo info=ArenaInfo()) | |
Construct a coalescing memory manager. hunk_size is the minimum size of hunks of memory to allocate from the heap. If hunk_size == 0 we use DefaultHunkSize as specified below. More... | |
CArena (const CArena &rhs)=delete | |
CArena (CArena &&rhs)=delete | |
CArena & | operator= (const CArena &rhs)=delete |
CArena & | operator= (CArena &&rhs)=delete |
~CArena () override | |
The destructor. More... | |
void * | alloc (std::size_t nbytes) final |
Allocate some memory. More... | |
std::pair< void *, std::size_t > | alloc_in_place (void *pt, std::size_t szmin, std::size_t szmax) final |
void * | shrink_in_place (void *pt, std::size_t new_size) final |
void | free (void *vp) final |
Free up allocated memory. Merge neighboring free memory chunks into largest possible chunk. More... | |
std::size_t | freeUnused () final |
Free unused memory back to the system. Return value is the amount memory freed. More... | |
bool | hasFreeDeviceMemory (std::size_t sz) final |
Does the device have enough free memory for allocating this much memory? For CPU builds, this always return true. This is not a const function because it may attempt to release memory back to the system. More... | |
std::size_t | heap_space_used () const noexcept |
The current amount of heap space used by the CArena object. More... | |
std::size_t | heap_space_actually_used () const noexcept |
Return the total amount of memory given out via alloc. More... | |
std::size_t | sizeOf (void *p) const noexcept |
Return the amount of memory in this pointer. Return 0 for unknown pointer. More... | |
void | PrintUsage (std::string const &name) const |
void | PrintUsage (std::ostream &os, std::string const &name, std::string const &space) const |
Public Member Functions inherited from amrex::Arena | |
virtual | ~Arena ()=default |
Arena () noexcept=default | |
Arena (const Arena &rhs)=delete | |
Arena (Arena &&rhs)=delete | |
Arena & | operator= (const Arena &rhs)=delete |
Arena & | operator= (Arena &&rhs)=delete |
virtual bool | isDeviceAccessible () const |
virtual bool | isHostAccessible () const |
virtual bool | isManaged () const |
virtual bool | isDevice () const |
virtual bool | isPinned () const |
void | registerForProfiling (const std::string &memory_name) |
Add this Arena to the list of Arenas that are profiled by TinyProfiler. More... | |
void | deregisterFromProfiling () |
Remove this Arena from the list of Arenas that are profiled by TinyProfiler. This is equivalent to destructing and re-constructing the Arena. More... | |
virtual bool | isStreamOrderedArena () const |
Is this GPU stream ordered memory allocator? More... | |
const ArenaInfo & | arenaInfo () const |
Return the ArenaInfo object for querying. More... | |
Static Public Attributes | |
constexpr static std::size_t | DefaultHunkSize = 1024*1024*8 |
The default memory hunk size to grab from the heap. More... | |
Static Public Attributes inherited from amrex::Arena | |
static const std::size_t | align_size = 16 |
Protected Types | |
using | NL = std::set< Node > |
The type of our freelist and blocklist. We use a set sorted from lo to hi memory addresses. More... | |
Protected Member Functions | |
void * | alloc_protected (std::size_t nbytes) |
std::size_t | freeUnused_protected () final |
Protected Member Functions inherited from amrex::Arena | |
void * | allocate_system (std::size_t nbytes) |
void | deallocate_system (void *p, std::size_t nbytes) |
Protected Attributes | |
std::vector< std::pair< void *, std::size_t > > | m_alloc |
The list of blocks allocated via ::operator new(). More... | |
NL | m_freelist |
The free list of allocated but not currently used blocks. Maintained in lo to hi memory sorted order. More... | |
std::unordered_set< Node, Node::hash > | m_busylist |
The list of busy blocks. A block is either on the freelist or on the blocklist, but not on both. More... | |
std::size_t | m_hunk |
The minimal size of hunks to request from system. More... | |
std::size_t | m_used {0} |
The amount of heap space currently allocated. More... | |
std::size_t | m_actually_used {0} |
The amount of memory given out via alloc(). More... | |
std::mutex | carena_mutex |
Protected Attributes inherited from amrex::Arena | |
ArenaInfo | arena_info |
struct amrex::Arena::ArenaProfiler | m_profiler |
Friends | |
std::ostream & | operator<< (std::ostream &os, const CArena &arena) |
Additional Inherited Members | |
Static Public Member Functions inherited from amrex::Arena | |
static std::size_t | align (std::size_t sz) |
Given a minimum required arena size of sz bytes, this returns the next largest arena size that will align to align_size bytes. More... | |
static void | Initialize () |
static void | PrintUsage () |
static void | PrintUsageToFiles (std::string const &filename, std::string const &message) |
static void | Finalize () |
A Concrete Class for Dynamic Memory Management using first fit. This is a coalescing memory manager. It allocates (possibly) large chunks of heap space and apportions it out as requested. It merges together neighboring chunks on each free().
|
protected |
The type of our freelist and blocklist. We use a set sorted from lo to hi memory addresses.
Construct a coalescing memory manager. hunk_size is the minimum size of hunks of memory to allocate from the heap. If hunk_size == 0 we use DefaultHunkSize as specified below.
|
delete |
|
delete |
|
override |
The destructor.
|
finalvirtual |
Allocate some memory.
Implements amrex::Arena.
|
finalvirtual |
Try to allocate in-place by extending the capacity of given pointer.
Reimplemented from amrex::Arena.
|
protected |
|
finalvirtual |
Free up allocated memory. Merge neighboring free memory chunks into largest possible chunk.
Implements amrex::Arena.
|
finalvirtual |
Free unused memory back to the system. Return value is the amount memory freed.
Reimplemented from amrex::Arena.
|
finalprotectedvirtual |
Reimplemented from amrex::Arena.
|
finalvirtual |
Does the device have enough free memory for allocating this much memory? For CPU builds, this always return true. This is not a const function because it may attempt to release memory back to the system.
Reimplemented from amrex::Arena.
|
noexcept |
Return the total amount of memory given out via alloc.
|
noexcept |
The current amount of heap space used by the CArena object.
void amrex::CArena::PrintUsage | ( | std::ostream & | os, |
std::string const & | name, | ||
std::string const & | space | ||
) | const |
void amrex::CArena::PrintUsage | ( | std::string const & | name | ) | const |
|
finalvirtual |
Try to shrink in-place
Reimplemented from amrex::Arena.
|
noexcept |
Return the amount of memory in this pointer. Return 0 for unknown pointer.
|
friend |
|
protected |
|
staticconstexpr |
The default memory hunk size to grab from the heap.
|
protected |
The amount of memory given out via alloc().
|
protected |
The list of blocks allocated via ::operator new().
|
protected |
The list of busy blocks. A block is either on the freelist or on the blocklist, but not on both.
|
protected |
The free list of allocated but not currently used blocks. Maintained in lo to hi memory sorted order.
|
protected |
The minimal size of hunks to request from system.
|
protected |
The amount of heap space currently allocated.