2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2017,2018,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
36 * \brief Declares functionality for deciding whether tasks will run on GPUs.
38 * \author Mark Abraham <mark.j.abraham@gmail.com>
39 * \ingroup module_taskassignment
43 #ifndef GMX_TASKASSIGNMENT_DECIDEGPUUSAGE_H
44 #define GMX_TASKASSIGNMENT_DECIDEGPUUSAGE_H
51 enum class PmeRunMode;
58 //! Record where a compute task is targetted.
59 enum class TaskTarget : int
66 //! Help pass GPU-emulation parameters with type safety.
67 enum class EmulateGpuNonbonded : bool
69 //! Do not emulate GPUs.
76 * \brief Structure that holds boolean flags corresponding to the development
77 * features present enabled through environment variables.
80 struct DevelopmentFeatureFlags
82 //! True if the Buffer ops development feature is enabled
83 // TODO: when the trigger of the buffer ops offload is fully automated this should go away
84 bool enableGpuBufferOps = false;
85 //! If true, forces 'mdrun -update auto' default to 'gpu'
86 bool forceGpuUpdateDefault = false;
87 //! True if the GPU halo exchange development feature is enabled
88 bool enableGpuHaloExchange = false;
89 //! True if the PME PP direct communication GPU development feature is enabled
90 bool enableGpuPmePPComm = false;
96 /*! \brief Decide whether this thread-MPI simulation will run
97 * nonbonded tasks on GPUs.
99 * The number of GPU tasks and devices influences both the choice of
100 * the number of ranks, and checks upon any such choice made by the
101 * user. So we need to consider this before any automated choice of
102 * the number of thread-MPI ranks.
104 * \param[in] nonbondedTarget The user's choice for mdrun -nb for where to assign
105 * short-ranged nonbonded interaction tasks.
106 * \param[in] haveAvailableDevices Whether there are available devices.
107 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
108 * \param[in] emulateGpuNonbonded Whether we will emulate GPU calculation of nonbonded
110 * \param[in] buildSupportsNonbondedOnGpu Whether GROMACS was built with GPU support.
111 * \param[in] nonbondedOnGpuIsUseful Whether computing nonbonded interactions on a GPU is
112 * useful for this calculation.
113 * \param[in] numRanksPerSimulation The number of ranks in each simulation.
115 * \returns Whether the simulation will run nonbonded tasks on GPUs.
117 * \throws std::bad_alloc If out of memory
118 * InconsistentInputError If the user requirements are inconsistent. */
119 bool decideWhetherToUseGpusForNonbondedWithThreadMpi(TaskTarget nonbondedTarget,
120 bool haveAvailableDevices,
121 const std::vector<int>& userGpuTaskAssignment,
122 EmulateGpuNonbonded emulateGpuNonbonded,
123 bool buildSupportsNonbondedOnGpu,
124 bool nonbondedOnGpuIsUseful,
125 int numRanksPerSimulation);
127 /*! \brief Decide whether this thread-MPI simulation will run
130 * The number of GPU tasks and devices influences both the choice of
131 * the number of ranks, and checks upon any such choice made by the
132 * user. So we need to consider this before any automated choice of
133 * the number of thread-MPI ranks.
135 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
136 * \param[in] pmeTarget The user's choice for mdrun -pme for where to assign
137 * long-ranged PME nonbonded interaction tasks.
138 * \param[in] numDevicesToUse The number of compatible GPUs that the user permitted us to use.
139 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
140 * \param[in] hardwareInfo Hardware information
141 * \param[in] inputrec The user input
142 * \param[in] numRanksPerSimulation The number of ranks in each simulation.
143 * \param[in] numPmeRanksPerSimulation The number of PME ranks in each simulation.
145 * \returns Whether the simulation will run PME tasks on GPUs.
147 * \throws std::bad_alloc If out of memory
148 * InconsistentInputError If the user requirements are inconsistent. */
149 bool decideWhetherToUseGpusForPmeWithThreadMpi(bool useGpuForNonbonded,
150 TaskTarget pmeTarget,
152 const std::vector<int>& userGpuTaskAssignment,
153 const gmx_hw_info_t& hardwareInfo,
154 const t_inputrec& inputrec,
155 int numRanksPerSimulation,
156 int numPmeRanksPerSimulation);
158 /*! \brief Decide whether the simulation will try to run nonbonded
161 * The final decision cannot be made until after the duty of the rank
162 * is known. But we need to know if nonbonded will run on GPUs for
163 * setting up DD (particularly rlist) and determining duty. If the
164 * user requires GPUs for the tasks of that duty, then it will be an
165 * error when none are found.
167 * With thread-MPI, calls have been made to
168 * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
169 * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
170 * the number of ranks and run some checks, but the final
171 * decision is made in this routine, along with many more
172 * consistency checks.
174 * \param[in] nonbondedTarget The user's choice for mdrun -nb for where to assign short-ranged nonbonded interaction tasks.
175 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
176 * \param[in] emulateGpuNonbonded Whether we will emulate GPU calculation of nonbonded interactions.
177 * \param[in] buildSupportsNonbondedOnGpu Whether GROMACS was build with GPU support.
178 * \param[in] nonbondedOnGpuIsUseful Whether computing nonbonded interactions on a GPU is useful for this calculation.
179 * \param[in] gpusWereDetected Whether compatible GPUs were detected on any node.
181 * \returns Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
183 * \throws std::bad_alloc If out of memory
184 * InconsistentInputError If the user requirements are inconsistent. */
185 bool decideWhetherToUseGpusForNonbonded(TaskTarget nonbondedTarget,
186 const std::vector<int>& userGpuTaskAssignment,
187 EmulateGpuNonbonded emulateGpuNonbonded,
188 bool buildSupportsNonbondedOnGpu,
189 bool nonbondedOnGpuIsUseful,
190 bool gpusWereDetected);
192 /*! \brief Decide whether the simulation will try to run tasks of
193 * different types on GPUs.
195 * The final decision cannot be made until after the duty of the rank
196 * is known. But we need to know if nonbonded will run on GPUs for
197 * setting up DD (particularly rlist) and determining duty. If the
198 * user requires GPUs for the tasks of that duty, then it will be an
199 * error when none are found.
201 * With thread-MPI, calls have been made to
202 * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
203 * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
204 * the number of ranks and run some checks, but the final
205 * decision is made in this routine, along with many more
206 * consistency checks.
208 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
209 * \param[in] pmeTarget The user's choice for mdrun -pme for where to assign long-ranged PME nonbonded interaction tasks.
210 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
211 * \param[in] hardwareInfo Hardware information
212 * \param[in] inputrec The user input
213 * \param[in] numRanksPerSimulation The number of ranks in each simulation.
214 * \param[in] numPmeRanksPerSimulation The number of PME ranks in each simulation.
215 * \param[in] gpusWereDetected Whether compatible GPUs were detected on any node.
217 * \returns Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
219 * \throws std::bad_alloc If out of memory
220 * InconsistentInputError If the user requirements are inconsistent. */
221 bool decideWhetherToUseGpusForPme(bool useGpuForNonbonded,
222 TaskTarget pmeTarget,
223 const std::vector<int>& userGpuTaskAssignment,
224 const gmx_hw_info_t& hardwareInfo,
225 const t_inputrec& inputrec,
226 int numRanksPerSimulation,
227 int numPmeRanksPerSimulation,
228 bool gpusWereDetected);
230 /*! \brief Determine PME run mode.
232 * Given the PME task assignment in \p useGpuForPme and the user-provided
233 * FFT task target in \p pmeFftTarget, returns a PME run mode for the
234 * current run. It also checks the compatibility of the two.
236 * \note Aborts the run upon incompatible values of \p useGpuForPme and \p pmeFftTarget.
238 * \param[in] useGpuForPme PME task assignment, true if PME task is mapped to the GPU.
239 * \param[in] pmeFftTarget The user's choice for -pmefft for where to assign the FFT
240 * work of the PME task. \param[in] inputrec The user input record
242 PmeRunMode determinePmeRunMode(bool useGpuForPme, const TaskTarget& pmeFftTarget, const t_inputrec& inputrec);
244 /*! \brief Decide whether the simulation will try to run bonded tasks on GPUs.
246 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
247 * \param[in] useGpuForPme Whether GPUs will be used for PME interactions.
248 * \param[in] bondedTarget The user's choice for mdrun -bonded for where to assign tasks.
249 * \param[in] inputrec The user input.
250 * \param[in] mtop The global topology.
251 * \param[in] numPmeRanksPerSimulation The number of PME ranks in each simulation, can be -1 for auto.
252 * \param[in] gpusWereDetected Whether compatible GPUs were detected on any node.
254 * \returns Whether the simulation will run bondeded tasks on GPUs.
256 * \throws std::bad_alloc If out of memory
257 * InconsistentInputError If the user requirements are inconsistent. */
258 bool decideWhetherToUseGpusForBonded(bool useGpuForNonbonded,
260 TaskTarget bondedTarget,
261 const t_inputrec& inputrec,
262 const gmx_mtop_t& mtop,
263 int numPmeRanksPerSimulation,
264 bool gpusWereDetected);
266 /*! \brief Decide whether to use GPU for update.
268 * \param[in] isDomainDecomposition Whether there more than one domain.
269 * \param[in] useUpdateGroups If the constraints can be split across domains.
270 * \param[in] pmeRunMode PME running mode: CPU, GPU or mixed.
271 * \param[in] havePmeOnlyRank If there is a PME-only rank in the simulation.
272 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
273 * \param[in] updateTarget User choice for running simulation on GPU.
274 * \param[in] gpusWereDetected Whether compatible GPUs were detected on any node.
275 * \param[in] inputrec The user input.
276 * \param[in] mtop The global topology.
277 * \param[in] useEssentialDynamics If essential dynamics is active.
278 * \param[in] doOrientationRestraints If orientation restraints are enabled.
279 * \param[in] useReplicaExchange If this is a REMD simulation.
280 * \param[in] haveFrozenAtoms If this simulation has frozen atoms (see Issue #3920).
281 * \param[in] doRerun It this is a rerun.
282 * \param[in] devFlags GPU development / experimental feature flags.
283 * \param[in] mdlog MD logger.
285 * \returns Whether complete simulation can be run on GPU.
286 * \throws std::bad_alloc If out of memory
287 * InconsistentInputError If the user requirements are inconsistent.
289 bool decideWhetherToUseGpuForUpdate(bool isDomainDecomposition,
290 bool useUpdateGroups,
291 PmeRunMode pmeRunMode,
292 bool havePmeOnlyRank,
293 bool useGpuForNonbonded,
294 TaskTarget updateTarget,
295 bool gpusWereDetected,
296 const t_inputrec& inputrec,
297 const gmx_mtop_t& mtop,
298 bool useEssentialDynamics,
299 bool doOrientationRestraints,
300 bool useReplicaExchange,
301 bool haveFrozenAtoms,
303 const DevelopmentFeatureFlags& devFlags,
304 const gmx::MDLogger& mdlog);
307 /*! \brief Decide whether to use GPU for halo exchange.
309 * \param[in] devFlags GPU development / experimental feature flags.
310 * \param[in] havePPDomainDecomposition Whether PP domain decomposition is in use.
311 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
312 * \param[in] useModularSimulator Whether modularsimulator is in use.
313 * \param[in] doRerun Whether this is a rerun.
314 * \param[in] haveEnergyMinimization Whether energy minimization is in use.
316 * \returns Whether halo exchange can be run on GPU.
318 bool decideWhetherToUseGpuForHalo(const DevelopmentFeatureFlags& devFlags,
319 bool havePPDomainDecomposition,
320 bool useGpuForNonbonded,
321 bool useModularSimulator,
323 bool haveEnergyMinimization);