![]() |
Block-Structured AMR Software Framework
|
Abstract base class for memory arenas. More...
#include <AMReX_Arena.H>
Public Member Functions | |
| 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 void * | alloc (std::size_t sz)=0 |
Allocate sz bytes from this arena. | |
| virtual std::pair< void *, std::size_t > | alloc_in_place (void *pt, std::size_t szmin, std::size_t szmax) |
| Allocate memory in-place if possible. | |
| virtual void * | shrink_in_place (void *pt, std::size_t sz) |
| Shrink allocation size in-place. | |
| virtual void | free (void *pt)=0 |
Free a previously allocated block pointed to by pt. | |
| virtual std::size_t | freeUnused () |
| Release unused cached memory back to the system. | |
| virtual std::size_t | largestFreeBlock () const |
| Return the largest free memory block already held by this Arena. | |
| 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. | |
| virtual bool | hasFreeDeviceMemory (std::size_t sz) |
| 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. | |
| 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. | |
| virtual void | ResetMaxUsageCounter () |
Static Public Member Functions | |
| static std::size_t | align (std::size_t sz) |
Return the smallest multiple of Arena::align_size that is >= sz bytes. | |
| static void | Initialize (bool minimal) |
| Initialize the Arena subsystem (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 bool | IsInitialized () |
Static Public Attributes | |
| static const std::size_t | align_size = 256 |
Protected Member Functions | |
| virtual std::size_t | freeUnused_protected () |
| void * | allocate_system (std::size_t nbytes) |
| void | deallocate_system (void *p, std::size_t nbytes) |
Static Protected Member Functions | |
| static void | out_of_memory_abort (std::string const &memory_type, std::size_t nbytes, std::string const &error_msg) |
Protected Attributes | |
| ArenaInfo | arena_info |
Abstract base class for memory arenas.
Subclasses manage a pool of memory (CPU, GPU device, managed, or pinned) and expose alloc()/free() for raw byte allocation and deallocation.
|
virtualdefault |
|
defaultnoexcept |
|
delete |
|
delete |
|
static |
Return the smallest multiple of Arena::align_size that is >= sz bytes.
|
pure virtual |
Allocate sz bytes from this arena.
| sz | Number of bytes to allocate. |
Implemented in amrex::CArena, amrex::PArena, amrex::BArena, and amrex::SArena.
|
inlinevirtual |
Allocate memory in-place if possible.
In this implementation of the virtual function, a new allocation is always performed, and it returns the new pointer and allocation size. Note that this function does NOT free the existing allocation. So it's the caller's responsibility to free the original pointer when appropriate.
| pt | Existing allocation to be reused when possible. |
| szmin | Minimum acceptable size for reusing pt in place. |
| szmax | Requested size for the returned allocation. |
Reimplemented in amrex::CArena.
|
protected |
|
inline |
Return the ArenaInfo object for querying.
|
protected |
| void amrex::Arena::deregisterFromProfiling | ( | ) |
Remove this Arena from the list of Arenas that are profiled by TinyProfiler. This is equivalent to destructing and re-constructing the Arena.
|
static |
Used internally by amrex.
|
pure virtual |
Free a previously allocated block pointed to by pt.
Implemented in amrex::PArena, amrex::BArena, amrex::SArena, and amrex::CArena.
|
inlinevirtual |
Release unused cached memory back to the system.
Reimplemented in amrex::CArena.
|
inlineprotectedvirtual |
Reimplemented in amrex::CArena.
|
virtual |
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.
| sz | Requested allocation size in bytes. |
Reimplemented in amrex::CArena.
|
static |
|
virtual |
Check whether it is non-managed GPU device memory.
Note that isManaged, isDevice and isPinned are mutually exclusive. For memory allocated by cudaMalloc* etc. in GPU builds, one of them returns true. For CPU builds, they are always false.
Reimplemented in amrex::BArena, amrex::PArena, and amrex::SArena.
|
virtual |
Check whether the memory is accessible on the device. Note that isDeviceAccessible and isHostAccessible can both be true.
Reimplemented in amrex::BArena, amrex::PArena, and amrex::SArena.
|
virtual |
Check whether the memory is accessible on the host. Note that isDeviceAccessible and isHostAccessible can both be true.
Reimplemented in amrex::BArena, amrex::PArena, and amrex::SArena.
|
static |
Whether the Arena subsystem is initialized.
|
virtual |
Check whether it is managed GPU memory.
Note that isManaged, isDevice and isPinned are mutually exclusive. For memory allocated by cudaMalloc* etc. in GPU builds, one of them returns true. For CPU builds, they are always false.
Reimplemented in amrex::BArena, amrex::PArena, and amrex::SArena.
|
virtual |
Check whether it is pinned host memory.
Note that isManaged, isDevice and isPinned are mutually exclusive. For memory allocated by cudaMalloc* etc. in GPU builds, one of them returns true. For CPU builds, they are always false.
Reimplemented in amrex::BArena, amrex::PArena, and amrex::SArena.
|
inlinevirtual |
Is this GPU stream ordered memory allocator?
Reimplemented in amrex::PArena, and amrex::SArena.
|
inlinevirtual |
Return the largest free memory block already held by this Arena.
A return value of 0 means this query is not applicable or unknown.
Reimplemented in amrex::CArena.
|
staticprotected |
|
static |
Print memory usage information of all arenas.
This function reports memory usage statistics for all CArena-based AMReX arenas. It contains MPI collective calls and therefore must be called by all processes. The output is printed on the I/O process only.
Depending on the value of print_max_usage, the function prints either the current memory usage (when false) or the maximum memory usage recorded (when true).
| print_max_usage | whether to print the maximum usage or the current usage |
|
static |
Print memory usage information of all arenas to given file.
This function reports memory usage statistics for all CArena-based AMReX arenas. The output is appended to a file named {filename}.{rank}, where rank is the MPI rank of the process. Unlike PrintUsage, this does not contain MPI calls and therefore may be called independently on individual processes.
| filename | base name of the output file |
| message | message printed at the beginning |
|
static |
Print memory usage information of all arenas to a given output stream.
This function reports memory usage statistics for all CArena-based AMReX arenas. Unlike PrintUsage, this does not contain MPI calls and therefore may be called independently on individual processes.
| os | output stream |
| space | indentation prepended to printed lines |
| void amrex::Arena::registerForProfiling | ( | const std::string & | memory_name | ) |
Add this Arena to the list of Arenas that are profiled by TinyProfiler.
| memory_name | The name of this arena in the TinyProfiler output. |
|
inlinevirtual |
Reset the maximum usage counter. This is no-op in this implementation of the virtual function.
Reimplemented in amrex::CArena.
|
inlinevirtual |
Shrink allocation size in-place.
In this implementation of the virtual function, a new allocation is always performed, and it returns the new pointer. Note that this function does NOT free the existing allocation, so it's the caller's responsibility to free the original pointer when appropriate.
| pt | Existing allocation to be shrunk. |
| sz | Target size for the new allocation. |
Reimplemented in amrex::CArena.
|
virtual |
Reimplemented in amrex::PArena, and amrex::SArena.
|
static |
The alignment of allocated memory 256 bytes is the default alignment that cudaMalloc uses. If the native allocation function were to give memory that has a smaller alignment than align_size, memory from the Arena will also only have this smaller alignment. In practice, native allocation functions have >= 256 bytes of alignment. In all cases, memory should be at least aligned to std::max_align_t, usually 16.
|
protected |