Repository navigation
refactor(umbp): one incremental plan builder shared by every transfer engine - #774
Merged
Merged
Conversation
LocalCopyEngine plans a ranged get into host memory the way HbmCopyEngine plans one into a GPU: one TransferItem per page fragment, grouped by (src, dst) buffer and coalesced. Behind the default BufferedPlanBuilder it still held every fragment of the batch, and the composite builder copied each one into it once more, so host-destination restores got slower with the incremental builder instead of faster. Give it the builder HbmCopyEngine has: Plan()'s loop moves into Add(), and Plan() is the builder over a vector, so there is one copy of the merge logic. The pair map grows with distinct endpoint pairs instead of reserving two buckets per item. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 8f65997)
… engine #758 and #765 gave HbmCopyEngine and LocalCopyEngine incremental plan builders, each a hand-written copy of the same skeleton; MoriIoEngine and GdsEngine still planned only in batch, behind the buffering default. - plan_builder.h holds what was duplicated: AdjacentNoOverflow (3 copies), PtrPairKey (2), the coalesce-and-dedupe-tag append (3, now AppendSegment with an optional merge veto and length cap), the bounds check, and PlanViaBuilder() for "Plan() is the builder over a vector". - GroupedPlanBuilder<Traits> owns the skeleton: skip empty items, collect rejected tags, group into plans in first-seen order, Finish. An engine supplies Admit / Joins / NewPlan / Append in a small Traits struct. - Hbm and Local are ported onto it; MoriIoEngine (zero-copy groups keyed by memory ids and told apart by engine key, bounce groups retired when the pool fills) and GdsEngine (one plan per item) gain incremental builders. - CompositeTransferEngine::Plan() is now its builder over a vector, so there is one routing path; mixed batches list engines in first-seen order instead of unordered_map order. Plans are unchanged: a scratch harness dumping every engine's Plan() for 42 seeded random batches (merges, piece splits, bounce rollovers, the SGE cap, every reject path) is byte-identical before and after. Tests: MoriIoEngine's planner, untested until now (zero-copy grouping across peers with colliding ids, the uint32 SGE cap, bounce staging and rollover), Hbm's split at host registration pieces, and a builder-matches-Plan check for every engine and the composite. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at lookups The first cut gave every group a vector of plan indices and a Joins loop, which Local and Hbm never need: one buffer pair is one plan. Their incremental planning was 0.3-0.9 ms (8-18%) slower than the hand-written builders it replaced. kGroups becomes PlanGrouping: kNone (GDS), kOnePerKey (Local, Hbm: a plain key -> plan index map, and an item with the previous item's key skips the lookup, since a key's pages arrive back to back) and kManyPerKey (MORI-IO, which keeps Joins). Plans are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ir builder Every engine's Plan() had become "my builder over a vector", so make that the contract instead of a convention: - TransferEngine::CreatePlanBuilder() is pure virtual and Plan() is a non-virtual base method (the builder over the vector). Gone: the five identical Plan() overrides, BufferedPlanBuilder (the default that buffered every item) and PlanViaBuilder. A new engine cannot compile without a builder, so it cannot silently plan in batch. - The rules every builder keeps (no IO, empty items dropped, rejects into rejected_tags, each item named by one plan, deterministic order) are written on TransferPlanBuilder. - The traits template was more machinery than its four users needed: two of its three grouping modes served one engine each. It is now PairPlanBuilder, for the engines with one plan per buffer pair (Local, Hbm): admission (CanHandle + bounds), the pair map with its repeat-pair fast path, and new plans are shared, and an engine passes only how to append. GdsEngine and MoriIoEngine get plain builders (MORI-IO's is its original Plan() loop, item by item) on the shared helpers. Tests: builder-matches-Plan() checks are tautological now and are replaced by ExpectPlanContract (every item rejected or planned, accepted bytes planned exactly once), used on every engine; the three test fakes implement CreatePlanBuilder(). The add-engine skill describes the hook, the rules and when to use PairPlanBuilder. Plans are unchanged (the scratch harness's 42 plan sets are byte-identical to 320ddab). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comments cut to one line of why. LocalCopyEngine's two Builder* tests repeat the Plan() tests now that Plan() is the builder; their one extra case (an empty item is dropped) moves into the interleave test. Trimmed asserts that the plan count or ExpectPlanContract already cover. Co-Authored-By: Claude Opus 5.5 <[email protected]>
TianDi101
marked this pull request as ready for review
October 15, 2026 07:05
2 of 3 tasks
TianDi101
added a commit
that referenced
this pull request
Oct 16, 2026
A local reader now protects what it resolved by keeping a shared_ptr hold (ResolvedEntry::hold). The bytes stay put while any hold lives and come back when the last one drops. This replaces the lease tokens, generations, ReleaseResolved and kDeferred that the first version of this PR added. - PageBackend: each committed slot owns a hold. Evict, EvictionCandidates and ClearLocal skip a slot whose hold is shared. A kLocal resolve takes no lease. - SsdBackend: a staging span is reclaimed once its lease has expired and its last hold is gone. Reclaim runs in the reaper and on demand when staging is full. A kLocal batch is staged up to half the arena at a time; the rest comes back kBusy, and the caller serves it in further parts. A kRemote batch keeps all-or-nothing staging. - PeerPool: a partial kLocal batch still touches and promotes what it served. - PoolClient: ServeLocalGets and BatchGetRanges drop each part's holds before resolving the next part. The probes use BatchContains, so they stage nothing. Also fixes test_peer_pool's FailingEngine to override CreatePlanBuilder (#774's interface). Before this, test_peer_pool did not build on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
TianDi101
added a commit
that referenced
this pull request
Oct 16, 2026
#774 made Plan() a non-virtual wrapper over CreatePlanBuilder(). PosixEngine keys plans by (memory, file range, direction) because a file endpoint has no host_ptr, so it gets its own builder rather than PairPlanBuilder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Part of #773. Every transfer engine now plans incrementally, and that's the interface's contract rather than a convention. The planning code shrinks (net −121 source lines) while MORI-IO and GDS gain incremental builders.
Stacked on #765. The first commit (
320ddabf9) is #765's change, cherry-picked ontomain; it drops out once #765 lands. This PR's own commits are486694eafthrough245d36041. The later ones rework the first, so review the combined diff.Why
After #758 and #765,
HbmCopyEngineandLocalCopyEnginehad incremental builders, each a hand-written copy of the same skeleton.MoriIoEngineandGdsEngineplanned only in batch, behindBufferedPlanBuilder, which copies every item into a vector first.The interface was also the wrong way round.
Plan()was the pure virtual, andCreatePlanBuilder()an optional override defaulting to the buffered builder. A new engine that implemented onlyPlan()would quietly get the slow path.Change
One planning hook.
TransferEngine::CreatePlanBuilder()is pure virtual.Plan()is a non-virtual base method: the builder run over the vector. Removed:Plan()overrides;BufferedPlanBuilder;PlanViaBuilderhelper.A new engine can't compile without a builder, so it can't silently plan in batch.
The rules every builder keeps are written on
TransferPlanBuilder:Add()does no IO and changes no engine state;CanHandle()refuses the pair, or a range is out of bounds) goes torejected_tags;Shared pieces (
transfer/plan_builder.h):PairPlanBuilder, a whole builder for engines with one plan per (src, dst) buffer pair. It does the admission check (CanHandle()+ bounds), the pair map with a fast path for consecutive items of the same pair, and new plans. The engine passes only how to append a segment:AppendSegment.AppendSegment: merge adjacent segments, optional length cap, de-duplicated tags;ItemInBounds/RangeFits;PlanBetween.Engines:
LocalCopyEngineMakePairPlanBuilder(*this, AppendSegment): 6 linesHbmCopyEngineMakePairPlanBuilder+ its piece-split appendMoriIoEnginePlan()onlyGdsEnginePlan()onlyCompositeTransferEnginePlan()Plan()comes from the baseSource lines (excluding tests and docs), against
320ddabf9: +324 / −445.The
umbp-add-transfer-engineskill now covers the hook, the rules, when to usePairPlanBuilderversus writing a builder, and the contract test helper. MORI-IO's planner is noted as unit-testable.Behaviour change: composite plan order. For a mixed batch, the composite's
Plan()now groups plans by engine, with engines in first-seen order. It wasunordered_maporder. Each engine's own plans are unchanged.Verification
Plans are unchanged. A scratch harness (not in this PR) dumps every engine's
Plan()for seeded random batches. Built against320ddabf9and against this PR, the dumps are byte-identical: 42 plan sets, 8,450 lines. Composite mixed batches are compared sorted, because of the ordering change above.Unit tests:
test_transfer_engine21/21 andtest_gds_engine3/3 (built with the hipfile headers, including the GPU read).MoriIoEngine.GroupsZeroCopyByEndpointsAndCapsSegmentsandMoriIoEngine.StagesUnregisteredMemoryThroughTheBouncePool, the first tests of MORI-IO's planner. It needs no fabric, so the engine is neverInit()ed.HbmCopyEngine.BuilderSplitsAtHostRegistrationPieces.LocalCopyEngine.MergesWithinEachPairWhenPairsInterleave, which exercises the repeat-pair fast path.ExpectPlanContractchecks the builder rules on every engine's planning test: every item rejected or planned, accepted bytes planned exactly once.CreatePlanBuilder().LocalCopyEngine.BuilderMergesAdjacentRangesandBuilderRejectsOutOfBoundsRanges, which repeat thePlan()tests now thatPlan()is the builder. Their one extra case (an empty item is dropped) moved into the interleave test.Full UMBP suite: 54/54.
umbp_cross_node_smokeandumbp_pool_client_rangesabort underctest -j 8(RDMA device contention, as onmain) and pass serially.Planning cost: A/B of
320ddabf9against this PR (cc78f01ca), run with perf(umbp): build LocalCopyEngine transfer plans incrementally #765's microbenchmark. Kimi-K3 TP8 FP8, 999,936 tokens; median of 36 runs pinned to one core. Plan checksums are identical in every cell.Incremental path (what
BatchGetRangesuses), old → new:Plan()over a vector: a mixed batch no longer copies its items into per-engine vectors, so it is about 2× faster end to end (70.1 → 37.5 ms at 64 KiB, 148.4 → 75.8 ms at 32 KiB). A uniform batch's plan step drops 6.7 → 3.7 ms (GPU) and 5.8 → 3.4 ms (host).Merging with #763
#763 adds a
FailingEnginetest fake that overridesPlan(). Whichever of the two lands second switches it toCreatePlanBuilder(), a one-line change, as in merge07c26da29ontest/umbp-e2e-v4.Not in this PR
Transfer(vector)callers ontoCreatePlanBuilder(). That covers the remote ranged-get scatter,BatchPutRangesassembly,ServeLocalGets,ExecuteLocalPutRangesBatchandExecuteBatchPutPlan.PoolClient::BatchGetRangesstill mentions "buffered engines". fix(umbp): SSD staging no longer fails local loads; a local read holds its bytes until it is done #762 rewrites that block, so I've left it to avoid a conflict.🤖 Generated with Claude Code