31#ifndef EBGEOMETRY_POOL_HPP
32#define EBGEOMETRY_POOL_HPP
133#if defined(EBGEOMETRY_DEVICE_COMPILE)
172 attach(
const Pool& a_pool,
const char* a_who,
bool a_deviceWritten =
false) noexcept;
188 rebasedOnto(const
Pool& a_pool, uint64_t a_endByte, const
char* a_who) const noexcept;
191static_assert(std::is_trivially_copyable_v<
PoolLocation>,
192 "
PoolLocation must be trivially copyable, for a kernel to take a handle");
238 operator=(const
Pool&) = delete;
254 operator=(
Pool&& a_other) noexcept;
293 reserve(
size_t a_count,
size_t a_elemSize,
size_t a_alignment);
481 static constexpr
size_t s_maxBytes = SIZE_MAX & ~(
PoolBaseAlign - 1);
507 static std::unique_ptr<PoolControl>
510 static std::atomic<uint64_t> s_nextID{1};
512 auto control = std::make_unique<PoolControl>();
514 control->m_id = s_nextID.fetch_add(1, std::memory_order_relaxed);
515 control->m_rootId = control->m_id;
521 MemoryResource* m_resource =
nullptr;
530 size_t m_capacity = 0;
533 uint64_t m_mirrorOf = 0;
536 bool m_frozen =
false;
585 return m_location.isAttachedTo(a_pool);
641 return m_location.
base();
654 return m_location.base();
665 attach(
const Pool& a_pool,
const char* a_who,
const bool a_deviceWritten =
false) noexcept
667 m_location.attach(a_pool, a_who, a_deviceWritten);
682 return m_location.
rebasedOnto(a_pool, a_endByte, a_who);
693 m_location = a_location;
712#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:269
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:563
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:583
PoolLocation location() const noexcept
Where this handle's arrays live.
Definition EBGeometry_Pool.hpp:571
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:680
const void * base() const noexcept
The base address this handle's offsets resolve against, for read-only access.
Definition EBGeometry_Pool.hpp:652
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
void attach(const Pool &a_pool, const char *a_who, const bool a_deviceWritten=false) noexcept
Follow a_pool, as the first reservation does; see PoolLocation::attach().
Definition EBGeometry_Pool.hpp:665
void * base() noexcept
The base address this handle's offsets resolve against; see PoolLocation::base().
Definition EBGeometry_Pool.hpp:639
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:691
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
size_t capacityBytes() const noexcept
Bytes currently allocated for the block.
Definition EBGeometry_Pool.hpp:393
uint64_t rootId() const noexcept
Identity of the root of this pool's mirror chain.
Definition EBGeometry_Pool.hpp:371
PoolLocation location() const noexcept
A location that follows this pool, for rebuilding a structure from its layout with its (Layout,...
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:328
size_t usedBytes() const noexcept
Bytes currently in use (the bump cursor).
Definition EBGeometry_Pool.hpp:382
bool isFrozen() const noexcept
Whether the pool has been frozen.
Definition EBGeometry_Pool.hpp:404
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:357
uint64_t id() const noexcept
Identity of this pool, unique among all pools constructed in this process.
Definition EBGeometry_Pool.hpp:341
~Pool() noexcept
Destructor. Returns the block to the backing resource.
MemoryResource & resource() const noexcept
The backing memory resource.
Definition EBGeometry_Pool.hpp:415
Pool(MemoryResource &a_resource, size_t a_initialBytes=0)
Construct an empty pool over a_resource, optionally pre-reserving a block.
static Pool forImage(MemoryResource &a_resource, size_t a_bytes)
A pool for the image of a frozen pool: a block of exactly a_bytes from a_resource,...
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:708
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
constexpr PoolLocation() noexcept
An unset location.
Definition EBGeometry_Pool.hpp:110
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:114
void attach(const Pool &a_pool, const char *a_who, bool a_deviceWritten=false) noexcept
Start following a pool, as the descriptor's first reservation from it does.
bool m_hostAccessible
Whether host code may dereference a snapshot's base (managed or mapped memory).
Definition EBGeometry_Pool.hpp:120
void * base() const noexcept
The base address the descriptor's offsets resolve against.
Definition EBGeometry_Pool.hpp:131
void * m_base
Base address captured by a snapshot; null otherwise.
Definition EBGeometry_Pool.hpp:117
bool isAttachedTo(const Pool &a_pool) const noexcept
Whether this location follows the given pool.