Change the behavior of the GPU update UI
[alexxy/gromacs.git] / src / gromacs / taskassignment / decidegpuusage.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2017,2018,2019, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \libinternal \file
36  * \brief Declares functionality for deciding whether tasks will run on GPUs.
37  *
38  * \author Mark Abraham <mark.j.abraham@gmail.com>
39  * \ingroup module_taskassignment
40  * \inlibraryapi
41  */
42
43 #ifndef GMX_TASKASSIGNMENT_DECIDEGPUUSAGE_H
44 #define GMX_TASKASSIGNMENT_DECIDEGPUUSAGE_H
45
46 #include <vector>
47
48 struct gmx_hw_info_t;
49 struct gmx_mtop_t;
50 struct t_inputrec;
51
52 namespace gmx
53 {
54
55 //! Record where a compute task is targetted.
56 enum class TaskTarget : int
57 {
58     Auto,
59     Cpu,
60     Gpu
61 };
62
63 //! Help pass GPU-emulation parameters with type safety.
64 enum class EmulateGpuNonbonded : bool
65 {
66     //! Do not emulate GPUs.
67     No,
68     //! Do emulate GPUs.
69     Yes
70 };
71
72 class MDAtoms;
73
74 /*! \brief Decide whether this thread-MPI simulation will run
75  * nonbonded tasks on GPUs.
76  *
77  * The number of GPU tasks and devices influences both the choice of
78  * the number of ranks, and checks upon any such choice made by the
79  * user. So we need to consider this before any automated choice of
80  * the number of thread-MPI ranks.
81  *
82  * \param[in]  nonbondedTarget             The user's choice for mdrun -nb for where to assign short-ranged nonbonded interaction tasks.
83  * \param[in]  gpuIdsToUse                 The compatible GPUs that the user permitted us to use.
84  * \param[in]  userGpuTaskAssignment       The user-specified assignment of GPU tasks to device IDs.
85  * \param[in]  emulateGpuNonbonded         Whether we will emulate GPU calculation of nonbonded interactions.
86  * \param[in]  buildSupportsNonbondedOnGpu Whether GROMACS was built with GPU support.
87  * \param[in]  nonbondedOnGpuIsUseful      Whether computing nonbonded interactions on a GPU is useful for this calculation.
88  * \param[in]  numRanksPerSimulation       The number of ranks in each simulation.
89  *
90  * \returns    Whether the simulation will run nonbonded tasks on GPUs.
91  *
92  * \throws     std::bad_alloc          If out of memory
93  *             InconsistentInputError  If the user requirements are inconsistent. */
94 bool decideWhetherToUseGpusForNonbondedWithThreadMpi(TaskTarget              nonbondedTarget,
95                                                      const std::vector<int>& gpuIdsToUse,
96                                                      const std::vector<int>& userGpuTaskAssignment,
97                                                      EmulateGpuNonbonded     emulateGpuNonbonded,
98                                                      bool buildSupportsNonbondedOnGpu,
99                                                      bool nonbondedOnGpuIsUseful,
100                                                      int  numRanksPerSimulation);
101
102 /*! \brief Decide whether this thread-MPI simulation will run
103  * PME tasks on GPUs.
104  *
105  * The number of GPU tasks and devices influences both the choice of
106  * the number of ranks, and checks upon any such choice made by the
107  * user. So we need to consider this before any automated choice of
108  * the number of thread-MPI ranks.
109  *
110  * \param[in]  useGpuForNonbonded        Whether GPUs will be used for nonbonded interactions.
111  * \param[in]  pmeTarget                 The user's choice for mdrun -pme for where to assign
112  *                                       long-ranged PME nonbonded interaction tasks.
113  * \param[in]  gpuIdsToUse               The compatible GPUs that the user permitted us to use.
114  * \param[in]  userGpuTaskAssignment     The user-specified assignment of GPU tasks to device IDs.
115  * \param[in]  hardwareInfo              Hardware information
116  * \param[in]  inputrec                  The user input
117  * \param[in]  mtop                      Global system topology
118  * \param[in]  numRanksPerSimulation     The number of ranks in each simulation.
119  * \param[in]  numPmeRanksPerSimulation  The number of PME ranks in each simulation.
120  *
121  * \returns    Whether the simulation will run PME tasks on GPUs.
122  *
123  * \throws     std::bad_alloc          If out of memory
124  *             InconsistentInputError  If the user requirements are inconsistent. */
125 bool decideWhetherToUseGpusForPmeWithThreadMpi(bool                    useGpuForNonbonded,
126                                                TaskTarget              pmeTarget,
127                                                const std::vector<int>& gpuIdsToUse,
128                                                const std::vector<int>& userGpuTaskAssignment,
129                                                const gmx_hw_info_t&    hardwareInfo,
130                                                const t_inputrec&       inputrec,
131                                                const gmx_mtop_t&       mtop,
132                                                int                     numRanksPerSimulation,
133                                                int                     numPmeRanksPerSimulation);
134
135 /*! \brief Decide whether the simulation will try to run nonbonded
136  * tasks on GPUs.
137  *
138  * The final decision cannot be made until after the duty of the rank
139  * is known. But we need to know if nonbonded will run on GPUs for
140  * setting up DD (particularly rlist) and determining duty. If the
141  * user requires GPUs for the tasks of that duty, then it will be an
142  * error when none are found.
143  *
144  * With thread-MPI, calls have been made to
145  * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
146  * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
147  * the number of ranks and run some checks, but the final
148  * decision is made in this routine, along with many more
149  * consistency checks.
150  *
151  * \param[in]  nonbondedTarget             The user's choice for mdrun -nb for where to assign short-ranged nonbonded interaction tasks.
152  * \param[in]  userGpuTaskAssignment       The user-specified assignment of GPU tasks to device IDs.
153  * \param[in]  emulateGpuNonbonded         Whether we will emulate GPU calculation of nonbonded interactions.
154  * \param[in]  buildSupportsNonbondedOnGpu Whether GROMACS was build with GPU support.
155  * \param[in]  nonbondedOnGpuIsUseful      Whether computing nonbonded interactions on a GPU is useful for this calculation.
156  * \param[in]  gpusWereDetected            Whether compatible GPUs were detected on any node.
157  *
158  * \returns    Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
159  *
160  * \throws     std::bad_alloc          If out of memory
161  *             InconsistentInputError  If the user requirements are inconsistent. */
162 bool decideWhetherToUseGpusForNonbonded(TaskTarget              nonbondedTarget,
163                                         const std::vector<int>& userGpuTaskAssignment,
164                                         EmulateGpuNonbonded     emulateGpuNonbonded,
165                                         bool                    buildSupportsNonbondedOnGpu,
166                                         bool                    nonbondedOnGpuIsUseful,
167                                         bool                    gpusWereDetected);
168
169 /*! \brief Decide whether the simulation will try to run tasks of
170  * different types on GPUs.
171  *
172  * The final decision cannot be made until after the duty of the rank
173  * is known. But we need to know if nonbonded will run on GPUs for
174  * setting up DD (particularly rlist) and determining duty. If the
175  * user requires GPUs for the tasks of that duty, then it will be an
176  * error when none are found.
177  *
178  * With thread-MPI, calls have been made to
179  * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
180  * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
181  * the number of ranks and run some checks, but the final
182  * decision is made in this routine, along with many more
183  * consistency checks.
184  *
185  * \param[in]  useGpuForNonbonded        Whether GPUs will be used for nonbonded interactions.
186  * \param[in]  pmeTarget                 The user's choice for mdrun -pme for where to assign long-ranged PME nonbonded interaction tasks.
187  * \param[in]  userGpuTaskAssignment     The user-specified assignment of GPU tasks to device IDs.
188  * \param[in]  hardwareInfo              Hardware information
189  * \param[in]  inputrec                  The user input
190  * \param[in]  mtop                      Global system topology
191  * \param[in]  numRanksPerSimulation     The number of ranks in each simulation.
192  * \param[in]  numPmeRanksPerSimulation  The number of PME ranks in each simulation.
193  * \param[in]  gpusWereDetected          Whether compatible GPUs were detected on any node.
194  *
195  * \returns    Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
196  *
197  * \throws     std::bad_alloc          If out of memory
198  *             InconsistentInputError  If the user requirements are inconsistent. */
199 bool decideWhetherToUseGpusForPme(bool                    useGpuForNonbonded,
200                                   TaskTarget              pmeTarget,
201                                   const std::vector<int>& userGpuTaskAssignment,
202                                   const gmx_hw_info_t&    hardwareInfo,
203                                   const t_inputrec&       inputrec,
204                                   const gmx_mtop_t&       mtop,
205                                   int                     numRanksPerSimulation,
206                                   int                     numPmeRanksPerSimulation,
207                                   bool                    gpusWereDetected);
208
209 /*! \brief Decide whether the simulation will try to run bonded tasks on GPUs.
210  *
211  * \param[in]  useGpuForNonbonded        Whether GPUs will be used for nonbonded interactions.
212  * \param[in]  useGpuForPme              Whether GPUs will be used for PME interactions.
213  * \param[in]  bondedTarget              The user's choice for mdrun -bonded for where to assign tasks.
214  * \param[in]  canUseGpuForBonded        Whether the bonded interactions can run on a GPU
215  * \param[in]  usingLJPme                Whether Vdw interactions use LJ-PME.
216  * \param[in]  usingElecPmeOrEwald       Whether a PME or Ewald type method is used for electrostatics.
217  * \param[in]  numPmeRanksPerSimulation  The number of PME ranks in each simulation, can be -1 for auto.
218  * \param[in]  gpusWereDetected          Whether compatible GPUs were detected on any node.
219  *
220  * \returns    Whether the simulation will run bondeded tasks on GPUs.
221  *
222  * \throws     std::bad_alloc          If out of memory
223  *             InconsistentInputError  If the user requirements are inconsistent. */
224 bool decideWhetherToUseGpusForBonded(bool       useGpuForNonbonded,
225                                      bool       useGpuForPme,
226                                      TaskTarget bondedTarget,
227                                      bool       canUseGpuForBonded,
228                                      bool       usingLJPme,
229                                      bool       usingElecPmeOrEwald,
230                                      int        numPmeRanksPerSimulation,
231                                      bool       gpusWereDetected);
232
233 /*! \brief Decide whether to use GPU for update.
234  *
235  * \param[in]  forceGpuUpdateDefault        If update should run on GPU by default.
236  * \param[in]  isDomainDecomposition        Whether there more than one domain.
237  * \param[in]  useUpdateGroups              If the constraints can be split across domains.
238  * \param[in]  useGpuForPme                 Whether GPUs will be used for PME interactions.
239  * \param[in]  useGpuForNonbonded           Whether GPUs will be used for nonbonded interactions.
240  * \param[in]  updateTarget                 User choice for running simulation on GPU.
241  * \param[in]  gpusWereDetected             Whether compatible GPUs were detected on any node.
242  * \param[in]  inputrec                     The user input.
243  * \param[in]  mtop                         The global topology.
244  * \param[in]  useEssentialDynamics         If essential dynamics is active.
245  * \param[in]  doOrientationRestraints      If orientation restraints are enabled.
246  * \param[in]  useReplicaExchange           If this is a REMD simulation.
247  * \param[in]  doRerun                      It this is a rerun.
248  *
249  * \returns    Whether complete simulation can be run on GPU.
250  * \throws     std::bad_alloc            If out of memory
251  *             InconsistentInputError    If the user requirements are inconsistent.
252  */
253 bool decideWhetherToUseGpuForUpdate(bool              forceGpuUpdateDefault,
254                                     bool              isDomainDecomposition,
255                                     bool              useUpdateGroups,
256                                     bool              useGpuForPme,
257                                     bool              useGpuForNonbonded,
258                                     TaskTarget        updateTarget,
259                                     bool              gpusWereDetected,
260                                     const t_inputrec& inputrec,
261                                     const gmx_mtop_t& mtop,
262                                     bool              useEssentialDynamics,
263                                     bool              doOrientationRestraints,
264                                     bool              useReplicaExchange,
265                                     bool              doRerun);
266
267
268 } // namespace gmx
269
270 #endif