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&
- 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#
-
struct AdmissionResult#
Public Members
-
RequestHandle request#
-
std::vector<int32_t> prefillStarts#
Per-sequence logical token offset at which runtime prefill begins.
-
RequestHandle request#
-
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
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
Apply the post-decode advance and publish endpoints for the completed slots.
- inline explicit PublicationPolicy(
- ContextCacheCoordinator &coordinator
-
inline virtual char const *name() const noexcept override#
-
struct BeginRequestResult#
Public Members
-
ContextCacheCoordinatorStatus status = {ContextCacheCoordinatorStatus::kRequestFailed}#
-
std::optional<AdmissionResult> admission#
-
ContextCacheCoordinatorStatus status = {ContextCacheCoordinatorStatus::kRequestFailed}#
-
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
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
Apply the post-decode advance and publish endpoints for the completed slots.
- inline virtual ContextCacheCoordinatorStatus onTerminalize(
- RequestHandle &request
EAGLE-only: publish the frozen prefill once the first verification round terminalizes. Default no-op.
- inline explicit PublicationPolicy(
- ContextCacheCoordinator &coordinator
-
inline virtual char const *name() const noexcept override#
-
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
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
Hybrid+MTP-only: restore the checkpoint’s saved boundary hidden row. Unreachable for other flavors.
-
inline virtual char const *name() const noexcept override#
-
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
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
Apply the post-decode advance and publish endpoints for the completed slots.
- inline explicit PublicationPolicy(
- ContextCacheCoordinator &coordinator
-
inline virtual char const *name() const noexcept override#
-
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
-
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
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
Apply the post-decode advance and publish endpoints for the completed slots.
- inline virtual ContextCacheCoordinatorStatus onTerminalize( )#
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
Public Functions
- inline explicit Impl(
- ContextCacheCoordinator &coordinator,
- cudaStream_t requestStream
-
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}#
-
std::vector<SequenceState> sequences#
-
struct RequestSlotToken#
Public Functions
- inline explicit RequestSlotToken(
- ContextCacheCoordinator &coordinator
-
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#
-
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#
-
CacheRequestLease lease#
-
struct StagedHybridPublication#
Public Members
-
HybridCheckpointKey checkpoint#
-
HybridSnapshotReservation snapshots#
-
PublicationPoint point = {}#
-
HybridCheckpointKey checkpoint#
-
RequestHandle(RequestHandle &&other) noexcept#
Public Functions
- RequestHandle &request,
- std::vector<ContextCacheSequenceAdvance> const &advances,
- std::vector<int32_t> const *commonStateLengths
Apply the post-prefill advance and publish (or arm) every ready endpoint for this flavor.
- RequestHandle &request,
- std::vector<ContextCacheSequenceAdvance> const &advances,
- std::vector<int32_t> const &publishableCompletedSlots,
- std::vector<int32_t> const *commonStateLengths
Apply the post-decode advance and publish endpoints for the completed slots.
- RequestHandle &request
EAGLE-only: publish the frozen prefill once the first verification round terminalizes. Default no-op.
- ContextCacheCoordinator &coordinator
-
using StreamSynchronizer = std::function<cudaError_t(cudaStream_t)>#
-
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
-
enumerator kAdmitted
Public Functions
- inline explicit Impl(
- ContextCacheCoordinator &coordinator,
- cudaStream_t requestStream
-
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
-
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
-
CacheRequestLease lease
-
struct StagedHybridPublication
Public Members
-
HybridCheckpointKey checkpoint
-
HybridSnapshotReservation snapshots
-
PublicationPoint point = {}
-
HybridCheckpointKey checkpoint
-
enum class Phase : uint8_t
-
RequestHandle(RequestHandle &&other) noexcept
-
struct ContextCachePhysicalResources#
Validated physical resources borrowed from SharedResources for the coordinator lifetime.
Public Members
-
HybridCacheManager &baseCache#
-
KVPageTable &basePageTable#
-
HybridCacheManager *draftCache = {}#
-
KVPageTable *draftPageTable = {}#
-
HybridCacheManager &baseCache#
-
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<int32_t> tokenIds#
-
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.
-
std::vector<ContextCacheSequenceAdmission> sequences#
-
struct ContextCacheSequenceAdvance#
Host-visible sequence advance observed after an existing stream synchronization.
-
struct AdmissionResult
Public Members
-
RequestHandle request
-
std::vector<int32_t> prefillStarts
Per-sequence logical token offset at which runtime prefill begins.
-
RequestHandle request
-
struct BeginRequestResult
Public Members
-
ContextCacheCoordinatorStatus status = {ContextCacheCoordinatorStatus::kRequestFailed}
-
std::optional<AdmissionResult> admission
-
ContextCacheCoordinatorStatus status = {ContextCacheCoordinatorStatus::kRequestFailed}