Skip to content

Optimise how the CshiftMap table is calculated and copied to the device #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ilectra
Copy link

@ilectra ilectra commented Mar 27, 2025

This PR improves the performance of Cshift by optimising the way the Cshift_table is calculated and moved to the device:

  • The table doesn't need to save an std::pair<int, int> per index, since those two ints are the same number + lo or ro. So an std::vector<int> is saved instead.
  • The table (now vector) is the same for every slice, therefore it doesn't need to be calculated and copied to the GPU for every slice. So the vector is calculated and copied to the device once before the loop over slices in Cshift_local and Cshift_comms.
  • This new vector is used only for Copy_plane and Copy_plane_permute. For the rest of the functions (Gathers and Scatters) in Cshift_common.h, Cshift_table remains the same, so some template functions have been added to accommodate both cases while avoiding code duplication.

The improvement in performance varies quite a bit depending on the MPI distribution scheme (see table below), but it is significant nonetheless for cases heavy in gauge calculations.

The PR also contains changes from PR #465 and #471 which were used to asses the performance gains in the WilsonFlow and sp2n test cases.

Four test cases were run on Tursa:

  1. tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc
  2. test/hmc/Test_hmc_WilsonFermionGauge.cc
  3. HMC/Mobius2p1f.cc
  4. tests/smearing/Test_WilsonFlow.cc

with up to 3 different MPI configurations:

  • --mpi 1.1.1.1 (no MPI)
  • --mpi 1.1.1.4 (1 node)
  • --mpi 1.1.2.4 (2 nodes).

Based on the table below, test case 3 shows no measurable difference before and after the changes, as expected for a setup with not much contribution from gauge action calculations (and thus not many calls to Cshift).
But the other test cases show improvements, from mild ones for test cases 1 and 2, where the runtime is roughly split equally between gauge and fermion actions, to significant (~18% improvement for the no-MPI case) for test case 4, which is gauge-dominated.
The above improvements are compounded when the changes in this PR are considered on top of the ones in #473 , giving an improvement of ~32% for test case 4, no MPI and ~18% for test case 4, single-node MPI.

This table compares the develop branch at hash 3d01486 , with this branch:

Test case --grid --mpi time develop (s) time cshift-map-optimise (s) improvement (%)
1 24.24.24.48 1.1.1.1 5688.42 5461.26 3.99
1 32.32.32.64 1.1.1.4 7139.31 7026.83 1.58
1 32.32.32.64 1.1.2.4 3735.33 3681.24 1.45
2 24.24.24.48 1.1.1.1 1961.20 1837.46 6.31
2 32.32.32.64 1.1.1.4 2440.00 2372.93 2.75
2 32.32.32.64 1.1.2.4 1314.51 1285.40 2.21
3 24.24.24.48 1.1.1.1 14093.66 14082.41 0.08
4 24.24.24.48 1.1.1.1 168.96 138.59 17.98
4 32.32.32.64 1.1.1.4 225.55 210.95 6.47
4 32.32.32.64 1.1.2.4 133.87 126.55 5.47

@ilectra ilectra marked this pull request as ready for review March 28, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants