Multi-GPU Gromacs Jobs on TinyGPU

Symbolbild zum Artikel. Der Link öffnet das Bild in einer großen Anzeige.

Many of our users are aware that it is possible to allocate more than one GPU on a TinyGPU node. The reason behind running a calculation on more than one GPU is quite simply a hope for increased performance, since gathering the appropriate amount of data for research is often time consuming. So it may come as a surprise that using multiple GPUs for an MD simulation with Gromacs might actually worsen performance or, even if you get some more out of it, still be a waste of resources.

The Setup and first Results

Let’s have a closer look at a standard all-atom MD simulation (protein in membrane) with explicit water (65,209 atoms in total). Command-line flags (e.g. -pme gpu -bonded gpu) ensure that as many calculations as possible will be off-loaded to the GPU; in this case an NVIDIA RTX2080Ti.

Running on one GPU with Gromacs2019, we obtain about 134 ns/day; two GPUs yield up to 176 ns/day and four GPUs give us 230 ns/day. These results might look promising: by quadrupling the number of GPUs, the overall performance increases; after all, we get up to 96 ns/day (~72 %) more than with just one GPU.

What about using newer program versions?

Now let us switch to Gromacs2020 on the same hardware. One GPU: 229 ns/day, two GPUs: 188 ns/day, and four GPUs: 273 ns/day. Even more so with Gromacs 2021; one GPU: 233 ns/day, two GPUs: 195 ns/day, and four GPUs: 294 ns/day.

The gist of this is that newer versions of Gromacs give us the same performance (ns/day) on one GPU  as older versions on four. With the new versions, however, the speedup from one to four GPU is very limited, which is a waste of resources.

And with newer hardware?

On a single NVIDIA RTX3080, the same simulation with Gromacs2021 will give 266 ns/day; two GPUs give 203 ns/day, four GPUs the yield 281 ns/day, and on eight GPUs we get 322 ns/day. Keeping the same input and Gromacs version, the performance on an NVIDIA A100 is the following: one GPU: 332 ns/day, two GPUs: 247 ns/day and four GPUs: 334 ns/day.

It is fairly obvious that the newest generation of NVIDIA GPUs yield the best overall performance due to changes in the architecture. But again, the performance increase from one to multiple GPU is only about 21 % on the RTX3080 — given the cost of the hardware, this does not make sense.

Why is this happening?

One part of the explanation is that the communication between multiple GPU is limited. The Gromacs developers collaborated with NVIDIA engineers and implemented a so-called halo-exchange to increase performance with multiple GPU. The following environment variables need to be set with Gromacs2020 when using multiple GPUs:

export GMX_GPU_PME_PP_COMMS=true
export GMX_GPU_DD_COMMS=true
export GMX_GPU_FORCE_UPDATE_DEFAULT_GPU=true

It is not necessary to set these variables for Gromacs2021; they are already included and setting them explicitly might actually decrease performance again.

Secondly, the increase in performance from Gromacs2019 to Gromacs2020 is due to the possibility to additionally offload yet another part of the calculation to the GPU; up until Gromacs2019, the following calculations could be offloaded to GPU: non-bonded interactions, electrostatics using PME, and bonded interactions. With the release of Gromacs2020, the time-consuming calculation of “updates and constraints” (via the flag -update gpu) was also offloaded to GPU and by that, a large performance gain can be obtained. However, the offloading of “updates and constraints” to GPU does not work when using multiple GPUs, which leads to the observed slowdown.

Furthermore, additional code changes have been implemented in Gromacs2021 that are able to increase performance slightly. Most of the recent changes are about optimizing calculation loops to improve parallel performance; none of these changes impact basic MD functionality.

Are there cases at all that benefit from multiple GPUs?

This is a very tricky question. It looks like there might be some benchmarking inputs that show a speedup from one to eight GPUs; these tests were run on AMD MI100. We have MI100 available in our test cluster.

  1. STMV with Reaction Field-electrostatics: 1 GPU: 15 ns/day, 8 GPUs: 34 ns/day → gain: 127 %
  2. STMV with PME-electrostatics: 1 GPU: 12 ns/day, 8 GPUs: 29 ns/day → gain: 142 %
  3. Lignocellulose with RF-electrostatics: 1 GPU: 6 ns/day, 8 GPUs: 17 ns/day → gain: 183 %

Unfortunately, the speedup is not enough; we have to take the “parallel efficiency” into account. The parallel efficiency is the ratio of the speedup S(N), which quantifies how much faster we can compute with N devices instead of one, and the number of devices, N. For “perfect speedup” we have S(N)=N and thus S(N)/N=1. The parallel efficiency tells us which fraction of the resources is actually used for computation. For instance, if the efficiency is below 0.5, more than half the resources are wasted.

So for the STMV-RF benchmark, the speedup for eight GPUs is S(N) = S(8) = 2.27, but the parallel efficiency S(N)/N = S(8)/8 = 2.27/8 = 0.28 is lower than 0.5 — a threshold that we are convinced is just about reasonable. The parallel efficiency for the STMV-PME benchmark is 0.3 and that for the Lignocellulose benchmark is 0.35. Therefore, even increases in performance that give a speedup of more than 50% can turn out to be a disappointment with regards to parallel efficiency.

Conclusion

Up until now, we know of no (relevant) MD simulation input that can benefit from a multiple GPU setup. Coming back to our first example, were we could observe a speedup of 72% with four GPUs, the parallel efficiency is only 0.43 and so this “promising” result also turns out to be a waste of resources after all.

NHR@FAU recommendation: Before increasing GPU count, switch to newer hardware, but most importantly, use the newest version of the Gromacs simulation code provided as modules by our industrious admins and check if this already improves performance.

If you are unsure how to optimize your simulation setup or need help with benchmarking, please do not hesitate to let us know.