Skip to content

gpu: opt-in GPU graph capture/replay for the async eval path (MIGRAPHX_HIP_GRAPH) - #5261

Open
rlegithub wants to merge 1 commit into
ROCm:developfrom
rlegithub:pr/gpu-hipgraph-eval
Open

rlegithub wants to merge 1 commit into
ROCm:developfrom
rlegithub:pr/gpu-hipgraph-eval

Conversation

@rlegithub

Copy link
Copy Markdown

Summary

Adds an opt-in GPU graph‑capture path — the HIP equivalent of CUDA Graphs — for the async (EP decode) eval body. The decode‑step op sequence is captured once into a replayable graph and replayed as a single graph launch on later tokens, collapsing the ~1946 per‑op host‑side kernel dispatches of a decode step into one launch (cuts host launch overhead on the short‑per‑op decode path).

Gated by MIGRAPHX_HIP_GRAPH (default OFF → byte‑identical eager path); MIGRAPHX_HIP_GRAPH_DEBUG prints the WARMUP/CAPTURE/REPLAY trace. Only engages on the sync‑free async path (no trace/substitute callback, single context). Captures are keyed on sorted (param name, device ptr, shape) + queue, so identical buffers/shapes/stream replay safely; per‑key output args are cached. Correctness is preserved on any capture failure (falls back to eager).

context.hpp / gpu context provide capture_replay()/restore_queue() + a shared graph cache; program.cpp offers the eval body to the context on the async path.

Generic, opt‑in — not model‑specific (surfaced during GPT‑OSS‑20B decode).

Test plan

  • CI
  • Verified on gfx1151 (Strix Halo): with MIGRAPHX_HIP_GRAPH=1 it engages (WARMUP → CAPTURE → REPLAY) and decodes correctly (~57 tok/s); default‑off is the eager path (no capture, 55.7 tok/s, byte‑identical).

…X_HIP_GRAPH)

Adds an opt-in GPU graph-capture path -- the HIP equivalent of CUDA Graphs.
The sequence of GPU operations in the async (EP decode) eval body is CAPTURED
once into a replayable graph, then REPLAYED as a single graph launch on later
tokens. This collapses the ~1946 per-op host-side kernel dispatches of a decode
step into one launch, cutting host launch overhead on the short-per-op decode
path.

Graph capture (a.k.a. CUDA/HIP Graphs) is a standard technique for launch-bound
workloads; here it is exposed through HIP's graph API and gated by the env var
MIGRAPHX_HIP_GRAPH (default OFF -> byte-identical eager path). It only engages on
the sync-free async path (no trace/substitute callback, single context). Captures
are keyed on sorted (param name, device ptr, shape) + queue, so identical
buffers/shapes/stream replay safely; per-key output args are cached.

context.hpp / gpu context provide capture_replay()/restore_queue() + a shared
graph cache; program.cpp offers the eval body to the context on the async path.

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread src/program.cpp
// Defensive: handled but no cached outputs (should not happen) ->
// fall through to eager below.
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execution should be extended using operators not by changing the eval method, which is what #4956 already does.

@rlegithub
rlegithub marked this pull request as ready for review September 14, 2026 21:21
@rlegithub
rlegithub requested a review from causten as a code owner September 14, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants