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...
|
| | 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.
|
| |
| | CArena (const CArena &rhs)=delete |
| |
| | CArena (CArena &&rhs)=delete |
| |
| CArena & | operator= (const CArena &rhs)=delete |
| |
| CArena & | operator= (CArena &&rhs)=delete |
| |
| | ~CArena () override |
| | The destructor.
|
| |
| void * | alloc (std::size_t nbytes) final |
| | Allocate some memory.
|
| |
| std::pair< void *, std::size_t > | alloc_in_place (void *pt, std::size_t szmin, std::size_t szmax) final |
| | Allocate memory in-place if possible.
|
| |
| void * | shrink_in_place (void *pt, std::size_t new_size) final |
| | Shrink allocation size in-place.
|
| |
| void | free (void *vp) final |
| | Free up allocated memory. Merge neighboring free memory chunks into largest possible chunk.
|
| |
| std::size_t | freeUnused () final |
| | Free unused memory back to the system. Return value is the amount of memory freed.
|
| |
| std::size_t | freeableMemory () const |
| | Return the amount of memory that can be freed.
|
| |
| 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.
|
| |
| std::size_t | heap_space_used () const noexcept |
| | The current amount of heap space used by the CArena object.
|
| |
| std::size_t | heap_space_actually_used () const noexcept |
| | Return the total amount of memory given out via alloc.
|
| |
| std::size_t | sizeOf (void *p) const noexcept |
| | Return the amount of memory in this pointer. Return 0 for unknown pointer.
|
| |
| void | PrintUsage (std::string const &name, bool print_max_usage) const |
| | Print memory usage information of this arena.
|
| |
| void | PrintUsage (std::ostream &os, std::string const &name, std::string const &space) const |
| | Print memory usage information of this arena to a given output stream.
|
| |
| void | ResetMaxUsageCounter () final |
| | Reset the maximum usage counter.
|
| |
| 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 |
| | Check whether it is managed GPU memory.
|
| |
| virtual bool | isDevice () const |
| | Check whether it is non-managed GPU device memory.
|
| |
| virtual bool | isPinned () const |
| | Check whether it is pinned host memory.
|
| |
| void | registerForProfiling (const std::string &memory_name) |
| | Add this Arena to the list of Arenas that are profiled by TinyProfiler.
|
| |
| 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.
|
| |
| virtual bool | isStreamOrderedArena () const |
| | Is this GPU stream ordered memory allocator?
|
| |
| virtual void | streamOrderedFree (void *pt, gpuStream_t stream) |
| |
| const ArenaInfo & | arenaInfo () const |
| | Return the ArenaInfo object for querying.
|
| |
|
| 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.
|
| |
| static void | Initialize (bool minimal) |
| | Used internally by amrex.
|
| |
| static void | PrintUsage (bool print_max_usage=false) |
| | Print memory usage information of all arenas.
|
| |
| static void | PrintUsageToStream (std::ostream &os, std::string const &space) |
| | Print memory usage information of all arenas to a given output stream.
|
| |
| static void | PrintUsageToFiles (std::string const &filename, std::string const &message) |
| | Print memory usage information of all arenas to given file.
|
| |
| static void | Finalize () |
| | Used internally by amrex.
|
| |
| static void | out_of_memory_abort (std::string const &memory_type, std::size_t nbytes, std::string const &error_msg) |
| |
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().
| std::pair< void *, std::size_t > amrex::CArena::alloc_in_place |
( |
void * |
pt, |
|
|
std::size_t |
szmin, |
|
|
std::size_t |
szmax |
|
) |
| |
|
finalvirtual |
Allocate memory in-place if possible.
This function tries to allocate in-place by extending the capacity of an existing pointer. If it's possible to extend the given pointer to the minimum required size without performing a new allocation, this function will return the original pointer back along with the new size (which may be in the range of [szmin,szmax]); otherwise a new allocation is performed to allocate the maximum requested size.
Note that this function does NOT free the existing allocation, even when a new memory allocation is performed. So it's the caller's responsibility to free the original pointer when appropriate. A new allocation can be detected by comparing the returned pointer with the input pointer.
- Parameters
-
| pt | existing pointer |
| szmin | minimum required size in bytes |
| szmax | maximum requested size in bytes |
- Returns
- pair of pointer and allocation size in bytes
Reimplemented from amrex::Arena.
| void * amrex::CArena::shrink_in_place |
( |
void * |
pt, |
|
|
std::size_t |
new_size |
|
) |
| |
|
finalvirtual |
Shrink allocation size in-place.
This function shrinks the existing allocation of the given pointer to a new size. It's a runtime error, if the requested new size is larger than the original size. In the special case of pt == nullptr or new_size == 0, this does not do anything other than returning nullptr.
- Parameters
-
| pt | existing pointer |
| new_size | new size after shrinking |
- Returns
- either the original pointer or
nullptr if the requested new size is zero.
Reimplemented from amrex::Arena.