Many-Field CPU Copies - #421
Open
lightsighter wants to merge 3 commits into
Open
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #421 +/- ##
==========================================
+ Coverage 29.20% 29.50% +0.29%
==========================================
Files 195 196 +1
Lines 40493 40705 +212
Branches 14614 14738 +124
==========================================
+ Hits 11825 12008 +183
- Misses 27715 28270 +555
+ Partials 953 427 -526 ☔ View full report in Codecov by Sentry. |
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
Commit 442cab5 (#284) added a fast path for copies over hundreds or thousands of fields per instance, but only wired it into the CUDA channels. This change generalizes the same optimization to the CPU-side DMA channels — MemcpyChannel (same-node host memory) and RemoteWriteChannel (cross-node via active messages / RDMA) — so that Legion workloads with many-field copies benefit on CPU targets too.
The generic infrastructure (InstanceLayoutGeneric::idindexed_fields, IDIndexedFieldsIterator, FieldBlock, field-aware AddressListCursor, MIN_IDINDEXED_FIELDS) already shipped with #284 — this change implements the CPU-side progress routines and removes the runtime flag that gated the feature, letting Realm pick the fast-vs-slow path automatically from the copy parameters.
Cost model
The decision is made from knowns at graph-construction time (no user-facing knob).
Given N fields over domain volume V with per-field size S, bandwidth B, and total bytes W = N · V · S:
T_slow = N · C_iter + ⌈W/P⌉ · C_pkt + W/B // per-field iterator
T_fast = C_iter + C_fb + ⌈W/P⌉ · C_pkt + W/B // IDIndexedFieldsIterator + FieldBlock
↓
T_slow − T_fast = (N−1) · C_iter − C_fb
Bandwidth and packetization terms cancel; only iterator/XferDes setup overhead differs. C_fb is a single alloc_obj + field-ID memcpy, comparable in magnitude to C_iter, so the break-even is N ≈ 2. The existing MIN_IDINDEXED_FIELDS = 2 constant already encodes this and is now documented inline. At N = 1 only the slow path is valid; the fast path is gated off via this threshold.
Three gates decide fast-path eligibility at graph-construction time:
Changes
MemcpyChannel — local host-memory fast path
src/realm/transfer/memcpy_channel.{h,cc}
RemoteWriteChannel — cross-node fast path
src/realm/transfer/channel.{h,cc}
Remove -ll:dma_multi_field flag
src/realm/runtime_impl.{h,cc}, src/realm/transfer/transfer.cc
The flag is replaced by the cost-model gates described above. All three conditions are known locally at graph-construction time, so no runtime config is needed. MIN_IDINDEXED_FIELDS = 2 is annotated with the derivation so the threshold isn't mystery-magic.
Tests
tests/unit_tests/memcpy_multi_field_test.cc (new, registered in tests/CMakeLists.txt):
9 end-to-end cases driving a real MemcpyXferDes with IDIndexedFieldsIterator on both ports against malloc'd CPU buffers:
tests/multifield_transfer.cc — generalized to CPU or GPU:
Test plan
How to run many-field performance tests
Single-node CPU-to-CPU, field sweep
for F in 1 4 16 64 256 1024 4096; do
./tests/memspeed -copies 1 -tasks 0 -fields $F -aos 1 -b 4 -reps 20
-ll:cpu 4 -ll:csize 16384
done
Multi-node cross-node pairs (RemoteWriteChannel exercised automatically)
mpirun -np 2 ./tests/memspeed -copies 1 -tasks 0 -fields 4096 -aos 1 -b 4
-reps 20 -ll:cpu 4 -ll:csize 16384
Integration test at scale, CPU mode
./tests/multifield_transfer -memkind cpu -num_fields 1024 -size 256
-max_ops 1 -ll:cpu 4 -ll:csize 8192 -verify 1
Out of scope