Fix CUDA-aware MPI synchronization in PGemm#7688
Open
Stardust0831 wants to merge 1 commit into
Open
Conversation
Stardust0831
force-pushed
the
fix/pgemm-cuda-mpi-sync
branch
from
July 24, 2026 18:09
fc9a4bd to
7db8b74
Compare
AsTonyshment
left a comment
Collaborator
There was a problem hiding this comment.
This is a good fix! The SAI multi-GPU validation successfully exposed latent issues that previous CPU and single-GPU CI could not cover.
Stardust0831
force-pushed
the
fix/pgemm-cuda-mpi-sync
branch
from
July 25, 2026 08:40
7db8b74 to
1a47d8e
Compare
ZhouXY-PKU
approved these changes
Jul 26, 2026
ZhouXY-PKU
left a comment
Collaborator
There was a problem hiding this comment.
Nice job! Thanks for your contribution!
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.
Reminder
AGENTS.mdanddocs/developers_guide/agent_governance.md.source/changes.Linked Issue
Related to #7665. That PR introduced the SAI multi-GPU validation which exposed this failure and deliberately kept the existing numerical tolerance and reference unchanged. No separate issue is linked because this PR is the focused follow-up to that recorded CI failure.
Unit Tests and/or Case Tests for my changes
The race requires CUDA-aware MPI and multiple physical GPUs, so a CPU-only unit test cannot reproduce it. The existing
16_SDFT_GPU/005_PW_SDFT_MALL_BPCG_GPUcase is used as the regression test without changing its input, tolerance, or reference.Commands/checks run:
python3 tools/03_code_analysis/agent_governance_check.py \ --base origin/develop --head HEAD --format text git diff --check origin/develop..HEAD # The SAI workflow invokes this form for the target case on 2 V100 GPUs: bash tests/integrate/Autotest.sh -a <candidate-abacus> -n 2 -o 8 \ -f CASES.task.txt -r '^005_PW_SDFT_MALL_BPCG_GPU$' gh workflow run sai-gpu-full.yml \ --repo Stardust0831/abacus-develop \ --ref develop \ -f source_sha=1a47d8e8f2ab06be2e240f69cf8d79325bf04bd4 \ -f run_namespace=pgemm-sync-mode3Before/after results from the same SAI GPU workflow and toolchain:
3178e9415ba411e97ef4c8e03c905cf0eab6b5f1(before)703869_51a47d8e8f2ab06be2e240f69cf8d79325bf04bd4(final PR head)708786_5The final-head run rebuilt ABACUS and passed the full 48-case GPU matrix. Its overall workflow conclusion is failure because the separate 2-node cuSolverMp smoke fixture,
tests/15_rtTDDFT_GPU/19_NO_Si48_CUSOLVERMP_TDDFT_GPU, currently exists only in the still-open #7665 and is absent from upstreamdevelop; that smoke exited before launchingmpirun. This is independent of the PGemm path. An earlier composition run containing the same source fix together with the #7665 test infrastructure, 30114759440 atfc9a4bd0005a5cc2c4a0e093bc846a8c74a2d34a, passed all 48 GPU cases and the 2-node/16-GPU cuSolverMp smoke.Focused diagnosis on SAI established the synchronization boundary:
bndpar=1: deterministic and within tolerance.bndpar=2: deterministic and within tolerance.bndpar=2: nondeterministic energy deviations of about1.35e-6to3.88e-6 eVbefore the fix.CUDA_LAUNCH_BLOCKING=1: deterministic and within tolerance, indicating an asynchronous CUDA/MPI handoff race.CUDA_LAUNCH_BLOCKINGunset: 9/9 focused runs passed. Energy deviation was about4.16e-9 eV, force deviation was zero, and stress deviation was1.1e-5, below the existing1e-7,1e-4, and1e-3thresholds.4.69 sbefore and4.57 safter across six measured runs per variant. Run-to-run noise was larger than the difference, so no measurable end-to-end regression was observed.The final PR head passed the SAI candidate build, all 48 GPU cases, governance check, and diff check. The separate composition run passed the 2-node cuSolverMp validation as noted above. No local CUDA build was run because this workspace has no CUDA compiler/build tree; the final candidate was instead rebuilt from its immutable commit on the target SAI toolchain.
What's changed?
PGemmCN::multiply_col()passes the GPU-resident matrixAdirectly to CUDA-awareMPI_Isend. CUDA work producingAis asynchronous, so MPI could begin reading the buffer before the default CUDA stream finished writing it. The timing-dependent read caused the multi-GPU SDFT numerical deviation.This PR synchronizes the default CUDA stream once immediately before each group of nonblocking MPI sends: before
multiply_col()sends GPU-residentAin modes 1/2, and beforemultiply_row()sends GPU-residentBin mode 3. The synchronization is compiled only for CUDA-aware MPI builds, and only the GPU specialization performs work. It is intentionally placed once before all sends rather than once per destination, preserving overlap among theMPI_Isendrequests and avoiding repeated synchronization.Governance Notes
source_basePGemmCN::multiply_col(). CPU and non-CUDA-aware MPI paths are unchanged.