Repository navigation
[Common] Add caller-owned workspaces with per-stream resource isolation - #3766
Oleg-Goncharov wants to merge 20 commits into
Conversation
1c0b5ea to
7b1be7e
Compare
timmoon10
left a comment
There was a problem hiding this comment.
This workspace infrastructure may be overengineered: #3779 (comment)
|
Thanks for the detailed review, @timmoon10! I have narrowed this PR to caller-owned TMA descriptor storage for grouped MXFP8 operations. Below are responses to your comments in #3779
Comments 11-16 concern the resource lifecycle changes in the follow-up PR #3779 which is currently based on this PR. I’ll address those comments separately in that PR. |
[Medium impact] The PR appears safe to merge based on the code reviewed. SummaryThis PR moves mutable grouped MXFP8 descriptors into caller-owned workspace and updates PyTorch to allocate that storage.
Both earlier query-validation concerns are addressed. No new actionable issues were found. GPU tests were not run during this review. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Caller supplies empty workspace handle] --> B[Validate request and return size]
B --> C[Caller allocates workspace]
C --> D[Validate capacity and alignment]
D --> E[Rebuild descriptors on the supplied stream]
E --> F[Run grouped operation]
C -. Separate storage for independent streams and graphs .-> C
Reviews (9) · Last reviewed commit: "Merge branch 'main' into pr_resource_wor..." · Reviewed by Greptile |
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
…st thread. Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Pass workspace TMA storage to the grouped MXFP8 requantization updater and consumer introduced on main. Add a v2 query/allocate/execute entry point and keep constant-last-dimension calls working through the original API. Cover query validation, independent streams and graphs, and the grouped requantization numerical matrix without restoring global descriptors or the 64-group limit. Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com>
fde63a5 to
c8bb0c7
Compare
|
/te-ci |
| * Query and execution reconstruct the same TMA-specific layout from the group count. | ||
| * They may use different tensor handles; no persistent host metadata is attached to either. |
There was a problem hiding this comment.
The workspace should be considered opaque and the caller shouldn't need to know that it's for TMA descriptors. What we should focus on is the contract we make with the caller. I suppose we could mention that the workspace size does not depend on the data pointers, so you can reuse the same workspace for different tensors with the same shape... but that's also pretty obvious and bringing it up is mostly confusing.
| * Query and execution reconstruct the same TMA-specific layout from the group count. | |
| * They may use different tensor handles; no persistent host metadata is attached to either. |
| * They may use different tensor handles; no persistent host metadata is attached to either. | ||
| * The workspace is a one-dimensional byte tensor and requires at least one byte even when | ||
| * the selected kernel does not need temporary storage. | ||
| * Execution validates the tensor's declared byte capacity and base alignment. |
There was a problem hiding this comment.
This is basic error checking. No point bringing it up except for Codex to show off that it thought of an edge case.
| * Execution validates the tensor's declared byte capacity and base alignment. |
| * The workspace is a one-dimensional byte tensor and requires at least one byte even when | ||
| * the selected kernel does not need temporary storage. | ||
| * Execution validates the tensor's declared byte capacity and base alignment. | ||
| * The caller is responsible for the actual allocation behind the supplied pointer. |
There was a problem hiding this comment.
This is true for all NVTETensors. No point bringing it up here.
| * The caller is responsible for the actual allocation behind the supplied pointer. |
| * Contents are rebuilt on every invocation; no initialization is required. Keep the memory | ||
| * alive until submitted work completes, and for the lifetime of captured graphs that use it. | ||
| * Each workspace is used by one CUDA stream. The caller supplies separate allocations | ||
| * for independently executing streams and serializes complete host submissions using the same buffer. | ||
| * Independent graphs require separate mutable storage, even if captured on the same stream. | ||
| * Query and allocate the workspace before CUDA graph capture. |
There was a problem hiding this comment.
How is this different from basic CUDA stream semantics and CUDA Graph usage?
| * Contents are rebuilt on every invocation; no initialization is required. Keep the memory | |
| * alive until submitted work completes, and for the lifetime of captured graphs that use it. | |
| * Each workspace is used by one CUDA stream. The caller supplies separate allocations | |
| * for independently executing streams and serializes complete host submissions using the same buffer. | |
| * Independent graphs require separate mutable storage, even if captured on the same stream. | |
| * Query and allocate the workspace before CUDA graph capture. |
| * | ||
| * MXFP8 groups with varying last dimensions use the workspace for TMA descriptors and | ||
| * metadata, without a fixed group-count limit. Its data pointer must be 128-byte aligned. | ||
| * Contents are rebuilt on every invocation; no initialization is required. Keep the memory |
There was a problem hiding this comment.
The caller doesn't need to know how the workspace is used internally.
There was a problem hiding this comment.
These docs have a lot of of internal implementation details, irrelevant info, and excessive details.
There was a problem hiding this comment.
These are tests written for the sake of writing tests. GroupedTmaWorkspaceLayout is an internal helper class that very tightly integrated with the implementation of the grouped MXFP8 kernels. It is not written generally and has little abstraction, so there isn't much value in testing it independently from the rest of the grouped MXFP8 infrastructure.
| /*rowwise=*/true, /*columnwise=*/false); | ||
| fill_output_sentinel(dequantized); | ||
| nvte_group_dequantize(reference_input.data(), dequantized.data(), 0); | ||
| nvte_group_dequantize_v2(reference_input.data(), dequantized.data(), workspace.data(), 0); |
There was a problem hiding this comment.
We should make sure the workspace is large enough rather than assuming nvte_group_quantize_v2 and nvte_group_dequantize_v2 have the same workspace size.
| nvte_group_requantize_v2(input.data(), actual.data(), | ||
| return_dequantized ? dequantized_nvte.data() : nullptr, | ||
| workspace.data(), nullptr, 0); |
There was a problem hiding this comment.
We should make sure the workspace is large enough rather than assuming nvte_group_quantize_v2 and nvte_group_requantize_v2 have the same workspace size.
| if (shape_rep == SAME_BOTH_DIMS || shape_rep == VARYING_FIRST_DIM) { | ||
| nvte_group_dequantize(in_group_tensor, out_group_tensor, 0); | ||
| } else { | ||
| EXPECT_THROW(nvte_group_dequantize(in_group_tensor, out_group_tensor, 0), std::runtime_error); | ||
| } |
There was a problem hiding this comment.
Making nvte_group_dequantize and nvte_group_dequantize_v2 output to the same buffer means that the test could miss a bug where one silently skips.
Description
Replace global mutable TMA descriptor arrays in grouped MXFP8 quantization, activation forward/backward, and dequantization with caller-owned workspace. Use ordinary
NVTETensorhandles and the existing empty-tensor size-query protocol. Reconstruct the layout from the group count and rebuild descriptors and metadata on each invocation, without persistent host state or workspace ownership attached to tensors. Remove the fixed 64-group descriptor limit.Callers provide separate mutable allocations for independently executing CUDA streams and CUDA Graphs, order reuse of a shared buffer, and keep captured allocations alive for all graph executions that reference them.
Compatibility change: the original workspace-less grouped C APIs now reject MXFP8 layouts with varying last dimensions. C/C++ callers must use the corresponding
_v2query/allocate/execute APIs for those layouts. Constant-last-dimension layouts retain support through the original entry points.PyTorch grouped MXFP8 quantize/dequantize use the workspace-enabled APIs and framework allocations. The JAX grouped MXFP8 FFI keeps its existing call: its constant last dimension uses launch-local descriptors and does not require descriptor-array workspace.
Also fix PyTorch grouped DBias scratch lifetime and preserve supported partial-row MXFP8 dequantization. DBias retains its existing backend-specific scratch protocol.
CUDA resource lifecycle and reset changes belong to a follow-up PR #3779, which is currently based on this PR.
Workspace size queries perform the same host-side validation as execution, including non-MXFP8 forward formats and block-scaled dequantization, without launching GPU work or modifying outputs.
Type of change
Changes
NVTETensorhandles, including different handles for query and execution. Validate declared capacity and base alignment; centralize size-overflow checks in the layout calculation._v2grouped entry points. Original workspace-less APIs reject varying-last-dimension MXFP8 layouts; constant-last-dimension layouts remain supported. Document the migration._v2for grouped MXFP8 quantize/dequantize and allocate workspace through the framework, including graph-pool allocations during capture. Keep other grouped formats on their existing calls.Checklist: