Skip to content

feat(bypass): kernel source resolution + shape recovery for graph/Triton kernels - #1049

Open
lishuoshuo-amd wants to merge 2 commits into
mainfrom
feat/shuoshuo/bypass-shape-fallback
Open

feat(bypass): kernel source resolution + shape recovery for graph/Triton kernels#1049
lishuoshuo-amd wants to merge 2 commits into
mainfrom
feat/shuoshuo/bypass-shape-fallback

Conversation

@lishuoshuo-amd

Copy link
Copy Markdown
Contributor

Summary

  • Bring the bypass (TraceLens-free) kernel analysis path to parity for CUDA-graph and Triton workloads, so hot kernels resolve to editable sources and carry a dispatchable shape without patching sglang.
  • Commit 1 (resolve kernel sources by repo scan ...): repo-scan source resolution by device kernel name, comms/MoE/SDPA/GEMM/Elementwise classification, and graph-mode trace handling (hipGraphLaunch attribution + idle-gate skip on under-recorded graph traces).
  • Commit 2 (recover kernel shapes ...): a shape-resolution waterfall so graph-replay and Triton direct-launch kernels stop falling to unresolved.

Motivation

On a real Kimi-K3 graph-mode trace, ~45% of kernel executions (63 distinct kernels, including routable hand-written Triton/KDA kernels) had a broken correlation -> External id -> cpu_op -> Input Dims chain and resolved to shape_provenance=unresolved. The data is not lost, only displaced (capture-time record, launch geometry, or the tile-encoding name), so a general identity-keyed fallback recovers it.

Shape waterfall (identity-keyed, no name allowlist)

  1. torch_trace -- own cpu_op Input Dims (precise; unchanged)
  2. capture_backfill -- same-name kernel's capture-time shape
  3. launch_grid -- this kernel's launch grid/block geometry
  4. tile_name -- BLOCK_SIZE_* tile parsed from the kernel name
  5. unresolved -- none of the above

launch_grid/tile_name are geometry (not operand dims) and are deliberately excluded from the analytical roofline so they cannot poison AI/bound-type estimates.

Validation

  • On the real Kimi-K3 graph trace, the top-15 hot kernels went from 3 unresolved to 0 (the 3 became launch_grid); the 12 torch_trace rows are unchanged (no regression).
  • kernel-agent bypass suite: 195 passed (adds waterfall + reader passthrough tests).

Notes / follow-up (not in this PR)

  • These fallbacks make the kernels visible with a shape. Whether a launch_grid/tile_name-level shape should be allowed to satisfy the kernel_opt dispatch gate (non-empty trace shape REQUIRED) is left as a separate, opt-in decision, since geometry is coarser than operand shapes.

Test plan

  • CI green on the bypass / kernel-agent suites

Made with Cursor

shuoshuo and others added 2 commits July 30, 2026 03:35
…/attn, handle graph-mode traces

Add a repo-scan fallback that reverse-looks-up device kernel names against the
on-disk sglang/aiter sources, so hand-written Triton and C++/HIP kernels resolve
to editable sources without the Inductor-only kernel_file field or the stale
op_to_source table. Extend the classifier with a Communication category and
MoE/SDPA/GEMM/Elementwise rules. Recognize hipGraphLaunch so graph-internal
kernels are attributed instead of unlinked, expose graph-coverage health, and
skip the idle gate when a graph-mode trace is under-recorded.
…h kernels

Kernels whose correlation->cpu_op chain is broken (CUDA-graph replay and
Triton direct-launch) previously fell straight to shape_provenance=unresolved,
leaving ~45% of graph-mode kernels (including routable hand-written Triton/KDA
kernels) without a dispatchable shape.

Add a shape-resolution waterfall keyed on the kernel identity, not a name
allowlist:
  1. torch_trace      -- own cpu_op Input Dims (unchanged, precise)
  2. capture_backfill -- same-name kernel's capture-time shape
  3. launch_grid      -- this kernel's launch grid/block geometry
  4. tile_name        -- BLOCK_SIZE_* tile embedded in the kernel name

The reader now retains launch grid/block and builds name-keyed backfill/geometry
indices; the report builder consumes them. launch_grid/tile_name fallbacks are
geometry, not operand dims, so they are excluded from the analytical roofline to
avoid poisoning the AI/bound-type estimate.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lishuoshuo-amd
lishuoshuo-amd requested a review from a team as a code owner July 30, 2026 03:36


# Length-prefixed token of an Itanium name (e.g. "5aiter" -> "aiter").
_ITANIUM_TOKEN_RE = re.compile(r"(\d+)")


# Length-prefixed token of an Itanium name (e.g. "5aiter" -> "aiter").
_ITANIUM_TOKEN_RE = re.compile(r"(\d+)")
@github-actions

Copy link
Copy Markdown

CI E2E report — ❌ Failed

item value
result ❌ Failed
model Qwen/Qwen3-0.6B (dense)
resources 1× GPU, TP=1
PR branch feat/shuoshuo/bypass-shape-fallback
commit 283e2e8ee206a5f7d1e9aac71f3bc5b8a66a6dc0
session_id 526f10d8-39c0-4552-b83e-7f693e98ee45
queue → dispatch 0s
run time 165m 19s
total 165m 19s
reason pending too long (>30m0s)
detail pending too long (>30m0s)

details

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