13#ifndef CD_PARTICLEMEMORY_H
14#define CD_PARTICLEMEMORY_H
24#include <CD_NamespaceHeader.H>
67#ifdef CH_USE_MEMORY_TRACKING
77inline std::atomic<std::size_t> s_bytes[
static_cast<int>(
Kind::NumKinds)]{};
82inline std::atomic<std::size_t> s_peak[
static_cast<int>(
Kind::NumKinds)]{};
87inline std::atomic<std::size_t> s_totalBytes{0};
95inline std::atomic<std::size_t> s_totalPeak{0};
108raisePeak([[maybe_unused]] std::atomic<std::size_t>& a_mark, [[maybe_unused]]
const std::size_t a_value)
noexcept
110#ifdef CH_USE_MEMORY_TRACKING
111 std::size_t seen = a_mark.load(std::memory_order_relaxed);
113 while (a_value > seen && !a_mark.compare_exchange_weak(seen, a_value, std::memory_order_relaxed)) {
124addBytes([[maybe_unused]]
const Kind a_kind, [[maybe_unused]]
const std::size_t a_bytes)
noexcept
126#ifdef CH_USE_MEMORY_TRACKING
127 const int k =
static_cast<int>(a_kind);
129 raisePeak(s_peak[k], s_bytes[k].fetch_add(a_bytes, std::memory_order_relaxed) + a_bytes);
130 raisePeak(s_totalPeak, s_totalBytes.fetch_add(a_bytes, std::memory_order_relaxed) + a_bytes);
140removeBytes([[maybe_unused]]
const Kind a_kind, [[maybe_unused]]
const std::size_t a_bytes)
noexcept
142#ifdef CH_USE_MEMORY_TRACKING
143 s_bytes[
static_cast<int>(a_kind)].fetch_sub(a_bytes, std::memory_order_relaxed);
144 s_totalBytes.fetch_sub(a_bytes, std::memory_order_relaxed);
156#ifdef CH_USE_MEMORY_TRACKING
157 return s_bytes[
static_cast<int>(a_kind)].load(std::memory_order_relaxed);
171#ifdef CH_USE_MEMORY_TRACKING
172 return s_peak[
static_cast<int>(a_kind)].load(std::memory_order_relaxed);
185#ifdef CH_USE_MEMORY_TRACKING
186 return s_totalBytes.load(std::memory_order_relaxed);
199#ifdef CH_USE_MEMORY_TRACKING
200 return s_totalPeak.load(std::memory_order_relaxed);
207#include <CD_NamespaceFooter.H>
Running totals of the memory held by particle data on this rank.
Definition CD_ParticleMemory.H:55
std::size_t getPeakBytes() noexcept
Get the high-water mark across all kinds.
Definition CD_ParticleMemory.H:197
std::size_t getBytes(const Kind a_kind) noexcept
Get the bytes currently held by one kind.
Definition CD_ParticleMemory.H:154
void removeBytes(const Kind a_kind, const std::size_t a_bytes) noexcept
Record a release.
Definition CD_ParticleMemory.H:140
void raisePeak(std::atomic< std::size_t > &a_mark, const std::size_t a_value) noexcept
Raise a high-water mark to a_value unless it is already at least that.
Definition CD_ParticleMemory.H:108
std::size_t getPeak(const Kind a_kind) noexcept
Get the high-water mark of one kind.
Definition CD_ParticleMemory.H:169
std::size_t getAllocatedBytes() noexcept
Get the bytes currently held by particle data of every kind.
Definition CD_ParticleMemory.H:183
void addBytes(const Kind a_kind, const std::size_t a_bytes) noexcept
Record an allocation.
Definition CD_ParticleMemory.H:124
Kind
The kinds of particle memory tracked here. See the namespace documentation.
Definition CD_ParticleMemory.H:61
@ Container
ParticleSoA arenas: capacity a rank is holding.
Definition CD_ParticleMemory.H:62
@ NumKinds
Number of kinds.
Definition CD_ParticleMemory.H:64
@ Buffer
Flat exchange buffers: payload in flight.
Definition CD_ParticleMemory.H:63