31#ifndef EBGEOMETRY_POOL_HPP
32#define EBGEOMETRY_POOL_HPP
120#if defined(EBGEOMETRY_DEVICE_COMPILE)
170 rebasedOnto(
const Pool& a_pool, uint64_t a_endByte,
const char* a_who)
const noexcept;
213 operator=(const
Pool&) = delete;
229 operator=(
Pool&& a_other) noexcept;
268 reserve(
size_t a_count,
size_t a_elemSize,
size_t a_alignment);
289 return (m_control !=
nullptr) ? m_control->m_base :
nullptr;
305 return m_control.get();
318 return (m_control !=
nullptr) ? m_control->m_id : 0;
348 return (m_control !=
nullptr) ? m_control->m_rootId : 0;
417 static constexpr size_t s_maxBytes = SIZE_MAX & ~(
PoolBaseAlign - 1);
432 Pool(
MemoryResource& a_resource, MirrorTag) : m_resource(&a_resource), m_control(makeControl())
443 static std::unique_ptr<PoolControl>
446 static std::atomic<uint64_t> s_nextID{1};
448 auto control = std::make_unique<PoolControl>();
450 control->
m_id = s_nextID.fetch_add(1, std::memory_order_relaxed);
457 MemoryResource* m_resource =
nullptr;
460 std::unique_ptr<PoolControl> m_control;
466 size_t m_capacity = 0;
469 uint64_t m_mirrorOf = 0;
472 bool m_frozen =
false;
577 return m_location.
base();
590 return m_location.
base();
602 m_location.
attach(a_pool, a_who);
617 return m_location.
rebasedOnto(a_pool, a_endByte, a_who);
628 m_location = a_location;
647#include "EBGeometry_PoolImplem.hpp"
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Utility macros for EBGeometry.
#define EBGEOMETRY_EXPECT(cond)
Runtime precondition assertion for EBGeometry.
Definition EBGeometry_Macros.hpp:155
Placement-policy layer for the GPU memory foundation: the abstract MemoryResource and its concrete ho...
Abstract placement policy: allocates and frees raw, correctly-aligned byte blocks.
Definition EBGeometry_MemoryResource.hpp:69
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:499
PoolHandle(PoolHandle &&) noexcept=default
Move a handle; the same as a copy.
bool isAttachedTo(const Pool &a_pool) const noexcept
Check whether this handle's arrays were reserved from a_pool.
Definition EBGeometry_Pool.hpp:519
PoolLocation location() const noexcept
Where this handle's arrays live.
Definition EBGeometry_Pool.hpp:507
PoolHandle(const PoolHandle &) noexcept=default
Copy a handle, as a derived handle's copy does.
PoolLocation rebasedLocation(const Pool &a_pool, uint64_t a_endByte, const char *a_who) const noexcept
The location of this handle's arrays in another pool of its mirror chain; see PoolLocation::rebasedOn...
Definition EBGeometry_Pool.hpp:615
void attach(const Pool &a_pool, const char *a_who) noexcept
Follow a_pool, as the first reservation does; see PoolLocation::attach().
Definition EBGeometry_Pool.hpp:600
const void * base() const noexcept
The base address this handle's offsets resolve against, for read-only access.
Definition EBGeometry_Pool.hpp:588
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
void * base() noexcept
The base address this handle's offsets resolve against; see PoolLocation::base().
Definition EBGeometry_Pool.hpp:575
void setLocation(const PoolLocation &a_location) noexcept
Replace the location, for a view or a copy made by a derived handle.
Definition EBGeometry_Pool.hpp:626
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:183
size_t capacityBytes() const noexcept
Bytes currently allocated for the block.
Definition EBGeometry_Pool.hpp:368
void * base() const noexcept
Base address of the block.
Definition EBGeometry_Pool.hpp:287
uint64_t rootId() const noexcept
Identity of the root of this pool's mirror chain.
Definition EBGeometry_Pool.hpp:346
static Pool mirror(const Pool &a_src, MemoryResource &a_dstResource)
Mirror a frozen pool's whole block into another resource.
const PoolControl * control() const noexcept
This pool's stable control block, through which pool-resident objects re-resolve the base on every ac...
Definition EBGeometry_Pool.hpp:303
size_t usedBytes() const noexcept
Bytes currently in use (the bump cursor).
Definition EBGeometry_Pool.hpp:357
bool isFrozen() const noexcept
Whether the pool has been frozen.
Definition EBGeometry_Pool.hpp:379
uint64_t mirrorOf() const noexcept
Identity of the pool this one ultimately mirrors, or zero if it is not a mirror.
Definition EBGeometry_Pool.hpp:332
uint64_t id() const noexcept
Identity of this pool, unique among all pools constructed in this process.
Definition EBGeometry_Pool.hpp:316
~Pool() noexcept
Destructor. Returns the block to the backing resource.
MemoryResource & resource() const noexcept
The backing memory resource.
Definition EBGeometry_Pool.hpp:390
Pool(MemoryResource &a_resource, size_t a_initialBytes=0)
Construct an empty pool over a_resource, optionally pre-reserving a block.
uint64_t reserve(size_t a_count, size_t a_elemSize, size_t a_alignment)
Bump-reserve a_count * a_elemSize bytes aligned to a_alignment.
void freeze() noexcept
Freeze the block: forbid further reserve, stabilize base, enable mirror.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
constexpr size_t PoolBaseAlign
Block-base alignment for every Pool, in bytes.
Definition EBGeometry_MemoryResource.hpp:52
constexpr bool isPoolHandle
Whether P is a pool-resident handle (derives from PoolHandle).
Definition EBGeometry_Pool.hpp:643
Stable, heap-resident handle to a Pool's current base address and identity.
Definition EBGeometry_Pool.hpp:63
uint64_t m_id
Identity of the owning pool; see Pool::id. Never zero for a live pool.
Definition EBGeometry_Pool.hpp:69
void * m_base
Current base address of the owning pool's block. Rewritten whenever a Pool::reserve grows the block.
Definition EBGeometry_Pool.hpp:66
uint64_t m_rootId
Identity of the root of the owning pool's mirror chain: its own identity for a pool that is not a mir...
Definition EBGeometry_Pool.hpp:73
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99
PoolLocation rebasedOnto(const Pool &a_pool, uint64_t a_endByte, const char *a_who) const noexcept
The location of the same arrays in another pool of the same mirror chain.
const PoolControl * m_control
Control block of the pool the descriptor follows; null for a snapshot or when unset.
Definition EBGeometry_Pool.hpp:101
bool m_hostAccessible
Whether host code may dereference a snapshot's base (managed or mapped memory).
Definition EBGeometry_Pool.hpp:107
void attach(const Pool &a_pool, const char *a_who) noexcept
Start following a pool, as the descriptor's first reservation from it does.
void * base() const noexcept
The base address the descriptor's offsets resolve against.
Definition EBGeometry_Pool.hpp:118
void * m_base
Base address captured by a snapshot; null otherwise.
Definition EBGeometry_Pool.hpp:104
bool isAttachedTo(const Pool &a_pool) const noexcept
Whether this location follows the given pool.