Repository navigation
IBM: sparse per-step ib_heat path indexed by local body slot (no O(num_gbl_ibs) work per step) - #2330
Conversation
|
Claude Code Review Head SHA: c99e7cb Files changed:
Findings:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2330 +/- ##
==========================================
+ Coverage 65.72% 65.75% +0.03%
==========================================
Files 111 111
Lines 30493 30647 +154
Branches 4663 4687 +24
==========================================
+ Hits 20041 20152 +111
- Misses 6692 6711 +19
- Partials 3760 3784 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
GPU measurements for this PR on MI250X (Cray compiler, OpenACC, one rank per GCD, 8 per node), 8 to 64 ranks. Dense is this PR's base (cd2180c), sparse is this head (c99e7cb); both also carry #2335 and #2340, without which this periodic moving-circle case does not run on either. Case: periodic 2D box, N free circles (
This comment was made with Claude Code (AI). |
c99e7cb to
48c6b88
Compare
…_relax, lumped wall, ib_heat_wrt) The per-step heat/mass table, its shard sums, the relax bank and the shell map are indexed by patch_ib slot, not global id, so a step costs O(bodies a rank holds). Several ranks combine a body's partial sums through its owner with point-to-point messages to neighbor ranks instead of an allreduce over every body. The bank is patch_ib%mass_bank, held by the owner and moved with the body at an ownership handoff.
48c6b88 to
f3f4081
Compare
Lines of Code
|
On NVHPC GPU builds the conditional store in s_ib_shell_mass left the shell mass at zero, so the relax correction was never applied.
|
Fix pushed as f8a7221. The 13 moving-body tests (and the fixed-body Tested on the NVIDIA A100 80GB, NVHPC 25.5, OpenACC, with the one-line fix on top of f3f4081: 09FDDC81, 04FB9E91, F1F38949, B7A370B8, 27CD0714, 5C04A681, 997E2B0E, 540C72F1, 30C84CA3, ED2D5C0A, FB3F47C0, 9C0CAF25, 50B98DBF and 5E746B78 all pass. The mechanism is not proven; my best reading is a compiler problem with a conditionally stored private scalar. I found no other conditionally assigned slot or index in the GPU loops of |
|
Independent NVIDIA verification of current
Rows for the sparse ib_heat/relax path and the
Timing is reported only as measurements (above and the label wall times); no before/after comparison against a revert was made. Not run: chemistry tests, OpenMP-offload build, CPU build, any NVHPC other than 25.5, before/after timing of the changes. AI-assisted (Claude Code). |
Contribution Policy
All contributions are expected to demonstrate:
If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions.
Summary
One commit on
origin/mastercd2180c. Wheneverib_exchangeis true (athermal_bc = 3body,ib_heat_wrt, orib_mass_relax > 0, which is now every moving body by default) each step did O(num_gbl_ibs) work on every rank:ib_heat(5, N)andib_part(3, 32, N)indexed by global id, four device loops over1..N, a device-to-host copy, anMPI_Allreduceand a host-to-device copy ofib_heat(40 N bytes each way), plus a replicatedib_mass_res(2, N)bank and a setup allreduce. For 1e5 or more bodies that is the bottleneck. This makes the per-step path O(bodies a rank holds):ib_heat(7, cap)andib_partare indexed bypatch_ibslot (the rank's own bodies plus its neighbors', ass_build_ib_neighborhoodands_handoff_ib_ownershipalready maintain;ib_lookup_*maps a global id to a slot).cap = min(num_gbl_ibs, 2 x max over ranks of num_ibs + 64), allocated once.ib_shellstores the slot. The bank ispatch_ib%mass_bank(already in the struct and in the restart record) and is advanced by the owner;ib_mass_resis removed.s_ib_exchange_heatreplaces the allreduce: one device-to-host copy of 7 reals per held body; each rank sends the nonzero partial sums of bodies it does not own to the owner (one nonblocking message per neighbor rank), the owner adds them in ascending source-rank order and steps the bank; the owner returns the totals and the bank release only to the ranks that sent. No collective, no loop overnum_gbl_ibs. One rank keeps the device-only path with no host copy.s_ib_migrate_banks, one message per old-owner/new-owner pair, exact count).s_update_ib_temperaturesands_conserve_ib_massnow run befores_wrap_periodic_ibs/s_handoff_ib_ownershipins_tvd_rk, because a handoff renumbers slots (this also removes a read ofghost_points%ib_patch_idafter a compaction).ib_neighbor_ranksslots (periodic, few ranks) sent and received each arrival once per slot, sopatch_ibcould hold duplicate entries andnum_ibscould exceednum_gbl_ibs. On master this is harmless to the results (everything is indexed by global id), but it overflows the slot arrays here, so the handoff now takes each sending rank once. It reproduces on master: the 4-body straddle case below at 8 ranks printsnum_ibs > num_gbl_ibsafter 108 handoffs (checked with a one-line print). It may merit its own PR; a handoff abort (@:PROHIBIT) now guardsnum_ibs > cap.The restart record is unchanged.
ib_heat_wrtoutput already came from per-ownerpatch_ibfields, so it has no allreduce to keep. Startup items that remain O(N) per rank and are not changed here: the ib_state reader scans all records unlessfile_per_process;s_check_every_patch_markedallreduces N counters once;patch_iband the lookup arrays are sized bynum_ib_patches_max_namelist; the handoff host-updates all ofpatch_ibeach step.Evidence
Timer: wall time per step of
s_update_ib_temperaturespluss_conserve_ib_mass(benchmark-only instrumentation, not in the commit). It includes the O(local cells) shell and conserve kernels, identical in both versions. Case: periodic 2D box, N free-floating circles at 12.5 % area fraction, 4 cells per diameter,ib_mass_relax = 30. "dense" is the code before this PR (#2301 head), "sparse" this PR. These timings were taken before the last two rebases (the code path is unchanged by them).MI300A (amdflang, OpenMP offload), 1 rank per APU, ms per step, dense / sparse:
At 2 and 4 ranks every rank is a neighbor of every other and holds all N bodies, so there is nothing to save and the sparse exchange (two message phases and an extra device copy) is slower than one allreduce, by 0.1 to 0.6 ms per step. The benefit appears only when ranks hold a fraction of the bodies. That needs many ranks; I could only run that on CPU (same compiler, no GPU), ms per step, dense / sparse:
At 64 ranks each rank holds 9/64 of the bodies: the dense time stays at about 0.10 ms per N/64 and the sparse time at 0.035 to 0.05, about 3x less (the shared cell kernels bound the ratio). At 16 ranks it is a wash. The per-step byte figures for 1e5 bodies on 1000 ranks (about 4 MB plus an allreduce before, about 0.3 MB after) are arithmetic from the layout, not measured; no GPU run used more than 4 ranks.
Correctness: four prescribed moving circles on or crossing rank boundaries (handoffs, bank migration), 300 steps,
ib_mass_relax = 30, final restart file compared with the code before this PR (current master). CPU, deterministic: bitwise identical (fields and ib_state, banks included) at 1, 2, 4, 8 and 16 ranks. The difference between 1 rank and 2/4/8 ranks is 5.7e-12 relative in both builds (partition round-off). On MI300A, where GPU atomics are not deterministic, two runs of the same binary differ by 1e-12 to 1e-9 and sparse versus dense across 1, 2 and 4 ranks falls inside that spread (banks agree to 1e-15). An earlier comparison against the #2301 head showed an 8.9e-10 field difference at 8 and 16 ranks; a per-step check of the exchanged totals and the bank release against an allreduce showed no difference above 1e-12 relative, and against current master the results are bitwise equal, so I believe that was round-off amplification, but I did not prove it.Tests
No new test: the existing moving-body tests now use this path (
ib_mass_relaxdefaults to on for them), including theib_mass_relaxrestart checks and the 2-rank moving-sphere tests.Run on the commit before the final rebase onto cd2180c, which only changes AMR goldens.
./mfc.sh precheckpasses. Not run: A100 / NVHPC (not reachable), Cray CCE and MI250X (CI covers them), the Chemistry label.Limitations
caphas a 2x margin set at start-up; clustering beyond it aborts at a handoff instead of growing.This PR was made with Claude Code (AI).