Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
amrex::Arena Class Referenceabstract

A virtual base class for objects that manage their own dynamic memory allocation. More...

#include <AMReX_Arena.H>

Inheritance diagram for amrex::Arena:
amrex::BArena amrex::CArena amrex::PArena amrex::SArena

Classes

struct  ArenaProfiler
 

Public Member Functions

virtual ~Arena ()=default
 
 Arena () noexcept=default
 
 Arena (const Arena &rhs)=delete
 
 Arena (Arena &&rhs)=delete
 
Arenaoperator= (const Arena &rhs)=delete
 
Arenaoperator= (Arena &&rhs)=delete
 
virtual void * alloc (std::size_t sz)=0
 
virtual std::pair< void *, std::size_t > alloc_in_place (void *, std::size_t, std::size_t szmax)
 Allocate memory in-place if possible.
 
virtual void * shrink_in_place (void *, std::size_t sz)
 Shrink allocation size in-place.
 
virtual void free (void *pt)=0
 A pure virtual function for deleting the arena pointed to by pt.
 
virtual std::size_t freeUnused ()
 Free unused memory back to the system. Return value is the amount memory freed.
 
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?
 
const ArenaInfoarenaInfo () const
 Return the ArenaInfo object for querying.
 
virtual void ResetMaxUsageCounter ()
 

Static Public Member Functions

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 Public Attributes

static const std::size_t align_size = 16
 The alignment of allocated memory.
 

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
 
struct amrex::Arena::ArenaProfiler m_profiler
 

Detailed Description

A virtual base class for objects that manage their own dynamic memory allocation.

Constructor & Destructor Documentation

◆ ~Arena()

virtual amrex::Arena::~Arena ( )
virtualdefault

◆ Arena() [1/3]

amrex::Arena::Arena ( )
defaultnoexcept

◆ Arena() [2/3]

amrex::Arena::Arena ( const Arena rhs)
delete

◆ Arena() [3/3]

amrex::Arena::Arena ( Arena &&  rhs)
delete

Member Function Documentation

◆ align()

std::size_t amrex::Arena::align ( std::size_t  sz)
static

Given a minimum required arena size of sz bytes, this returns the next largest arena size that will align to align_size bytes.

◆ alloc()

virtual void * amrex::Arena::alloc ( std::size_t  sz)
pure virtual

Allocate a dynamic memory arena

Parameters
szsize of the memory request
Returns
a pointer to the allocated memory

Implemented in amrex::CArena, amrex::PArena, amrex::BArena, and amrex::SArena.

◆ alloc_in_place()

virtual std::pair< void *, std::size_t > amrex::Arena::alloc_in_place ( void *  ,
std::size_t  ,
std::size_t  szmax 
)
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.

Reimplemented in amrex::CArena.

◆ allocate_system()

void * amrex::Arena::allocate_system ( std::size_t  nbytes)
protected

◆ arenaInfo()

const ArenaInfo & amrex::Arena::arenaInfo ( ) const
inline

Return the ArenaInfo object for querying.

◆ deallocate_system()

void amrex::Arena::deallocate_system ( void *  p,
std::size_t  nbytes 
)
protected

◆ deregisterFromProfiling()

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.

◆ Finalize()

void amrex::Arena::Finalize ( )
static

Used internally by amrex.

◆ free()

virtual void amrex::Arena::free ( void *  pt)
pure virtual

A pure virtual function for deleting the arena pointed to by pt.

Implemented in amrex::PArena, amrex::BArena, amrex::SArena, and amrex::CArena.

◆ freeUnused()

virtual std::size_t amrex::Arena::freeUnused ( )
inlinevirtual

Free unused memory back to the system. Return value is the amount memory freed.

Reimplemented in amrex::CArena.

◆ freeUnused_protected()

virtual std::size_t amrex::Arena::freeUnused_protected ( )
inlineprotectedvirtual

Reimplemented in amrex::CArena.

◆ hasFreeDeviceMemory()

bool amrex::Arena::hasFreeDeviceMemory ( std::size_t  sz)
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.

Reimplemented in amrex::CArena.

◆ Initialize()

void amrex::Arena::Initialize ( bool  minimal)
static

Used internally by amrex.

◆ isDevice()

bool amrex::Arena::isDevice ( ) const
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.

◆ isDeviceAccessible()

bool amrex::Arena::isDeviceAccessible ( ) const
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.

◆ isHostAccessible()

bool amrex::Arena::isHostAccessible ( ) const
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.

◆ isManaged()

bool amrex::Arena::isManaged ( ) const
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.

◆ isPinned()

bool amrex::Arena::isPinned ( ) const
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.

◆ isStreamOrderedArena()

virtual bool amrex::Arena::isStreamOrderedArena ( ) const
inlinevirtual

Is this GPU stream ordered memory allocator?

Reimplemented in amrex::PArena, and amrex::SArena.

◆ operator=() [1/2]

Arena & amrex::Arena::operator= ( Arena &&  rhs)
delete

◆ operator=() [2/2]

Arena & amrex::Arena::operator= ( const Arena rhs)
delete

◆ out_of_memory_abort()

void amrex::Arena::out_of_memory_abort ( std::string const &  memory_type,
std::size_t  nbytes,
std::string const &  error_msg 
)
staticprotected

◆ PrintUsage()

void amrex::Arena::PrintUsage ( bool  print_max_usage = false)
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 recoreded (when true).

Parameters
print_max_usagewhether to print the maximum usage or the current usage

◆ PrintUsageToFiles()

void amrex::Arena::PrintUsageToFiles ( std::string const &  filename,
std::string const &  message 
)
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.

Parameters
filenamebase name of the output file
messagemessage printed at the beginning

◆ PrintUsageToStream()

void amrex::Arena::PrintUsageToStream ( std::ostream &  os,
std::string const &  space 
)
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.

Parameters
osoutput stream
spaceindentation prepended to printed lines

◆ registerForProfiling()

void amrex::Arena::registerForProfiling ( const std::string &  memory_name)

Add this Arena to the list of Arenas that are profiled by TinyProfiler.

Parameters
memory_nameThe name of this arena in the TinyProfiler output.

◆ ResetMaxUsageCounter()

virtual void amrex::Arena::ResetMaxUsageCounter ( )
inlinevirtual

Reset the maximum usage counter. This is no-op in this implementation of the virtual function.

Reimplemented in amrex::CArena.

◆ shrink_in_place()

virtual void * amrex::Arena::shrink_in_place ( void *  ,
std::size_t  sz 
)
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.

Reimplemented in amrex::CArena.

Member Data Documentation

◆ align_size

const std::size_t amrex::Arena::align_size = 16
static

The alignment of allocated memory.

◆ arena_info

ArenaInfo amrex::Arena::arena_info
protected

◆ m_profiler

struct amrex::Arena::ArenaProfiler amrex::Arena::m_profiler
protected

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