Refactor CK workspace memory management to use a unified toggle-pass helper object#552
Merged
Conversation
ipanfilo
approved these changes
Apr 22, 2026
wangye805
approved these changes
Apr 23, 2026
Comment on lines
-593
to
+629
| size_t q_storage_bytes = max_tokens_q*h*d_qk*nvte_dtype_size(dtype); | ||
| size_t k_storage_bytes = max_tokens_kv*hg*d_qk*nvte_dtype_size(dtype); | ||
| size_t v_storage_bytes = max_tokens_kv*hg*d_v*nvte_dtype_size(dtype); | ||
| size_t o_storage_bytes = max_tokens_q*h*d_v*nvte_dtype_size(dtype); | ||
| size_t q_storage_bytes = max_tokens_q*h*d_qk*nvte_dtype_size(dtype); | ||
| size_t k_storage_bytes = max_tokens_kv*hg*d_qk*nvte_dtype_size(dtype); | ||
| size_t v_storage_bytes = max_tokens_kv*hg*d_v*nvte_dtype_size(dtype); | ||
| size_t o_storage_bytes = max_tokens_q*h*d_v*nvte_dtype_size(dtype); |
Collaborator
There was a problem hiding this comment.
Just curious, what's changed here? I stare at it for half a minute but still not seeing any diff :-)
Contributor
Author
There was a problem hiding this comment.
Whitespace removal at the end of the line -- you can view diffs in the GH PR UI specifically excluding white space changes which I find quite helpful btw.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replaced the mirrored two-pass workspace pattern (
if(workspace==nullptr)block computing size + a separate execution block doing the same allocation arithmetic withworkspace_next) with a single-passWorkspacePlannerthat unifies both passes. Eliminates a class of drift bugs where the size pass and use pass could disagree.Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
WorkspacePlannerclass: constructor takesvoid* base;allocate(bytes)returns nullptr in sizing mode while still accumulatingtotal()byte_offset(ptr, n)andbyte_diff(a, b)helpers for nullptr-safe sub-buffer carving (qkv-packed cases)fused_attn_ck_fwd_impl: deleted the sizing-onlyifblock; replaced allworkspace_nextarithmetic withplanner.allocate(); moved init kernels (alibi gen,generate_cu_seqlen_padded, memset of O) past a singleif(planner.is_sizing()) returnearly-returnfused_attn_ck_bwd_impl: same treatment plus hoistednvte_get_qkv_layout_group(layout)to the function top (the original recomputed it inside the SBHD+padding branch); user-output dq/dk/dv memsets and workspace dq_acc/dbias/dqkv-without-padding memsets all moved past the sizing returnlse_workspace = workspace(which silently relied onworkspace_next == workspaceat that point) became an explicitplanner.allocate(...)as the first allocationChecklist: