Class DecodeCudaGraphSession
java.lang.Object
smile.llm.engine.DecodeCudaGraphSession
- All Implemented Interfaces:
AutoCloseable
Per-device CUDA graph session for uniform decode (batch 1 or power-of-two B).
Graphs are bucketed by (batch, numPages). Within a bucket,
last_page_len and per-row KV indices are updated in place before
replay(int).
-
Method Summary
Modifier and TypeMethodDescriptionbooleanbeginCapture(int deviceIndex) Begins CUDA graph capture ondeviceIndex(call from TP worker thread).booleancanReplay(int batch, int numPages) Returns whether a graph for(batch, numPages)can be replayed.intReturns the batch size of the captured bucket.intReturns thenumPagesof the captured bucket.voidclose()voidEnds capture and instantiates the graph.longReturns wall time in milliseconds for the last successful capture.voidreplay(int tpRank) Replays the captured graph (inputs must already be on device).booleanshouldCapture(int batch, int numPages, int tpRank) Marks one eager warmup step for the current bucket.booleanshouldCapture(int batch, int numPages, int tpRank, boolean prefetch) Marks one eager warmup step for the current bucket.static DecodeCudaGraphSessionCreates a session when decode CUDA graphs are enabled.
-
Method Details
-
tryCreate
Creates a session when decode CUDA graphs are enabled.- Returns:
- new session, or
nullwhen unavailable.
-
canReplay
public boolean canReplay(int batch, int numPages) Returns whether a graph for(batch, numPages)can be replayed.- Parameters:
batch- decode batch size.numPages- KV page count for this decode step.- Returns:
truewhen a graph for(batch, numPages)can be replayed.
-
shouldCapture
public boolean shouldCapture(int batch, int numPages, int tpRank) Marks one eager warmup step for the current bucket.- Parameters:
batch- decode batch size.numPages- KV page count for this decode step.tpRank- tensor-parallel rank for logging (>= 0).- Returns:
truewhen the next forward should capture a new graph.
-
shouldCapture
public boolean shouldCapture(int batch, int numPages, int tpRank, boolean prefetch) Marks one eager warmup step for the current bucket.- Parameters:
batch- decode batch size.numPages- KV page count for this decode step.tpRank- tensor-parallel rank for logging (>= 0).prefetch-truefor next-bucket prefetch capture logging.- 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. -
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.
-
capturedNumPages
public int capturedNumPages()Returns thenumPagesof the captured bucket.- Returns:
- page count, or
-1when none captured.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-