2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
37 * \brief Declarations for GPU implementation of Leap-Frog.
39 * \author Artem Zhmurov <zhmurov@gmail.com>
41 * \ingroup module_mdlib
44 #ifndef GMX_MDLIB_LEAPFROG_GPU_H
45 #define GMX_MDLIB_LEAPFROG_GPU_H
50 # include "gromacs/gpu_utils/gputraits.cuh"
53 # include "gromacs/gpu_utils/gputraits_sycl.h"
58 #include "gromacs/gpu_utils/devicebuffer_datatype.h"
59 #include "gromacs/gpu_utils/hostallocator.h"
60 #include "gromacs/utility/arrayref.h"
70 /*! \brief Sets the number of different temperature coupling values
72 * This is needed to template the kernel
73 * \todo Unify with similar enum in CPU update module
75 enum class NumTempScaleValues
77 None = 0, //!< No temperature coupling
78 Single = 1, //!< Single T-scaling value (one group)
79 Multiple = 2, //!< Multiple T-scaling values, need to use T-group indices
80 Count = 3 //!< Number of valid values
83 /*! \brief Different variants of the Parrinello-Rahman velocity scaling
85 * This is needed to template the kernel
86 * \todo Unify with similar enum in CPU update module
88 enum class VelocityScalingType
90 None = 0, //!< Do not apply velocity scaling (not a PR-coupling run or step)
91 Diagonal = 1, //!< Apply velocity scaling using a diagonal matrix
92 Count = 2 //!< Number of valid values
99 /*! \brief Constructor.
101 * \param[in] deviceContext Device context (dummy in CUDA).
102 * \param[in] deviceStream Device stream to use.
103 * \param[in] numTempScaleValues Number of temperature scale groups.
105 LeapFrogGpu(const DeviceContext& deviceContext, const DeviceStream& deviceStream, int numTempScaleValues);
110 * Integrates the equation of motion using Leap-Frog algorithm.
111 * Updates coordinates and velocities on the GPU. The current coordinates are saved for constraints.
113 * \param[in,out] d_x Coordinates to update
114 * \param[out] d_xp Place to save the values of initial coordinates coordinates to.
115 * \param[in,out] d_v Velocities (will be updated).
116 * \param[in] d_f Forces.
117 * \param[in] dt Timestep.
118 * \param[in] doTemperatureScaling If velocities should be scaled for temperature coupling.
119 * \param[in] tcstat Temperature coupling data.
120 * \param[in] doParrinelloRahman If current step is a Parrinello-Rahman pressure coupling step.
121 * \param[in] dtPressureCouple Period between pressure coupling steps
122 * \param[in] prVelocityScalingMatrix Parrinello-Rahman velocity scaling matrix
124 void integrate(DeviceBuffer<Float3> d_x,
125 DeviceBuffer<Float3> d_xp,
126 DeviceBuffer<Float3> d_v,
127 DeviceBuffer<Float3> d_f,
129 bool doTemperatureScaling,
130 gmx::ArrayRef<const t_grp_tcstat> tcstat,
131 bool doParrinelloRahman,
132 float dtPressureCouple,
133 const matrix prVelocityScalingMatrix);
135 /*! \brief Set the integrator
137 * Allocates memory for inverse masses, and, if needed for temperature scaling factor(s)
138 * and temperature coupling groups. Copies inverse masses and temperature coupling groups
141 * \param[in] numAtoms Number of atoms in the system.
142 * \param[in] inverseMasses Inverse masses of atoms.
143 * \param[in] tempScaleGroups Maps the atom index to temperature scale value.
145 void set(int numAtoms, const real* inverseMasses, const unsigned short* tempScaleGroups);
147 /*! \brief Class with hardware-specific interfaces and implementations.*/
151 //! GPU context object
152 const DeviceContext& deviceContext_;
154 const DeviceStream& deviceStream_;
159 //! 1/mass for all atoms (GPU)
160 DeviceBuffer<float> d_inverseMasses_;
161 //! Current size of the reciprocal masses array
162 int numInverseMasses_ = -1;
163 //! Maximum size of the reciprocal masses array
164 int numInverseMassesAlloc_ = -1;
166 //! Number of temperature coupling groups (zero = no coupling)
167 int numTempScaleValues_ = 0;
168 /*! \brief Array with temperature scaling factors.
169 * This is temporary solution to remap data from t_grp_tcstat into plain array.
170 * \todo Replace with better solution.
172 gmx::HostVector<float> h_lambdas_;
173 //! Device-side temperature scaling factors
174 DeviceBuffer<float> d_lambdas_;
175 //! Current size of the array with temperature scaling factors (lambdas)
176 int numLambdas_ = -1;
177 //! Maximum size of the array with temperature scaling factors (lambdas)
178 int numLambdasAlloc_ = -1;
181 //! Array that maps atom index onto the temperature scaling group to get scaling parameter
182 DeviceBuffer<unsigned short> d_tempScaleGroups_;
183 //! Current size of the temperature coupling groups array
184 int numTempScaleGroups_ = -1;
185 //! Maximum size of the temperature coupling groups array
186 int numTempScaleGroupsAlloc_ = -1;
188 //! Vector with diagonal elements of the Parrinello-Rahman pressure coupling velocity rescale factors
189 Float3 prVelocityScalingMatrixDiagonal_;