Resource Pools#

class ResourcePools#

Host-side allocation and reference accounting for all context-cache storage types.

Each ResourceType has an independent fixed-capacity pool and circular free list. ResourcePools manages only IDs and reference counts; the corresponding GPU buffers are allocated and bound by the runtime. An active reference pins a resource for an in-flight request, while a cache reference retains it for a published CacheRecord. A resource returns to its free list only when both counts reach zero.

Multi-pool allocation is all-or-nothing. Valid releases do not allocate and cannot fail after their preconditions have been checked.

Public Functions

explicit ResourcePools(ResourceDemand capacities)#
std::optional<std::vector<ResourceId>> allocate(
ResourceDemand const &demand
)#

Atomically allocate the full typed demand with active=1 and cache=0, or return nullopt without mutation.

bool allocateInto(
ResourceDemand const &demand,
std::vector<ResourceId> &resources
)#

Fill caller-owned storage and commit without dynamic memory allocation. The output vector must already match the total demand; insufficient capacity returns false without mutation.

void addActiveRef(ResourceId const &resource)#

Pin an allocated resource for an active request.

void releaseActiveRef(ResourceId const &resource)#

Drop an active pin, returning the resource to the free list only when both reference counts reach zero.

void addCacheRef(ResourceId const &resource)#

Add published-record ownership to an allocated resource.

void releaseCacheRef(ResourceId const &resource)#

Drop published ownership, returning the resource to the free list only when both reference counts reach zero.

int32_t activeRefCount(ResourceId const &resource) const#
int32_t cacheRefCount(ResourceId const &resource) const#
int32_t freeCount(ResourceType type) const noexcept#
int32_t capacity(ResourceType type) const noexcept#
bool canAllocate(ResourceDemand const &demand) const noexcept#