Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
amrex::SArena Class Reference

A STREAM-ordered memory arena. More...

#include <AMReX_SArena.H>

Inheritance diagram for amrex::SArena:
amrex::Arena

Public Member Functions

void * alloc (std::size_t sz) final
 Allocates dynamic memory from the arena of size sz. Returns a pointer to this memory. The memory can be used immediately by both the CPU and GPU with any stream. This function may synchronize all GPU streams to free up memory.
 
void free (void *pt) final
 Deletes the arena pointed to by pt. After this function is called, the memory can still be used by already launched GPU kernels on the currently active stream. This function may synchronize the currently active GPU stream to free up memory.
 
bool isDeviceAccessible () const final
 
bool isHostAccessible () const final
 
bool isManaged () const final
 Check whether it is managed GPU memory.
 
bool isDevice () const final
 Check whether it is non-managed GPU device memory.
 
bool isPinned () const final
 Check whether it is pinned host memory.
 
bool isStreamOrderedArena () const final
 Is this a GPU stream ordered memory allocator?
 
- Public Member Functions inherited from amrex::Arena
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 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 std::size_t freeUnused ()
 Free unused memory back to the system. Return value is the amount memory freed.
 
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.
 
const ArenaInfoarenaInfo () const
 Return the ArenaInfo object for querying.
 
virtual void ResetMaxUsageCounter ()
 

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.
 
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 inherited from amrex::Arena
static const std::size_t align_size = 16
 The alignment of allocated memory.
 
- Protected Member Functions inherited from amrex::Arena
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 inherited from amrex::Arena
static void out_of_memory_abort (std::string const &memory_type, std::size_t nbytes, std::string const &error_msg)
 
- Protected Attributes inherited from amrex::Arena
ArenaInfo arena_info
 
struct amrex::Arena::ArenaProfiler m_profiler
 

Detailed Description

A STREAM-ordered memory arena.

This Arena is implemented as a wrapper around amrex::The_Arena() where the free() function calls amrex::Gpu::freeAsync(). This allows memory to be used by GPU kernels that were launched before free() was called but may execute afterward, without calling amrex::Gpu::streamSynchronize(). These kernels need to use the same GPU stream that is active when free() is called, otherwise explicit synchronization is needed.

This is achieved by holding freed memory in a temporary buffer until the next time the GPU stream is synchronized. In case too much memory is held up in this buffer or if The_Arena needs more memory, the stream is automatically synchronized to clear the buffer.

Member Function Documentation

◆ alloc()

void * amrex::SArena::alloc ( std::size_t  sz)
finalvirtual

Allocates dynamic memory from the arena of size sz. Returns a pointer to this memory. The memory can be used immediately by both the CPU and GPU with any stream. This function may synchronize all GPU streams to free up memory.

Implements amrex::Arena.

◆ free()

void amrex::SArena::free ( void *  pt)
finalvirtual

Deletes the arena pointed to by pt. After this function is called, the memory can still be used by already launched GPU kernels on the currently active stream. This function may synchronize the currently active GPU stream to free up memory.

Implements amrex::Arena.

◆ isDevice()

bool amrex::SArena::isDevice ( ) const
finalvirtual

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 from amrex::Arena.

◆ isDeviceAccessible()

bool amrex::SArena::isDeviceAccessible ( ) const
finalvirtual

Check whether the memory is accessible on the device. Note that isDeviceAccessible and isHostAccessible can both be true.

Reimplemented from amrex::Arena.

◆ isHostAccessible()

bool amrex::SArena::isHostAccessible ( ) const
finalvirtual

Check whether the memory is accessible on the host. Note that isDeviceAccessible and isHostAccessible can both be true.

Reimplemented from amrex::Arena.

◆ isManaged()

bool amrex::SArena::isManaged ( ) const
finalvirtual

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 from amrex::Arena.

◆ isPinned()

bool amrex::SArena::isPinned ( ) const
finalvirtual

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 from amrex::Arena.

◆ isStreamOrderedArena()

bool amrex::SArena::isStreamOrderedArena ( ) const
inlinefinalvirtual

Is this a GPU stream ordered memory allocator?

Reimplemented from amrex::Arena.


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