Add compiled CopyPlan for prepared strided copies (stage 1 of #139)#142
Merged
Conversation
Make fuse_pair_layout / apply_fused_pair / FusedPairLayout and is_injective_layout pub(crate) so a compiled CopyPlan can reuse the exact traversal the per-call raw kernels build, and add the PlanLayoutMismatch error variant for the plan's per-call layout check. No public API change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopyPlan::compile validates the layout pair once (rank agreement, extent overflow, destination injectivity) and builds the fused loop nest; execute / execute_scale / execute_conj re-check only the per-call facts (that the supplied raw views carry the compiled layout) and replay it with no planning and no heap allocation for ranks at most RAW_FUSED_RANK_LIMIT. Higher ranks fall back to the view-based kernels. Prepared-replay consumers issuing many small fixed-layout copies avoid the per-call fusion cost measured in tensor4all#139. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Counting-global-allocator integration test asserting that execute/execute_scale/execute_conj perform no heap allocations for rank <= RAW_FUSED_RANK_LIMIT layouts. Kept in its own test binary so concurrent sibling tests cannot leak setup allocations into the counted window. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Add compiled CopyPlan for prepared strided copies
Summary
Stage 1 of #139: a prepared, reusable copy plan over the raw borrowed-layout kernels from #140.
CopyPlan::compileruns the layout planning once (validation + fused-pair layout);execute/execute_scale/execute_conjreplay it againstRawStridedRef/RawStridedMutwith zero heap allocations for rank ≤ 8.Design
executeis exactly "Add allocation-free raw copy/axpy kernels #140 minus the per-call planning" — it reuses the samepub(crate)fused-pair machinery (fuse_pair_layout/apply_fused_pair), so there is no second copy-kernel implementation. Rank > 8 falls back to the view kernels (the explicit-fallback rule; this is the only allocating path).compileproves layout compatibility (rank agreement, extent-product overflow, destination injectivity via the existingis_injective_layout);execute*re-checks only the per-call facts (the supplied views must carry exactly the compiled layout —PlanLayoutMismatchotherwise). Buffer bounds are already proven byRawStridedRef/Mutconstruction.CopyPlan+ its methods and the newStridedError::PlanLayoutMismatchvariant become public; all planning internals staypub(crate).MapPlan/ReducePlan(stages 2–3 of #139) are deliberately not included; this PR proves the API shape on the smallest reviewable slice.Tests
execute/execute_scale/execute_conjperform no heap allocations at rank 8, on both the default andparallelfeatures.cargo test --workspacegreen (incl.--features parallel),cargo fmt --checkclean,cargo doc --no-depswarning-free, per-file coverage ≥ 80% (copy_plan.rs 99.3%).