Class VerifyCudaGraphSession
java.lang.Object
smile.llm.engine.VerifyCudaGraphSession
- All Implemented Interfaces:
AutoCloseable
Per-device CUDA graph session for the uniform MTP window-verify forward.
Graphs are bucketed by (batch, windowLen, numPages) — unlike
DecodeCudaGraphSession (implicit S == 1), verify's query
length is a real bucket dimension. Within a bucket, the flat KV write-index
buffer and CSR metadata are updated in place before replay(int).
Stage 4 of the verify-CUDA-graph plan drives this session's
shouldCapture(int, int, int, int) bookkeeping against real traffic while
VerifyCudaGraph.captureEnabled() is false, so
beginCapture(int) is never actually invoked yet — only bucket-key
transitions and warmup counting are exercised for real.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AtomicIntegerDiagnostic counter (process-wide): graph captures.static final AtomicIntegerDiagnostic counter (process-wide): session closes.static final AtomicIntegerDiagnostic counter (process-wide): bucket resets.static final AtomicIntegerDiagnostic counter (process-wide): eager warmup steps. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbeginCapture(int deviceIndex) Begins CUDA graph capture ondeviceIndex(call from TP worker thread).booleancanReplay(int batch, int windowLen, int numPages) Returns whether a graph for(batch, windowLen, numPages)can be replayed.intReturns the batch size of the captured bucket.intReturns thenumPagesof the captured bucket.intReturns thewindowLenof the captured bucket.voidclose()voidEnds capture and instantiates the graph.longReturns wall time in milliseconds for the last successful capture.voidlogCapture(int tpRank) Logs (once per bucket) a successful graph capture.voidreplay(int tpRank) Replays the captured graph (inputs must already be on device).booleanshouldCapture(int batch, int windowLen, int numPages, int tpRank) Marks one eager warmup step for the current bucket.static VerifyCudaGraphSessionCreates a session when verify CUDA graph wiring is enabled.
-
Field Details
-
RESETS
Diagnostic counter (process-wide): bucket resets. -
WARMUPS
Diagnostic counter (process-wide): eager warmup steps. -
CAPTURES
Diagnostic counter (process-wide): graph captures. -
CLOSES
Diagnostic counter (process-wide): session closes.
-
-
Method Details
-
tryCreate
Creates a session when verify CUDA graph wiring is enabled.- Returns:
- new session, or
nullwhen unavailable.
-
canReplay
public boolean canReplay(int batch, int windowLen, int numPages) Returns whether a graph for(batch, windowLen, numPages)can be replayed.- Parameters:
batch- verify batch size.windowLen- query length (numDrafts + 1).numPages- KV page count for this verify step.- Returns:
truewhen a graph for this bucket can be replayed.
-
shouldCapture
public boolean shouldCapture(int batch, int windowLen, int numPages, int tpRank) Marks one eager warmup step for the current bucket.- Parameters:
batch- verify batch size.windowLen- query length (numDrafts + 1).numPages- KV page count for this verify step.tpRank- tensor-parallel rank for logging (>= 0).- Returns:
truewhen the next forward should capture a new graph.
-
beginCapture
public boolean beginCapture(int deviceIndex) Begins CUDA graph capture ondeviceIndex(call from TP worker thread).- Parameters:
deviceIndex- CUDA device ordinal for capture.- Returns:
truewhen capture started.
-
lastCaptureMs
public long lastCaptureMs()Returns wall time in milliseconds for the last successful capture.- Returns:
- capture duration in milliseconds.
-
endCapture
public void endCapture()Ends capture and instantiates the graph. No-op when not capturing. -
logCapture
public void logCapture(int tpRank) Logs (once per bucket) a successful graph capture.- Parameters:
tpRank- tensor-parallel rank for logging.
-
replay
public void replay(int tpRank) Replays the captured graph (inputs must already be on device).- Parameters:
tpRank- tensor-parallel rank for one-shot bucket logging.
-
capturedBatch
public int capturedBatch()Returns the batch size of the captured bucket.- Returns:
- batch size, or
-1when none captured.
-
capturedWindowLen
public int capturedWindowLen()Returns thewindowLenof the captured bucket.- Returns:
- window length, or
-1when none captured.
-
capturedNumPages
public int capturedNumPages()Returns thenumPagesof the captured bucket.- Returns:
- page count, or
-1when none captured.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-