Context Cache Coordinator#

class ContextCacheCoordinator#

Owns the complete host/device lifecycle around the CUDA-free ContextCacheManager.

The coordinator has no worker and is deliberately single-request-at-a-time under the runtime’s serialized request contract. Normal publication occurs only at host-visible completion points already present in the runtime. An abnormal exit drains the bound stream before releasing active page references; a failed drain quarantines the entire request and poisons the coordinator until runtime-owned shutdown can establish quiescence.

Public Types

using StreamSynchronizer = std::function<cudaError_t(cudaStream_t)>#

Public Functions

ContextCacheCoordinator(
ContextCacheConfig const &config,
DeploymentConfig const &deployment,
ContextCacheDeploymentProfile profile,
ContextCachePhysicalResources resources,
cudaStream_t stream,
StreamSynchronizer synchronizer = {}
)#
~ContextCacheCoordinator() noexcept#
ContextCacheCoordinator(ContextCacheCoordinator const&) = delete#
ContextCacheCoordinator &operator=(
ContextCacheCoordinator const&
) = delete#
BeginRequestResult beginRequest(
ContextCacheBatchAdmission const &admission,
DecodingKvHeadroom const &headroom,
cudaStream_t stream
)#
ContextCacheCoordinatorStatus preparePrefill(RequestHandle &request)#

Bind every admitted row and reset logical cache lengths to the selected reuse boundaries.

ContextCacheCoordinatorStatus enqueuePrefillCaptures(
RequestHandle &request
)#

Reserve and enqueue hybrid prefill-end snapshots before the runtime’s existing prefill synchronization.

ContextCacheCoordinatorStatus finalizePrefillPublication(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const *commonStateLengths = nullptr
)#

Apply the post-prefill sequence advance and publish every ready full-block endpoint. For EAGLE, commonStateLengths caps publication at the prefix materialized by both base and draft state.

ContextCacheCoordinatorStatus publishHybridMtpEndpoint(
RequestHandle &request,
int32_t slot,
int32_t residentStateLength,
Tensor const &baseHiddenStates,
int32_t boundaryHiddenRow
)#

Publish one Hybrid+MTP checkpoint at the stable predecessor boundary. This is the dedicated MTP publication entrypoint; the runtime drives it after the folded draft prefill has materialized the boundary draft state. It captures the recurrent state, the paired base+draft partial pages, and the successor-dependent boundary base-hidden row, then commits the exact checkpoint. Skipped for bypass, already-published, or empty prefixes.

ContextCacheCoordinatorStatus restoreHybridMtpBoundaryHidden(
RequestHandle &request,
int32_t slot,
Tensor &baseHiddenStates,
int32_t destinationRow
)#

Restore the checkpoint’s saved boundary base-hidden row into baseHiddenStates[slot, destinationRow, :] for the runtime’s fold micro-forward. No synchronization: the caller orders this within its prefill stream.

ContextCacheCoordinatorStatus prepareDecodeStep(
RequestHandle &request,
DecodingKvHeadroom const &headroom
)#

Grow and upload every row needed for the next decode working set before model execution.

ContextCacheCoordinatorStatus completeDecodeStep(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const &publishableCompletedSlots,
std::vector<int32_t> const *commonStateLengths = nullptr
)#

Apply the post-decode sequence advance after the decoder’s existing synchronization. For EAGLE, commonStateLengths excludes any unmaterialized accepted suffix and speculative lookahead.

ContextCacheCoordinatorStatus beginBatchCompaction(
RequestHandle &request,
std::vector<int32_t> const &oldToNew,
int32_t newBatchSize,
Tensor &deviceBatchMapping
)#

Validate and upload the one authoritative old-to-new mapping before any old-slot compaction work.

ContextCacheCoordinatorStatus compactBatch(RequestHandle &request)#

Compact slot-addressed state/page-table rows, retire leases, and consume the existing eviction sync.

ContextCacheCoordinatorStatus finish(RequestHandle &request)#

Consume a normally completed request. This is idempotent for an already-empty handle.

ContextCacheCoordinatorStatus shutdown() noexcept#

Drain quarantined ownership before physical cache resources are destroyed.

ContextCacheMetrics metrics() const noexcept#
ContextCacheManager const &manager() const noexcept#
struct AcquireSequenceResult#

Public Members

std::optional<CacheRequestLease> lease#
AcquireStatus status = {AcquireStatus::kInsufficientCapacity}#
ReusePlan plan#
bool forcedCold = {}#
struct AdmissionResult#

Public Members

RequestHandle request#
std::vector<int32_t> prefillStarts#

Per-sequence logical token offset at which runtime prefill begins.

class BaseEndpointPolicy : public trt_edgellm::rt::ContextCacheCoordinator::PublicationPolicy#

Public Functions

inline virtual char const *name() const noexcept override#
inline virtual void onPrefillFinalized(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-prefill advance and publish (or arm) every ready endpoint for this flavor.

inline virtual ContextCacheCoordinatorStatus onDecodeCompleted(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const &publishableCompletedSlots,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-decode advance and publish endpoints for the completed slots.

inline explicit PublicationPolicy(
ContextCacheCoordinator &coordinator
) noexcept#
struct BeginRequestResult#

Public Members

ContextCacheCoordinatorStatus status = {ContextCacheCoordinatorStatus::kRequestFailed}#
std::optional<AdmissionResult> admission#
class EagleSpecPolicy : public trt_edgellm::rt::ContextCacheCoordinator::PublicationPolicy#

Public Functions

inline virtual char const *name() const noexcept override#
inline virtual void onPrefillFinalized(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-prefill advance and publish (or arm) every ready endpoint for this flavor.

inline virtual ContextCacheCoordinatorStatus onDecodeCompleted(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const &publishableCompletedSlots,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-decode advance and publish endpoints for the completed slots.

inline virtual ContextCacheCoordinatorStatus onTerminalize(
RequestHandle &request
) override#

EAGLE-only: publish the frozen prefill once the first verification round terminalizes. Default no-op.

inline explicit PublicationPolicy(
ContextCacheCoordinator &coordinator
) noexcept#
class HybridMtpPolicy : public trt_edgellm::rt::ContextCacheCoordinator::HybridSnapshotPolicy#

Public Functions

inline virtual char const *name() const noexcept override#
inline virtual ContextCacheCoordinatorStatus publishMtpBoundary(
RequestHandle &request,
int32_t slot,
int32_t residentStateLength,
Tensor const &baseHiddenStates,
int32_t boundaryHiddenRow
) override#

Hybrid+MTP-only: publish the successor-boundary checkpoint. Unreachable for other flavors.

inline virtual ContextCacheCoordinatorStatus restoreMtpBoundary(
RequestHandle &request,
int32_t slot,
Tensor &baseHiddenStates,
int32_t destinationRow
) override#

Hybrid+MTP-only: restore the checkpoint’s saved boundary hidden row. Unreachable for other flavors.

class HybridSnapshotPolicy : public trt_edgellm::rt::ContextCacheCoordinator::PublicationPolicy#

Subclassed by trt_edgellm::rt::ContextCacheCoordinator::HybridMtpPolicy

Public Functions

inline virtual char const *name() const noexcept override#
inline virtual void onPrefillFinalized(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-prefill advance and publish (or arm) every ready endpoint for this flavor.

inline virtual ContextCacheCoordinatorStatus onDecodeCompleted(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const &publishableCompletedSlots,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-decode advance and publish endpoints for the completed slots.

inline explicit PublicationPolicy(
ContextCacheCoordinator &coordinator
) noexcept#
class PublicationPolicy#

Subclassed by trt_edgellm::rt::ContextCacheCoordinator::BaseEndpointPolicy, trt_edgellm::rt::ContextCacheCoordinator::EagleSpecPolicy, trt_edgellm::rt::ContextCacheCoordinator::HybridSnapshotPolicy, trt_edgellm::rt::ContextCacheCoordinator::SharedKvSpecPolicy

Public Functions

inline explicit PublicationPolicy(
ContextCacheCoordinator &coordinator
) noexcept#
virtual ~PublicationPolicy() noexcept = default#
virtual char const *name() const noexcept = 0#
virtual void onPrefillFinalized(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const *commonStateLengths
) = 0#

Apply the post-prefill advance and publish (or arm) every ready endpoint for this flavor.

virtual ContextCacheCoordinatorStatus onDecodeCompleted(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const &publishableCompletedSlots,
std::vector<int32_t> const *commonStateLengths
) = 0#

Apply the post-decode advance and publish endpoints for the completed slots.

inline virtual ContextCacheCoordinatorStatus onTerminalize(
RequestHandle&
)#

EAGLE-only: publish the frozen prefill once the first verification round terminalizes. Default no-op.

inline virtual ContextCacheCoordinatorStatus publishMtpBoundary(
RequestHandle&,
int32_t,
int32_t,
Tensor const&,
int32_t
)#

Hybrid+MTP-only: publish the successor-boundary checkpoint. Unreachable for other flavors.

inline virtual ContextCacheCoordinatorStatus restoreMtpBoundary(
RequestHandle&,
int32_t,
Tensor&,
int32_t
)#

Hybrid+MTP-only: restore the checkpoint’s saved boundary hidden row. Unreachable for other flavors.

class RequestHandle#

Public Functions

RequestHandle(RequestHandle &&other) noexcept#
RequestHandle &operator=(RequestHandle &&other) = delete#
RequestHandle(RequestHandle const&) = delete#
RequestHandle &operator=(RequestHandle const&) = delete#
~RequestHandle() noexcept#
bool valid() const noexcept#
struct Impl#

Public Types

enum class Phase : uint8_t#

Values:

enumerator kAdmitted#
enumerator kExecuting#
enumerator kFinishing#

Public Functions

inline explicit Impl(
ContextCacheCoordinator &coordinator,
cudaStream_t requestStream
) noexcept#
inline bool admitted() const noexcept#
inline bool executing() const noexcept#
inline bool hasPendingDeviceWork() const noexcept#
inline bool awaitingFirstSpecCompletion() const noexcept#
inline void beginPrefill() noexcept#

kAdmitted -> kExecuting with the prefill work enqueued on the stream.

inline void markDeviceWorkEnqueued() noexcept#

Fresh GPU work was enqueued on impl.stream (prefill grow, decode grow, fold, compaction copy).

inline void markDeviceWorkSynchronized() noexcept#

impl.stream was explicitly synchronized (or a verification round already synchronized it).

inline void markDeviceWorkResolvedWithoutSync() noexcept#

The enqueued work is provably terminal without a coordinator synchronize (no async publish work remains).

inline void beginSpecDraftInit() noexcept#

EAGLE only: the ordered draft initialization awaits its first verification round before publishing.

inline void endSpecDraftInit() noexcept#
inline void markFinishing() noexcept#

Enter the terminal phase (normal completion at empty batch, or an unrecoverable capacity/growth failure).

Public Members

RequestSlotToken requestSlot#

Declared before sequences so its destructor clears the admission flag only after every lease is released.

ContextCacheCoordinator *owner = {}#
cudaStream_t stream = {}#
bool speculativeRequest = {}#
std::vector<int32_t> pendingCompactionMapping#
int32_t pendingCompactionBatchSize = {-1}#
Tensor const *pendingDeviceBatchMapping = {}#
std::vector<SequenceState> sequences#
struct RequestSlotToken#

Public Functions

inline explicit RequestSlotToken(
ContextCacheCoordinator &coordinator
) noexcept#
inline RequestSlotToken(RequestSlotToken &&other) noexcept#
RequestSlotToken &operator=(RequestSlotToken&&) = delete#
RequestSlotToken(RequestSlotToken const&) = delete#
RequestSlotToken &operator=(RequestSlotToken const&) = delete#
inline ~RequestSlotToken() noexcept#

Public Members

ContextCacheCoordinator *owner = {}#
struct SequenceState#

Public Members

CacheRequestLease lease#
std::vector<int32_t> tokenIds#
BlockKeyExtras keyExtras#
std::vector<Hash128> perPositionMediaHash#
int32_t reuseTokenLength = {}#
ContextCacheLookupPolicy lookupPolicy = {ContextCacheLookupPolicy::kUseCache}#
ContextCacheCommitPolicy commitPolicy = {ContextCacheCommitPolicy::kIncludingGeneratedTokens}#
int32_t replayTailLength = {}#
int32_t committedStateLength = {}#
int32_t publishedFullBlockCount = {}#
int32_t publishedExactLength = {}#
int32_t commonStateLength = {}#
std::optional<int32_t> frozenSpecPrefillLength#
std::optional<StagedHybridPublication> stagedHybridPublication#
struct StagedHybridPublication#

Public Members

HybridCheckpointKey checkpoint#
HybridSnapshotReservation snapshots#
PublicationPoint point = {}#
class SharedKvSpecPolicy : public trt_edgellm::rt::ContextCacheCoordinator::PublicationPolicy#

Public Functions

inline virtual char const *name() const noexcept override#
inline virtual void onPrefillFinalized(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-prefill advance and publish (or arm) every ready endpoint for this flavor.

inline virtual ContextCacheCoordinatorStatus onDecodeCompleted(
RequestHandle &request,
std::vector<ContextCacheSequenceAdvance> const &advances,
std::vector<int32_t> const &publishableCompletedSlots,
std::vector<int32_t> const *commonStateLengths
) override#

Apply the post-decode advance and publish endpoints for the completed slots.

inline virtual ContextCacheCoordinatorStatus onTerminalize(
RequestHandle &request
) override#

EAGLE-only: publish the frozen prefill once the first verification round terminalizes. Default no-op.

inline explicit PublicationPolicy(
ContextCacheCoordinator &coordinator
) noexcept#
class RequestHandle

Public Functions

RequestHandle(RequestHandle &&other) noexcept
RequestHandle &operator=(RequestHandle &&other) = delete
RequestHandle(RequestHandle const&) = delete
RequestHandle &operator=(RequestHandle const&) = delete
~RequestHandle() noexcept
bool valid() const noexcept
struct Impl

Public Types

enum class Phase : uint8_t

Values:

enumerator kAdmitted
enumerator kExecuting
enumerator kFinishing

Public Functions

inline explicit Impl(
ContextCacheCoordinator &coordinator,
cudaStream_t requestStream
) noexcept
inline bool admitted() const noexcept
inline bool executing() const noexcept
inline bool hasPendingDeviceWork() const noexcept
inline bool awaitingFirstSpecCompletion() const noexcept
inline void beginPrefill() noexcept

kAdmitted -> kExecuting with the prefill work enqueued on the stream.

inline void markDeviceWorkEnqueued() noexcept

Fresh GPU work was enqueued on impl.stream (prefill grow, decode grow, fold, compaction copy).

inline void markDeviceWorkSynchronized() noexcept

impl.stream was explicitly synchronized (or a verification round already synchronized it).

inline void markDeviceWorkResolvedWithoutSync() noexcept

The enqueued work is provably terminal without a coordinator synchronize (no async publish work remains).

inline void beginSpecDraftInit() noexcept

EAGLE only: the ordered draft initialization awaits its first verification round before publishing.

inline void endSpecDraftInit() noexcept
inline void markFinishing() noexcept

Enter the terminal phase (normal completion at empty batch, or an unrecoverable capacity/growth failure).

Public Members

RequestSlotToken requestSlot

Declared before sequences so its destructor clears the admission flag only after every lease is released.

ContextCacheCoordinator *owner = {}
cudaStream_t stream = {}
bool speculativeRequest = {}
std::vector<int32_t> pendingCompactionMapping
int32_t pendingCompactionBatchSize = {-1}
Tensor const *pendingDeviceBatchMapping = {}
std::vector<SequenceState> sequences
struct RequestSlotToken

Public Functions

inline explicit RequestSlotToken(
ContextCacheCoordinator &coordinator
) noexcept
inline RequestSlotToken(RequestSlotToken &&other) noexcept
RequestSlotToken &operator=(RequestSlotToken&&) = delete
RequestSlotToken(RequestSlotToken const&) = delete
RequestSlotToken &operator=(RequestSlotToken const&) = delete
inline ~RequestSlotToken() noexcept

Public Members

ContextCacheCoordinator *owner = {}
struct SequenceState

Public Members

CacheRequestLease lease
std::vector<int32_t> tokenIds
BlockKeyExtras keyExtras
std::vector<Hash128> perPositionMediaHash
int32_t reuseTokenLength = {}
ContextCacheLookupPolicy lookupPolicy = {ContextCacheLookupPolicy::kUseCache}
ContextCacheCommitPolicy commitPolicy = {ContextCacheCommitPolicy::kIncludingGeneratedTokens}
int32_t replayTailLength = {}
int32_t committedStateLength = {}
int32_t publishedFullBlockCount = {}
int32_t publishedExactLength = {}
int32_t commonStateLength = {}
std::optional<int32_t> frozenSpecPrefillLength
std::optional<StagedHybridPublication> stagedHybridPublication
struct StagedHybridPublication

Public Members

HybridCheckpointKey checkpoint
HybridSnapshotReservation snapshots
PublicationPoint point = {}
struct ContextCachePhysicalResources#

Validated physical resources borrowed from SharedResources for the coordinator lifetime.

Public Members

HybridCacheManager &baseCache#
KVPageTable &basePageTable#
HybridCacheManager *draftCache = {}#
KVPageTable *draftPageTable = {}#
struct ContextCacheSequenceAdmission#

One complete logical input admitted to the cache before its executable suffix is derived.

Public Members

std::vector<int32_t> tokenIds#
BlockKeyExtras keyExtras#

Request-wide non-token identity; LoRA/isolation identity is constant for the sequence.

std::vector<Hash128> perPositionMediaHash#

Per-position media content hash. Empty means text-only. When non-empty, must have tokenIds.size() entries. A non-zero Hash128 at position i causes the block hash to consume that 128-bit digest instead of the token ID.

struct ContextCacheBatchAdmission#

One serialized runtime request. Bypass still uses managed private pages but neither looks up nor publishes state.

Public Members

std::vector<ContextCacheSequenceAdmission> sequences#
bool speculativeRequest = {}#
ContextCacheLookupPolicy lookupPolicy = {ContextCacheLookupPolicy::kUseCache}#
ContextCacheCommitPolicy commitPolicy = {ContextCacheCommitPolicy::kIncludingGeneratedTokens}#
int32_t replayTailLength = {0}#

Carried-through Hybrid+MTP replay tail length. Not consumed by this stage.

struct ContextCacheSequenceAdvance#

Host-visible sequence advance observed after an existing stream synchronization.

Public Members

int32_t const *acceptedTokenIds = {}#
int32_t acceptedTokenCount = {}#
int32_t committedStateLength = {}#

Greatest logical token boundary whose model state is materialized in the bound cache.

struct AdmissionResult

Public Members

RequestHandle request
std::vector<int32_t> prefillStarts

Per-sequence logical token offset at which runtime prefill begins.

struct BeginRequestResult

Public Members

ContextCacheCoordinatorStatus status = {ContextCacheCoordinatorStatus::kRequestFailed}
std::optional<AdmissionResult> admission