3 #include <AMReX_Config.H>
8 #ifdef AMREX_TINY_PROFILING
21 #include <unordered_map>
30 inline std::size_t
aligned_size (std::size_t align_requirement, std::size_t
size) noexcept
32 return ((
size + (align_requirement-1)) / align_requirement) * align_requirement;
35 inline bool is_aligned (
const void* p, std::size_t alignment) noexcept
37 auto* q =
const_cast<void*
>(p);
38 auto space = alignment;
39 return std::align(alignment, alignment, q, space) == p;
116 [[nodiscard]] virtual
void*
alloc (std::
size_t sz) = 0;
121 [[nodiscard]] virtual std::pair<
void*,std::
size_t>
124 auto* p =
alloc(szmax);
125 return std::make_pair(p, szmax);
131 [[nodiscard]]
virtual void*
140 virtual void free (
void* pt) = 0;
155 [[nodiscard]]
virtual bool isManaged ()
const;
156 [[nodiscard]]
virtual bool isDevice ()
const;
157 [[nodiscard]]
virtual bool isPinned ()
const;
188 static std::size_t
align (std::size_t sz);
192 static void PrintUsageToFiles (std::string
const& filename, std::string
const& message);
203 static const std::size_t
align_size =
sizeof(Word);
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
A virtual base class for objects that manage their own dynamic memory allocation.
Definition: AMReX_Arena.H:100
static void Finalize()
Definition: AMReX_Arena.cpp:549
virtual void free(void *pt)=0
A pure virtual function for deleting the arena pointed to by pt.
const ArenaInfo & arenaInfo() const
Return the ArenaInfo object for querying.
Definition: AMReX_Arena.H:211
virtual void * shrink_in_place(void *, std::size_t sz)
Definition: AMReX_Arena.H:132
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 a...
Definition: AMReX_Arena.cpp:143
virtual bool isPinned() const
Definition: AMReX_Arena.cpp:103
virtual bool isHostAccessible() const
Definition: AMReX_Arena.cpp:67
virtual bool isStreamOrderedArena() const
Is this GPU stream ordered memory allocator?
Definition: AMReX_Arena.H:181
virtual void * alloc(std::size_t sz)=0
static const std::size_t align_size
Definition: AMReX_Arena.H:206
static void PrintUsage()
Definition: AMReX_Arena.cpp:432
virtual bool isManaged() const
Definition: AMReX_Arena.cpp:79
void deregisterFromProfiling()
Remove this Arena from the list of Arenas that are profiled by TinyProfiler. This is equivalent to de...
Definition: AMReX_Arena.cpp:130
virtual std::size_t freeUnused_protected()
Definition: AMReX_Arena.H:217
void registerForProfiling(const std::string &memory_name)
Add this Arena to the list of Arenas that are profiled by TinyProfiler.
Definition: AMReX_Arena.cpp:120
static void Initialize()
Definition: AMReX_Arena.cpp:283
static void PrintUsageToFiles(std::string const &filename, std::string const &message)
Definition: AMReX_Arena.cpp:495
virtual bool isDevice() const
Definition: AMReX_Arena.cpp:91
virtual std::pair< void *, std::size_t > alloc_in_place(void *, std::size_t, std::size_t szmax)
Definition: AMReX_Arena.H:122
virtual bool hasFreeDeviceMemory(std::size_t sz)
Does the device have enough free memory for allocating this much memory? For CPU builds,...
Definition: AMReX_Arena.cpp:114
void deallocate_system(void *p, std::size_t nbytes)
Definition: AMReX_Arena.cpp:232
struct amrex::Arena::ArenaProfiler m_profiler
virtual std::size_t freeUnused()
Free unused memory back to the system. Return value is the amount memory freed.
Definition: AMReX_Arena.H:146
ArenaInfo arena_info
Definition: AMReX_Arena.H:215
virtual bool isDeviceAccessible() const
Definition: AMReX_Arena.cpp:57
void * allocate_system(std::size_t nbytes)
Definition: AMReX_Arena.cpp:149
AMREX_GPU_HOST_DEVICE Long size(T const &b) noexcept
integer version
Definition: AMReX_GpuRange.H:26
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
@ max
Definition: AMReX_ParallelReduce.H:17
Definition: AMReX_Amr.cpp:49
bool is_aligned(const void *p, std::size_t alignment) noexcept
Definition: AMReX_Arena.H:35
Arena * The_Managed_Arena()
Definition: AMReX_Arena.cpp:639
Arena * The_Comms_Arena()
Definition: AMReX_Arena.cpp:669
Arena * The_Device_Arena()
Definition: AMReX_Arena.cpp:629
Arena * The_Pinned_Arena()
Definition: AMReX_Arena.cpp:649
Arena * The_Async_Arena()
Definition: AMReX_Arena.cpp:619
std::size_t aligned_size(std::size_t align_requirement, std::size_t size) noexcept
Given a minimum required size of size bytes, this returns the next largest arena size that will align...
Definition: AMReX_Arena.H:30
Arena * The_Cpu_Arena()
Definition: AMReX_Arena.cpp:659
Arena * The_Arena()
Definition: AMReX_Arena.cpp:609
Definition: AMReX_Arena.H:53
bool device_set_preferred
Definition: AMReX_Arena.H:58
bool device_set_readonly
Definition: AMReX_Arena.H:57
ArenaInfo & SetReadOnly() noexcept
Definition: AMReX_Arena.H:69
bool device_use_hostalloc
Definition: AMReX_Arena.H:59
Long release_threshold
Definition: AMReX_Arena.H:54
ArenaInfo & SetReleaseThreshold(Long rt) noexcept
Definition: AMReX_Arena.H:60
ArenaInfo & SetDeviceMemory() noexcept
Definition: AMReX_Arena.H:64
ArenaInfo & SetHostAlloc() noexcept
Definition: AMReX_Arena.H:79
ArenaInfo & SetPreferred() noexcept
Definition: AMReX_Arena.H:74
bool device_use_managed_memory
Definition: AMReX_Arena.H:56
bool use_cpu_memory
Definition: AMReX_Arena.H:55
ArenaInfo & SetCpuMemory() noexcept
Definition: AMReX_Arena.H:84
Definition: AMReX_Arena.H:221
std::map< std::string, MemStat > m_profiling_stats
Data structure used for profiling with TinyProfiler.
Definition: AMReX_Arena.H:227
void profile_alloc(void *ptr, std::size_t nbytes)
Definition: AMReX_Arena.cpp:693
void profile_free(void *ptr)
Definition: AMReX_Arena.cpp:706
std::unordered_map< void *, std::pair< MemStat *, std::size_t > > m_currently_allocated
Track the currently allocated memory, not used by CArena.
Definition: AMReX_Arena.H:229
bool m_do_profiling
If this arena is profiled by TinyProfiler.
Definition: AMReX_Arena.H:223
std::mutex m_arena_profiler_mutex
Mutex for the profiling.
Definition: AMReX_Arena.H:225
ArenaProfiler() noexcept=default
Definition: AMReX_Arena.H:12