Add reusable workspace support to the Python API - #31
Open
0z5a wants to merge 3 commits into
Open
Conversation
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.
Summary
outoptional in the Python wrapper and consistently return the output tensorworkspace, withallocate_workspace()for automatic sizing; the existing per-call allocation remains the defaultCloses #23.
RTX 5080 validation
Built for SM120 with PyTorch 2.10.0+cu130 and CUDA Toolkit 13.2.
Workspace benchmark
The benchmark preallocates
outin both modes, so the only API difference is automatic workspace allocation versus caller-owned reuse.Times are microseconds per call. Arrows are automatic allocation -> reused workspace.
aten::empty/ callAll five cases produced exact equality between automatic and reused output, and all five captured/replayed exactly with
torch.cuda.CUDAGraph. Reuse removes exactly one profiler-visible allocation per call and nearly all incremental workspace memory. Batched E2E and stream time are mostly neutral; this is evidence for explicit lifetime control and allocation stability, not a kernel-speedup claim. Host p95 includes queue backpressure for the longer-running shapes, which is why the E2E and stream columns are included separately.Compatibility
Existing positional calls and calls that omit
workspaceretain their behavior. Callers that reuse storage must provide one workspace per overlapping call; sequential calls may share the same buffer, and a buffer sized for a larger input may serve a smaller one on the same device.