Molecular dynamics (MD) is a very active research field that is continuously progressing. 1,2
Among the various evolutions of the field, the definition of force fields themselves grows more complex. Indeed, beyond the popular pairwise additive models 3-7 that remain extensively used, polarizable force field (PFF) approaches are becoming increasingly mainstream and start to be more widely adopted, [8] [9] [10] [11] mainly because accounting for polarizability is often crucial for complex applications and adding new physics to the model through the use of many-body potentials can lead to significant accuracy enhancements. 10 Numerous approaches are currently under development but a few methodologies such as the Drude [12] [13] [14] or the AMOEBA 15-17 models emerge. These models are more and more employed because of the alleviation of the main bottleneck of these methods: their larger computational cost compared to classical pairwise models. Indeed, the availability of High Performance Computing (HPC) implementations of such models within popular packages such as NAMD 18 or GROMACS 19 for Drude or Tinker-HP 20 for AMOEBA fosters the diffusion of these new generation techniques within the research community. This paper is dedicated to the evolution of the Tinker-HP package. 20 The software, which is part of the Tinker distribution, 21 was initially introduced as a double precision massively parallel MPI addition to Tinker dedicated to the acceleration of the various PFFs and non-polarizable force fields (n-PFFs) present within the Tinker package. The code was shown to be really efficient, being able to scale on up to tens of thousand cores on modern petascale supercomputers. 20, 22 Over the years, it has been optimized on various platforms taking advantage of vectorization and of the evolution of the recent CPUs (Central Processing Units). 22 However, in the last 15 years, the field has been increasingly using GPUs (Graphic Processor Unit) 23-25 taking advantage of low precision arithmetic. Indeed, such platforms offer important computing capabilities at both low cost and high energy efficiency allowing for reaching routine microsecond simulations on standard GPUs cards with pair potentials. 24, 26 Regarding the AMOEBA polarizable force field, the OpenMM package 27 was the first to propose an AMOEBA-GPU library that was extensively used within Tinker through a specific implementation that could be used in Tinker using the Tinker-OpenMM GPU interface. 28 The present contribution aims to address two goals: i) the design of an efficient native Tinker-HP GPU implementation; ii) the HPC optimization in a massively parallel context to address both the use of research laboratories clusters and modern multi-GPUs pre-exascale supercomputer systems. The paper is organized as follows. First, we will describe our OpenACC port and its efficiency in double precision. After observing the limitations of this implementation regarding the use of single precision, we introduce a new CUDA approach and detail the various parts of the code it concerns after a careful study of the precision. In both cases, we present benchmarks of the new code on illustrative large biosystems of increasing size on various NVIDIA platforms (including 2080Ti, V100 and A100 cards). Then, we explore how to run on even larger systems and optimize memory management by making use of latest tools such as NVSHMEM. 29 OpenACC Approach
Tinker-HP is a molecular dynamics application with a MPI layer allowing a significant acceleration on CPUs . The core of the application is based on the resolution of the classical newton equations 30, 31 given an interaction potential (force field) between atoms. In practice, a molecular dynamic simulation consists into the repetition of the call to an integrator routine defining the changes of the positions and the velocities of all the atoms of the simulated system between two consecutive time steps. The same process is repeated as many times as needed until the simulation duration is reached (see Figure 3 ). To distribute computations over the processes, a traditional three dimensional domain decomposition is performed on the simulation box (Ω) which means that it is divided in subdomains (ψ), each of which being associated to a MPI process. Then, at each time step, positions of the atoms and forces are exchanged between processes before and after the computation of the forces. Additionally, small communications are required after the update of the positions to deal with the fact that an atom can change of subdomain during a time step. This workflow is described in detail in reference. 31 In recent years a new paradigm has emerged to facilitate computation and programming on GPU devices. In the rest of the text, we will denote as kernel the smallest piece of code made of instructions designed for a unique purpose. Therefore a succession of kernels might constitute a routine. Then a program can be seen as a collection of routines, each of them representing an essential component of an application. There are two types of kernels • Serial kernel, mostly used for variable configuration • Loops kernel, operating on multiple data sets This approach, called OpenACC , 32,33 is a directive-based language close to the multithreading OpenMP paradigm with an additional complexity level. Since a target kernel is destined to be executed on GPUs , it becomes crucial to manage data between GPUs and CPUs . At the most elementary level, OpenACC interacts on a standard host (CPU) kernel and generates a device (GPU) kernel using directives implemented to describe its parallelism along with clauses to manage global data behaviour at both entry and exit point and/or kernel launch configuration [ Figure 1 ]. This method offers two majors benefits. Unlike the low-level CUDA programming language, 34 it takes only a few directives to generate a device kernel. Secondly, the same kernel is compatible with both platforms -CPUs and GPUs -.
The portability along with all the associated benefits such as host debug is therefore ensured.
However, there are some immediate drawbacks mainly because CPUs and GPUs do not share the same architecture and specifications. While CPUs are optimized for serial tasks, a full GPU compute potential can only be reached with parallel tasks. This requires a parallelism property on most device kernels. As a direct consequence, it may be necessary to reshape kernels to fit device architecture in order to get appropriate acceleration. Once we clearly exhibit a kernel parallelism and associate OpenACC directives to offload it on device, it should perform as well as if it had been in native CUDA. Still, in addition to kernel launch instruction (performed by both OpenACC and CUDA ) before the appropriate execution, there is a global data checking operation overhead which might slow down execution [ Figure   1 ]. However, this operation can be overlapped using asynchronous device streams in the kernel configuration [ Figure 2 ]. It is safe to assume that under proper conditions, there should not be any major performance difference between both OpenACC and CUDA.
In the following, we will say that a kernel is semi-parallel if one can find a partition inside the instructions sequence which does not share any dependency at all. A semi-parallel kernel is consequently defined parallel if all instructions in the partition do not induce a race condition within its throughput. Once a kernel is device compiled, his execution requires a configuration which define the resources provided by the device to perform on it. With OpenACC , those resources are respectively the total number of threads and the assignment stream. We can access the first one through the gang and vector clauses attached to a device compute region directive.
A gang is a collection of vectors inside of which every thread can share cache memory. All gangs run separately on device streaming multi-processors (SM) to process kernel instructions inside a stream where many other kernels are sequentially queued. OpenACC offers an intermediate parallelism level between gang and vector called worker . This level can be seen as a gang subdivision.
It is commonly known that GPUs are inefficient for sequential execution due to their latency. To cover up latency, each SM comes with a huge register file and cache memory in order to hold and run as many vectors as possible at the same time. Instructions from different gangs are therefore pipe-lined and injected in the compute unit. 34, 35 From this emerges the kernel occupancy's concept which is defined as the ratio between the gang's number concurrently running on one SM and the maximum gang number that can actually be held by this SM. 
The parallel computing power of GPUs is in constant evolution and the number of streaming multiprocessors (SM) is almost doubling with every generation unlike traditional CPUs .
Considering their impressive compute potential in comparison to CPUs, it becomes safe to assume that the only way to fully benefit from this power is by offloading the entire application on device. Any substantial part of the workflow of Tinker-HP should not be performed on the CPU platform. It will otherwise represent a bottleneck to performance in addition to requiring multiple data transfers. As for all MD applications, most of the computation lies in the evaluation of the forces. For the AMOEBA polarizable model, it takes around 97% of a time step to evaluate those forces when running sequentially on CPU platform. Of these 97%, around 10% concern bonded forces and 90% the non bonded ones, namely: polarization, (multipolar) permanent electrostatics and van der Waals. The polarization which includes the iterative resolution of induced dipoles largely dominates this part (see [ Figure 3 ]). Non-bonded forces and polarization in particular will thus be our main focus regarding the porting and optimization. We will then benefit from the already present Tinker-HP MPI layer 20, 22 to operate on several GPUs . The communications can then be made directly between GPUs by using a CUDA aware MPI implementation. 36 The Smooth
Particle Mesh Ewald method 31, 37, 38 is at the heart of both the permanent electrostatics and polarization non-bonded forces used in Tinker-HP , first through the iterative solution of the induced dipoles and then through the final force evaluation. It consists in separating the electrostatic energy in two independent pieces: real space contribution and reciprocal space contribution. Let us describe our OpenACC strategy regarding those two terms.
Because the real space part of the total PME energy and forces has the same structure as the van der Waals one, the associated OpenACC strategy is the same. Evaluating real space energy and forces is made through the computation of pairwise interactions. Considering n atoms, a total of n(n−1) pairwise interactions need to be computed. This number is reduced by half because of the symmetry of the interactions. Besides, because we use a cutoff distance after which we neglect these interactions, we can reduce their number to being proportional to n in homogeneous systems by using neighbor lists. The up-bound constant is naturally reduced to a maximum neighbors for every atoms noted as Neig max .
The number of interactions is up-bounded by n * Neig max . In terms of implementation, we have written the compute algorithm into a single loop kernel. As all the interactions are independent, the kernel is semi-parallel. By making sure that energy and forces are added one at a time, the kernel becomes parallel. To do that, we can use atomic operations on
GPUs which allow to make this operation in parallel and solve any race condition issue without substantially impacting parallel performance. By doing so, real space kernels looks Listing 1: OpenACC real space offload scheme. The kernel is offloaded on device using two of the three parallelism levels offered by OpenACC . The first loop is broken down over gangs and gathers all data related to atom iglob using gang's shared memory through the private clause. OpenACC vectors are responsible of the evaluation and the addition of forces and energy after resolving scaling factor if necessary. Regarding data management we make sure with the present clause that everything is available on device before the execution of the kernel.
At first, our approach was designed to directly offload the CPU vectorized real space compute kernels which use small arrays to compute pairwise interactions in hope to align memory access pattern at the vector level and therefore accelerate the code. 22 This requires each gang to privatize every temporary array and results in a significant overhead with memory reservation associated to a superior bound on the gang's number. Making interactions computation scalar helps us remove those constraints and double the kernel performance.
The explanation behind this increase arises from the use of GPU scalar registers. Still, one has to compute the scaling factors of the interactions. As it happens inside gang shared memory, the performance is lightly affected. However, we would benefit from a complete removal of this inside search. Two drawbacks are to be listed.
> Scaling interactions between neighboring atoms of the same molecule can become very complex. This is particularly true with large proteins. Storage workspace can potentially affect shared memory and also kernel's occupancy.
> Depending on the interactions, there is more than one kind of scaling factor. For example, every AMOEBA polarization interaction needs three different scaling factors.
The best approach is then to compute scaling interactions separately in a second kernel.
Because they only involve connected atoms, their number is small compared to the total number of non-bonded interactions. We first compute unscaled non-bonded interactions and then apply scaling correction in a second part. An additional issue is to make this approach compatible with the 3d domain decomposition. Our previous kernel then reads: 2. Regarding parallelism, Tinker-HP uses a two dimensional decomposition of the associated 3d grid based on successive 1D FFt's . Here, we use the cuFFt library. 39 The OpenACC offload scheme for reciprocal space is described in [ Figure 4 ] Figure 4 : Reciprocal space offload scheme. Charge interpolation and Force interpolation are both written in a single kernel. They are naturally parallel except for the atomic contributions to the grid in the first one. The approach remains the same for data management between host and device as for real space: all data are by default device resident to prevent any sort of useless transfer. Regarding MPI communications, exchanges take place directly between GPUs through interconnection.
We just reviewed our offload strategy of the non-bonded forces kernels with OpenACC , but the bonded ones remain to be treated. Also, the MPI layer has to be dealt with. The way bonded forces are computed is very similar to the real space ones, albeit simpler, which makes their offloading relatively straightforward. MPI layer kernels require, on the other hand, a slight rewriting as communications are made after a packing pre-treatment. In parallel, one does not control the throughput order of this packing operation. This is why it becomes necessary to also communicate the atom list of each process to their neighbors. Now that we presented the main offload strategies, we can focus on some global optimizations regarding the implementation and execution for single and multi-GPUs . We were able to identify and apply several optimizations during our work. Some of them lead to very different results depending on the device architecture. Here, the idea is to reduce the computation and favor coalesce memory access by precomputing and storing the elements of (the real space part) of the matrix before the iterations.
As the matrix-vector product is being repeated, we see a performance gain starting from the second iteration. But this method is memory consuming, and more suitable to host execution or a high level of multi device parallelism where the memory can be distributed.
> An additional improvement concerns the two dimensional domain decomposition of the reciprocal space 3D grid involved with FFt. The parallel scheme for FFt used in Tinker-HP is the following for a forward transform:
Each Transposition represents an all-to-all MPI communication which is the major bottleneck preventing most MD Applications using PME to scale across nodes. 22, 31, 41 Given the GPUs huge compute power, this communication is even more problematic in that context. On device, we use the cuFFt 39 library. Using many cuFFt 1d batches is not as efficient as using less batches in a higher dimension. Indeed, devices are known to under perform with low saturation kernels. In order to reduce MPI exchanges and increase load on device, we adopted a simple 3d dimensional cuFFt batch when running on a single device. On multiple GPUs , we use the following scheme based on a 1d domain decomposition along the z axis :
which gives a 25% improvement compared to the initial approach.
> Profiling the application on a single device, we observed that real space computation is on average 5 times slower than reciprocal space computation. This trend reverses using multiple GPUs because of the communications mentioned above. This motivated the assignment of these two parts in two different priority streams. The reciprocal kernels along with MPI communications are queued inside the higher priority stream, and real space kernels -devoid of communications -can operate at the same time on the lower priority stream to recover communications. This is illustrated in [ Figure 6 ]. Figure 6 : Representation of cuFFt's communication recovering using device stream computation between direct and reciprocal space. Real space computation kernels are assigned to asynchronous stream 18. reciprocal ones goes into high priority asynchronous stream 17. real space kernel therefore recovers FFt grid exchanges. This profile was retrieved on 2GPUs .
Here, we use the same bench systems as in reference. 20, 22 These are the solvated DHFR2 protein, along with the solvated COX protein and the STMV virus, all with the AMOEBA force field.
They hold respectively 23 558, 171 219 and 1 066 600 atoms. The molecular dynamics simulations were run in the NVT ensemble at 300K for 5 pico-seconds simulation using a (bonded/non-bonded) RESPA integrator with a 2fs outer timestep (and a 1fs inner time step) 42 and the Bussi thermostat. 43 For validation purposes, we compared the results of the first time step between Tinker-HP v1.2 release version and the GPU one. Note that we used here double precision DP on all platforms. Furthermore, we compared our results to a well known MD application: Tinker-OpenMM in the same exact setup. 28 We can directly observe the technical superiority of the Quadro architecture compared to the Geforce one. Double precision compute units of the V100 allow to vastly outperform the Geforce. In addition, by comparing the performance of the Geforce RTX to the one of the Quadro GV100, we see that Quadro devices are much less sensitive to warp discrepancy 36 This results is very satisfactory as a single V100 card is at least ten times faster than an entire node of this supercomputer using only CPUs.
Multi-device benchmark results compared with host-platform execution are presented in [ Figure 7 ]. DHFR2 is to small to scale out. MPI communications overcomes the computations even with optimizations. On the other hand, COX and STMV show good multi-gpu performances. Adding our latest MPI optimizations -FFt reshaping and asynchronous compute between direct and reciprocal part of PME -allows an additional substantial gain in performances. We see that on a Jean-Zay node we can only benefit from the maximum communication bandwidth when running on the entire node, hence the relative inflexion point on the STMV performances on 2 GPUs . Indeed, all devices are interconnected inside one node in such a way that they all share interconnection bandwidth. More precisely, running on 2 GPUs reduces bandwidth by four and therefore affects the scalabity. It is almost certain that results would get better on an interconnected node made exclusively of 2 GPUs . Those results are more than encouraging considering the fact that we manage to achieve them with a full OpenACC implementation of Tinker-HP (direct portage of the reference CPU code) in addition to some adjustments. Figure 7 : Performance ratio between single node GPU and single node CPU performance. Reference values can be found in [Table 1 ].
In summary, our DP implementation is already satisfactory compared to other applications such as Tinker-OpenMM. Our next section concerns the porting of Tinker-HP in single and mixed precision. As a reminder, our main goal is to provide an efficient GPUs implementation of PFF in Tinker-HP which can deliver high performances and good accuracy in every computational mode in addition of providing new scientific methods and features.
Even Figure 8 ] suggests that there is still room for improvements in order to take full advantage of the card's computing power and memory bandwidth both in SP and DP .
In order to exploit device SP computational power and get rid of the bottleneck exposed by [ Figure 8 ], it becomes necessary to reshape our implementation method and consider some technical aspects beyond OpenACC 's scope. 
As mentioned in the previous section, GPUs are the most efficient with parallel computations and coalescent memory access patterns. This notion is very close to SIMD vectorization 22, 44 but with the possibility to apply it at a very large scale. This is the concept of Single Program
Multiple Data (SPMD) approach. To improve the results presented in the last paragraph Figure 8 : Profile of the matrix-vector compute kernel on the DHFR2 system. The left picure is obtained from the double precision run and the right one from simple precision. In both modes, results indicate an obvious latency issue coming from memory accessing pattern which prevents the device to reach its peak performance.
[ Table 2 ] and to reach peak performance on computation and throughput, it becomes crucial to expose more computation in real space kernels and to minimize global memory accesses to benefit from cache & shared memory access on the other hand. To achieve that, we decided to rewrite those specific kernels using the standard approach of low-level device programming in addition to CUDA built-in intrinsics. We describe our corresponding strategy in a following section, but let us first review the issue of the precision.
Definition i . We shall call p the machine precision (in SP or DP ), the smallest floating point value such that 1 + p > 1.
Definition ii .Considering a positive floating point variable a, the machine precision a attached to a is
Therefore an error made for a floating point operation between a and b can be expressed as
where⊕ designates the numerical operation between a and b.
Property i . Numerical error resulting from sequential reduction operations are linear while those resulting from parallel reduction are logarithmic. Thus, parallel reductions are entirely suitable to GPUs implementation as they benefit from both parallelism and accuracy. Before looking further into the matter of downgrading precision, we have to make sure that our application is able to work in this mode. Although it has been proven in the lit- When it comes to floating point arithmetics, standard 32 storage bits offer no more than 7 significant digits due to the mantissa. In comparison, we benefit from 16 significant digits with DP 64 storage bits. Without any consideration on the floating number's sign, it is safe to assume that any application working with values outside [10 −7 , 10 7 ] scope will fail to deliver sufficient accuracy when running in complete DP mode. To overcome this matter, the common solution is to use a mixed precision mode which encompasses both modes by using DP on variables subject to overflowing (in practice interactions are computed in SP but accumulated in DP ). This way, we maintain a good accuracy on those entities.
All inputs in Tinker-HP -system data and parameters -are accessible to SP . Then, the same checks with the outputs (energy, force, pressure, ...) has to be made. The description made in the previous section shows that energy evaluation along with virial calculation are linear-dependent with the system's size. Depending on the complexity of the interaction in addition to the number of operations it requires, we can attach a constant error value named i to it. Thus, we can bound the error made on the computation of a potential energy with N int i < nNeig max i where N int represents the number of interactions contributing to this energy. As this one is linear with respect to the system size we have to evaluate this entity with a DP storage container. Furthermore, to reduce even more the accumulation of error due to large summation, we shall employ buffered parallel reduction instead of sequential reduction [ Figure 9 ]. On the other hand, we have to deal with the forces which remain Furthermore, we must take under consideration the fact that unlike the energy, a sequential reduction using atomic operations is applied to the forces. The resulting error is therefore linear with the total number of summation operations. All those arguments led us to select a DP container on those entities despite the fact they can be held in an SP container. A practical verification of our theoretical analysis has been conducted once our hybrid/mixed precision (MP ) implementation has been achieved. The results are represented in [ Figure   10 ]. The fixed precision arithmetic is also a good choice for small to medium systems. Our interpretation of those results is that Tinker-HP is fine with mixed precision simulations.
However, as one can see, if errors remain very low for forces even for large systems, a larger error exists for energies, a phenomenon observed in all previous MD GPUs implementations. 
We want to expose the maximum of computation inside a kernel using the device shared memory. To do so, we consider the approach where a specific group of atoms interacts with another one in a block-matrix pattern (see [ Figure 11 ]). We need to load the parameters of Figure 10 : Absolute error between double precision implementation and mixed precision implementation on total potential energy. Forces root mean square deviation between DP and MP for systems from 648 up to 2 592 000 atoms. As expected, error on the energy grows linearly with the system size. Logarithmic regression gives 0.99 value for the curve slope. We reach 70 kcal/mol on the highest system. The relative energy for all systems is located under 1 × 10 −5 . Regarding forces, the slight variations are due to the sensibility of the bonded forces to the conformation of the system: we can either obtain a slight growing error or an accurate RMSD like the 1 509 506 atoms test case. These numbers justify the use of Tinker-HP in mixed precision mode to perform accurate sampling.
the group of atoms and the output structures needed for computation directly inside cache memory and/or registers. On top of that, CUDA built-in intrinsics can be used to read data from neighbor threads and if possible compute cross term interactions. Ideally, we can expose B comp = B 2 size computations without a single access to global memory, with B size representing the number of atoms within the group. With this approach, the kernel should reach its peak in terms of computational load.
A new approach of the neighbor list algorithm is necessary to follow the logic presented above. This method will be close to standard blocking techniques used in many MD applications. 25, 27 Let us present the structure of the algorithm in a sequential and parallel -MPI -context. We consider in the following that each group deals with interactions involving atoms within a region of space. In order to maximize B comp between every pair of groups, we must then ensure their spatial compactness. Moreover, all these regions need to define a partition
of Ω to make sure we do not end up with duplicate interactions. Following this reasoning, we might be tempted to group them into small spheres but it is impossible to partition a polygon with only spheres; not to mention the difficulties arising from the implementation point of view.
The MPI layer of Tinker-HP induces a first partition of Ω in P subdomains ψ p , p ∈ [0..P ]
where P is the number of MPI processes. Tinker-HP uses the midpoint image convention 46 so that the interactions computed by the process assigned to ψ p are the ones whose midpoint falls into ψ p . The approach used in Tinker-HP for the non bonded neighbor list uses a cubic partition ω c , c ∈ [1..Nc] of ψ p and then collects the neighboring atoms among the neighboring cells of ω c . Here, we proceed exactly in the same way with two additional conditions to the partitioning. First, the number of atoms inside each cell ω c must be less or equal than B size .
Second, we must preserve a common global numbering of the cells across all domains ψ p to benefit from a unique partitioning of Ω.
Once the first partitioning in cells is done, an additional sorting operation is initiated to define groups so that each of them contains exactly B size spatially aligned atoms following the cell numbering (note that because of the first constrain mention earlier, one cell can contain atoms belonging to a maximum of two groups). More precisely, the numbering of the cells follows a one dimensional representation of the three dimension of the simulation box. Now, we want to find the best partitioning of ψ p in groups that will ensure enough proximity between atoms inside a group, minimizing the number of neighboring groups and consequently maximizing B comp .
When the partitioning generates too flat domains, each group might end up having too many neighboring groups. The optimal cell shape (close to a sphere) is the cube but we must not forget the first constrain and end up with a very thin partition either. However, atom groups are not affected by a partition along the inner most contiguous dimension in the cell numbering. We can exploit this to get better partitioning. [ Figure 12 ] illustrates and explains the scheme on a two dimensional box. Partitioning is done in an iterative manner by cycling on every dimension. We progressively increase the number of cells along each dimension starting on the contiguous one until the first condition is fulfilled. During a parallel run, we keep track of the cell with the smallest number of atoms with a reduction operation. This allows to have a global partitioning of Ω and not just ψ p . Re-indexing all the atoms following the cells numbering and separating them equally shows all the groups. Here B size = 16. A unique color is associated to every atom belonging to the same group. No cell contains more than B size atoms or 2 groups. Once a group is selected -23-, searching for its neighboring groups is made through the set of cells (with respect to the periodic boundary condition) close to the cells it contains -43 & 44 -. Once this set is acquired, all the group indexes greater or equal than the selected group constitute the actual list of neighbors to take the symmetry of the interactions into account. We see that the group's shape modulates the group neighborhood as illustrated with the right illustration and a spatially flat group 23. Once the adjacency matrix is built, a simple post-processing gives us the adjacency list with optimal memory size and we can use the new list on real space computation kernels following the process described in the introduction of this subsection and illustrated in [ Figure   11 ]. In addition, we benefit from a coalesced memory access pattern while loading blocks data and parameters when they are spatially reordered.
We can improve the performance of our group-group pairing with an approach similar to the list reordering method mentioned in the optimizations presented above. The principle is to filter every neighboring group in order to get a list of atoms which really belong to a group's neighborhood. The process is achieved by following the rule:
α and α i are atoms, β represents a group of B size atoms, B is the neighborhood of a group and dist : (R 3 × R 3 ) → R is the euclidean distance.
An illustration of the results using the filtering process is depicted in [ Figure 13 ].
After extracting this new list of atoms, it is reinterpreted as a set of groups on which to Figure 13 : Starting from the latest Figure 12 , we represent the geometry resulting from the filtering process. As observed in comparison with the previous list, we significantly reduce group 23 neighborhood with the list filtering-From 144 atoms with the first list to 77 with the filtered one -. B comp increases which corresponds to more interactions computed within each group pair.
interact. When the number of neighbor atoms is not a multiple of B size , we create phantom atoms to complete the actual neighbor lists. A drawback of the filtering process is a loss of coalesced memory access pattern. As it has been entirely constructed in parallel, we don't have control of the output order. Nonetheless, this loss is compensated by an increase of B comp for each interaction between groups, as represented by [ Figure 13 ]. In practice, we measure a 75% performance gain between the original list and the filtered one for the van der Waals interaction kernel. Moreover, [ Figure 14 ] (deep profile of the previous bottleneck kernel: matrix-vector product ) shows a much better utilisation of the device computational capability. We applied the same strategy for the other real space kernels (electrostatics and polarization). 
As mentioned above, the Particle Mesh Ewald method separates electrostatics computation in two spaces -real and reciprocal -. A new profiling of Tinker-HP in single-device mixed precision mode with the latest developments shows that the reciprocal part is the new bottleneck. More precisely, real space performs 20% faster than reciprocal space within a standard PME setup. Moreover, reciprocal space is even more a bottleneck in parallel because of the additional MPI communications induced by the cuFFt Transformations. This significantly narrows our chances of benefiting from the optimizations mentioned in the previous optimization subsection. However, as both parts are independent, we can distribute them on different MPI processes in order to reduce or even suppress communications inside FFt's .
During this operation, a subset of GPUs are assigned to reciprocal space computation only. Depending on the system size and the load balancing between real and reciprocal spaces, we can break through the scalability limit and gain additional performance on a multi-device configuration.
The precision study already showed that Tinker-HP will be suited to mixed precision simulations. At least when it comes to molecular dynamics using PFF, the error made during forces evaluation is almost constant with the system size. In other words, we are safe from floating point overflow in addition to benefiting from a correct accuracy consistent with double precision simulations. To validate our implementation, we compare a 1 nanosecond long simulation in double precision on CPU (Tinker-HP 1.2) in a constant energy setup (NVE) with the exact same run using the GPU mixed precision implementation, using a 0.5 fs time step and the DHFR2 solvated protein [ Figure 15 ]. We see that using the mixed precision GPU implementation, the total energy fluctuates within −1 and 3 kcal/mol during the run, showing the good accuracy of the simulation in this mode.
After this validation, we focused on porting the main features of Tinker-HP to the GPU implementation such as its various integrators like the new multi-time step integrators: RESPA1 and BAOAB-RESPA1 47 which allows to use up to a 10 fs time step with PFF (this required to create new neighbor lists to perform short-range non-bonded interactions computations for both van der Waals and electrostatics). Aside from Langevin integrators, we ported the Bussi 43 (which is the default) and the Berendsen thermostats, as well as the Monte-Carlo Figure 15 : Variation of the total energy during a NVE molecular dynamics simulation of the DHFR2 protein in both DP and mixed precision. and the Berendsen barostats. We also ported free energy methods such as the Steered Molecular Dynamics 48 and van der Waals soft cores for alchemical transformations, as well as the enhanced sampling method Gaussian Accelerated Molecular Dynamics. 49 Even if it is not the main goal of our implementation as well optimized softwares suited to such simulations exist, we also ported the routines necessary to use standard non-polarizable force fields such as CHARMM, 4 Amber 5 or OPLS. 50 Still, we obtained already satisfactory performances with these models despite a simple portage, the associated numbers can be found in supplementary information and further optimization is ongoing. On top of all these features that concern a molecular dynamics simulation, we ported the "analyze" and "minimize" program of Tinker-HP, allowing to run single point calculations as well as geometry optimizations.
All these capabilities are summed up in table 3
We ran benchmarks on various systems using our mixed precision implementation on GPUs on V100 nodes of the Jean-Zay supercomputer. We also ran the whole set of test on the Irène Puddle ) up to 2 592 000 atoms (i.e Bay ), the DHFR2 , COX and the Main Protease of Sars-Cov2 proteins (M pro ) 51 as well as the STMV virus.
[ Figure 16 ] recaps all the performance results and the number of atoms of the systems.
On a single GPU device, the BAOAB-RESPA1 integrator performs almost twice as fast as RESPA in all test cases -20.81 to 37.91 ns/day on DHFR2 , 0.49 to 1.06 ns/day for the STMV virus. Regarding the RESPA integrator, results compared with those obtained in DP are now close to the Quadro V100 theoretical performance [ Table 1 ]. Speeds ratio are now respectively of 2.24-fold for DHFR2 and 3.88 for STMV . This reinforces our assumption according to witch the first implementation -with standard neighbor list -is not suited to bigger systems like STMV . On the other hand, the parallel scalability starts to be effective above 100 000 atoms. With RESPA, we observe a speed ratio between 1.06 to 1.68 respectively on M pro and bay benches on 4 GPUs compared to a single one. The relatively balanced load between real and reciprocal space with RESPA allows us to break through the scalability limit on almost every GPUs simulations with 2 GPUs with PME separation enabled. For instance, for the STMV case, we have a better performance on 2GPUs with PME separation than with 4GPUs without (0.62 ns/day V 0.57 ns/day), knowing that 2GPUs only benefits from a quarter of interconnection bandwidth available on a node. Such a delay in the strong scalability is understandable given the device computational speed and the messages size imposed by the system and the configuration run. For example, we noticed that for the stmv system using 4GPUs and BAOAB-RESPA1, communications represents 65% of a timestep. This is an indication of the theoretical gain we can obtain with an improvement of the interconnect technology or the MPI layer. Nevertheless, it is already satisfactory to be able to scale on huge systems since one of the goals of the development of Tinker-HP is to efficiently tackle systems containing up to several millions of atoms. Table 4 shows the performance obtained on a single Geforce RTX-2080 Ti with both RESPA and BAOAB-RESPA1 frameworks. We observe similar absolute performances compared to the Jean-Zay V100s for systems up to 100 000 atoms, and the same doubling in performance by using BAOAB-RESPA1. For larger systems, V100 results exceeds the RTX ones.
Furthermore, we compared the performance of our code to an already existing implementation of PFF on GPUs on a V100: Tinker-OpenMM with a similar RESPA framework and observe between 12 and 30% of performance increase depending on the systems. Figure 16 : Single node mixed precision scalability on the Jean Zay Cluster (V100) using the AMOEBA polarizable force field 
We reviewed in the last section the impressive performance obtained by the porting of the Tinker-HP application to GPUs in mixed precision. However one of the goals of the development of Tinker-HP is to be able to treat (very) large biological systems such as protein complexes or entire viruses encompassing up to several millions of atoms. Clearly since march 2020, the present development efforts were reoriented towards enabling the extensive modeling of SARS-Cov-2 proteins using the AMOEBA polarizable force field. The CPU implementation already allowed the simulations of systems like the STMV virus by using several thousands of CPUs cores. 20, 22 The following section reviews the scalability limit of the GPU implementation in terms of system size knowing that GPUs don't have the same memory capabilities.
How far can we go in terms of system size on a single GPUs and at what point a multi-GPUs (potentially on several nodes) simulation becomes really useful? A critical aspect concerns memory: where classical CPU nodes routinely benefit from more than 128 GB of memory, the most advanced Ampere GPU architecture holds up to 40 GB of memory. Thus, it becomes crucial to study and optimize memory distribution in our GPU implementation.
MD with 3D spatial decomposition has its own distribution pattern when it comes to memory distribution among MPI processes. We use the midpoint rule to compute real space interactions as it is done in the CPU implementation. In practice, it means that each process holds information about its neighbors (to be able to compute the proper forces). More precisely, a domain ψ q belongs to the neighborhood of ψ p if the minimum distance between them is under some cutoff distance plus a buffer. To simplify data exchange between processes, we transfer all positions in a single message, the same thing is done with the forces.
An additional filtering is then done to list the atoms actually involved in the interactions computed by a domain ψ p . An atomα ∈ Ω -belong to domain ψ p 's interaction area (λ p )
if the distance between this atom and the domain is below dcut+d buff 2 .
Lets us call n p the number of atoms belonging to the ψ p domain, n b the number of atoms belonging to a process domain and its neighbors and n l the number of atoms inside λ p . This is illustrated in [ Figure 17 ].
One can see that all data reserved with a size proportional to n p are equally distributed among processes. Those with size proportional to n b are only partially distributed. In other words, the distribution for these data strucures is non-existent if all domains ψ p are neighbors. This is why in practice the distribution only takes place at that level with a relatively high number of process -more than 26 at least on a large box with 3d domain decomposition -. On the other hand, data allocated with a size proportional to n l like the neighbor list see their distribution increase with the number of processes depending on the Figure 17 : Two dimensional spatial decomposition of a simulation box with MPI distribution across 16 processes. ω 6 collects all the neighboring domains of ψ 6 . Here n b < n fact that n l is more close to n p than n b . On top of that, some data remains undistributed (proportional to n) like atom parameters for each potential energy term. Splitting those among MPI processes would severely increase the communication cost which we can not afford. As we cannot predict how one atom will interact and move inside the box Ω, the best strategy regarding such data is to make all parameters available to each process. Reference
Tinker-HP reduces the memory footprint of such data by using MPI shared memory space.
Thus, only one parameter data instance is shared among all processes within the same node.
When it comes to multi-GPUs simulations, there is no such things as shared memory between GPUs inside a node. The only way to deal with undistributed data is by replicating all of them on each device. This approach will have serious consequences on memory with large systems: as the system size increases, so does the duplicated memory space. This limits the capability to reach huge systems on GPU platforms. Therefore, we are left with two solutions: waiting for next generations GPUs and their additional memory capabilities, or find a new approach to communicate information between devices. The latter is the topic of the next section.
As OpenACC kernels.
Such a singular approach affects performances since additional communications have to be made inside kernels. Furthermore, all communications do not follow a special pattern that would leave room for optimizations, meaning that each device accesses data randomly Figure 18 : NVSHMEM memory distribution pattern across a four interconnected devices node. A symmetric reserved space is allocated by the NVSHMEM library at initialization. Thus, data is equally split across all devices in order. Every time a device needs to access data allocated with NVSHMEM, either a GMA or RMA is issued.
from the others depending on the atoms involved in the interactions it needs to compute.
In order to limit performance loss, we can decide which data is going to be split across devices and which kernels are going to be involved with this approach. Considering the force fields of interest, it seems reasonable that affecting bonded force kernels with NVSHMEM feature is a good choice. Doing so, we aim to distribute most of the parameter datawhich mainly concern bonded terms (torsions, angles, bonds,...) -and therefore reduce the duplicated memory footprint. We won't touch any undistributed data related to non-bonded interactions to keep those kernels unharmed.
During our NVSHMEM implementation, we were able to detect and optimize several memory wells. For instance, the adjacency matrix described in section 1. has a quadratic memory requirement following the groups of atoms. This means that this represents a potential risk of memory saturation on a single device. To prevent this, we have implemented a buffer limit on this matrix with the intention to construct the pair-group list piece by piece. We have also implemented algorithms that prioritize computing and searching over storing where ever needed -essentially scaling factor reconstruction -. In the end, Tinker-HP is able to simulate a 7 776 000 atoms water box with a performance of 0.15 ns/day with the AMOEBA force field on a single V100 and scale-out to 0.25 ns/day on Jean Zay's one node.
Later in our progression, we had the opportunity to test our implementation on the latest generation NVIDIA GPU Ampere architecture: the Selene supercomputer whis is made of nodes consisting in DGX-A100 servers. A DGX-A100 server contains eight A100 graphic cards with 40 GB of memory each and with latest generation inter-connection NVIDIA Switches. The results we obtained on such a node with the same systems as above in the same RESPA and BAOAB-RESPA1 framework are listed in [ Table 6 ] and [ Figure 19 ].
We observe an average of 50% of performance gain for systems larger than 100 000 atoms on a single A100 compared to a single V100 card. Also, the more efficient interconnection between cards : NV-switch compared to NV-link, allows to scale better on several GPUs with the best performances ever obtained with our code on all the benchmark systems, the larger ones making use of all the 8 cards of the node. Although the code is designed to do so, the latency and the speed of the inter-node interconnection on the present Jean-Zay and Selene supercomputers did not allow us to scale efficiently accross nodes, even on the largest systems. The very fast evolution of the compilators, as well as the incoming availability of new classes of large pre-exascale supercomputers will change this situation. Presently, the use of multiple nodes for a single trajectory is the subject of active work within our group and results will be shared in due course. Still, one can already make use of several nodes with the present implementation by using methods such as unsupervised adaptive sampling as we recently proposed. 51 Such pleasingly parallel approach already offers the possibility to use hundreds (if not thousands!) of GPUs card simultaneously. 
We presented the native Tinker-HP multi-GPUs -multi-precision acceleration platform. The new code is shown to be accurate and scalable across multiple GPUs cards offering unprecedented performances and new capabilities to deal with long timescale simulations on large realistic systems using polarizable force fields such as AMOEBA. The approach strongly reduces the time to solution offering to achieve routine simulations that would have require thousands of CPUs cores on a single GPU card. Overall, the GPU -accelerated Tinker-HP reaches the best performances ever obtained for AMOEBA simulations and extends the applicability of polarizable force fields. The package is shown to be applicable to various computer GPU system architectures ranging from research laboratories to modern supercomputers.
Future work that will lead to Tinker-HP 1.3 will focus on adding additional features (sampling methods, integrators ...) and on further optimizing the performance of the multi-nodes /multi-GPUs to address the exascale challenge. We will improve the non-polarizable force Figure 19 : Performance and one node scalibility results with the AMOEBA force field field simulations capabilities as we will provide the high performance implementations of additional new generation polarizable many-body force fields models such as AMOEBA+, 53, 54 SIBFA 55 and others. Beyond this native GPU platform, Tinker-HP 's users will still conserve the possibility to use the latest OpenMM library thanks to an incoming interface in the spirit of the initial Tinker-OpenMM framework. We will continue to develop the recently introduced adaptive sampling computing strategy enabling the simultaneous use of hundreds (thousands) of GPU cards to further reduce time to solution and deeper explore conformational spaces at high resolution. 51 Indeed, in such simulations that are grounded on the present GPU code have been the basis of our COVID-19 research, one can decompose the global proteins conformational space exploration problem into a set of separate MD trajectories that can be restarted within an iterative selection process able to achieve sufficient phase-space sampling within large biosystems. With such exascale-ready simulation setup, computations that would have taken years can now be achieved in days thanks to GPUs .
Finally, this work, that extensively exploits low precision arithmetic, highlights the key fact that high-performance computing (HPC) grounded applications such as Tinker-HP can now efficiently use converged GPU-accelerated supercomputers, combining HPC and artificial intelligence (AI) such as the Jean Zay machine to actually enhance their performances. Reduction operation illustration on a 16 variables set. Each arithmetic operation generates an error a that is accumulated during the sequential operation. 