You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up from #716 review (requested by @vedaanta): remove the SDPA SM80 adapters' operand staging — most immediately the per-execute .contiguous() allocations inside it — in favor of kernels that address declared operand strides natively.
Current state
Backward — python/cudnn/sdpa/bwd/api.pyexecute._stage (on develop today):
Every execute with a dense_flex (non-BSHD-compact) operand or a head-dim pad allocates fresh tensors — an AGENTS.md Rule 1 violation ("no per-execute allocation") that #716's carving pass fixed for the kernel-internal buffers but not for these operand gathers.
Forward — the SdpaFwdDsl base helpers have the same issue for wrapper-path callers:
_to_bshd: return view if view.is_contiguous() else view.contiguous()
_to_bshd_writable: torch.empty_like(view, ...) per execute
Kill the staging copies entirely (Rule 2 end-state) — even a carved gather is a copy per execute. The kernels should address non-compact operand layouts natively via declared strides, the way the forward f16 kernels already handle THD declared token strides ("no normalization-copy fallback") and the way frost(sdpa): SM80 backward native strided-LSE reads + THD max_s_kv grid hint #766 makes the backward's LSE reads stride-aware (after frost(sdpa): enable sdpa_fwd engines to write dense LSE directly to non-contiguous, dense-compatible layouts #712 did the forward's LSE writes). Concretely: stride-parameterized global loads for Q/K/V/O/dO (and stores for dQ/dK/dV) in the SM80 kernels, with the plan-time declared strides carried on the template compile() seam like lse_stride. Once operands bind natively, _stage and the gather sizing in scratch_workspace_bytes() can be deleted outright. Declarations the hardware/addressing cannot express should be REJECTED in check_support, not silently copied.
Head-dim padding (flavor envelopes) is a separate concern from layout normalization and may legitimately keep a carved staging path — or move into the kernels as predicated loads; to be decided as part of milestone 2.
Follow-up from #716 review (requested by @vedaanta): remove the SDPA SM80 adapters' operand staging — most immediately the per-execute
.contiguous()allocations inside it — in favor of kernels that address declared operand strides natively.Current state
Backward —
python/cudnn/sdpa/bwd/api.pyexecute._stage(on develop today):Every execute with a dense_flex (non-BSHD-compact) operand or a head-dim pad allocates fresh tensors — an AGENTS.md Rule 1 violation ("no per-execute allocation") that #716's carving pass fixed for the kernel-internal buffers but not for these operand gathers.
Forward — the
SdpaFwdDslbase helpers have the same issue for wrapper-path callers:_to_bshd:return view if view.is_contiguous() else view.contiguous()_to_bshd_writable:torch.empty_like(view, ...)per executeTwo milestones
Kill the allocations (Rule 1) — gather into carved workspace instead of
.contiguous(). For the backward this lands with frost(sdpa): port the SM80 backward onto SdpaBwdDsl + TemplateParams with sym_int THD extents (issue #604) #765, which deletesbwd/api.py; its replacement_stagecarves via the Convert torch-native SM80 SDPA adapters to scratch workspace carving #514 machinery (zero allocation when a workspace is provided). The forward's_to_bshd/_to_bshd_writableresidual remains open after frost(sdpa): port the SM80 backward onto SdpaBwdDsl + TemplateParams with sym_int THD extents (issue #604) #765.Kill the staging copies entirely (Rule 2 end-state) — even a carved gather is a copy per execute. The kernels should address non-compact operand layouts natively via declared strides, the way the forward f16 kernels already handle THD declared token strides ("no normalization-copy fallback") and the way frost(sdpa): SM80 backward native strided-LSE reads + THD max_s_kv grid hint #766 makes the backward's LSE reads stride-aware (after frost(sdpa): enable sdpa_fwd engines to write dense LSE directly to non-contiguous, dense-compatible layouts #712 did the forward's LSE writes). Concretely: stride-parameterized global loads for Q/K/V/O/dO (and stores for dQ/dK/dV) in the SM80 kernels, with the plan-time declared strides carried on the template
compile()seam likelse_stride. Once operands bind natively,_stageand the gather sizing inscratch_workspace_bytes()can be deleted outright. Declarations the hardware/addressing cannot express should be REJECTED incheck_support, not silently copied.Head-dim padding (flavor envelopes) is a separate concern from layout normalization and may legitimately keep a carved staging path — or move into the kernels as predicated loads; to be decided as part of milestone 2.
Related