Merge branch release-2018 into release-2019
[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, 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
50 enum class EmulateGpuNonbonded : bool;
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 /*! \brief Decide whether this thread-MPI simulation will run
64  * nonbonded tasks on GPUs.
65  *
66  * The number of GPU tasks and devices influences both the choice of
67  * the number of ranks, and checks upon any such choice made by the
68  * user. So we need to consider this before any automated choice of
69  * the number of thread-MPI ranks.
70  *
71  * \param[in]  nonbondedTarget             The user's choice for mdrun -nb for where to assign short-ranged nonbonded interaction tasks.
72  * \param[in]  gpuIdsToUse                 The compatible GPUs that the user permitted us to use.
73  * \param[in]  userGpuTaskAssignment       The user-specified assignment of GPU tasks to device IDs.
74  * \param[in]  emulateGpuNonbonded         Whether we will emulate GPU calculation of nonbonded interactions.
75  * \param[in]  buildSupportsNonbondedOnGpu Whether GROMACS was built with GPU support.
76  * \param[in]  usingVerletScheme           Whether the nonbondeds are using the Verlet scheme.
77  * \param[in]  nonbondedOnGpuIsUseful    Whether computing nonbonded interactions on a GPU is useful for this calculation.
78  * \param[in]  numRanksPerSimulation     The number of ranks in each simulation.
79  *
80  * \returns    Whether the simulation will run nonbonded tasks on GPUs.
81  *
82  * \throws     std::bad_alloc          If out of memory
83  *             InconsistentInputError  If the user requirements are inconsistent. */
84 bool decideWhetherToUseGpusForNonbondedWithThreadMpi(TaskTarget              nonbondedTarget,
85                                                      const std::vector<int> &gpuIdsToUse,
86                                                      const std::vector<int> &userGpuTaskAssignment,
87                                                      EmulateGpuNonbonded     emulateGpuNonbonded,
88                                                      bool                    buildSupportsNonbondedOnGpu,
89                                                      bool                    usingVerletScheme,
90                                                      bool                    nonbondedOnGpuIsUseful,
91                                                      int                     numRanksPerSimulation);
92
93 /*! \brief Decide whether this thread-MPI simulation will run
94  * PME tasks on GPUs.
95  *
96  * The number of GPU tasks and devices influences both the choice of
97  * the number of ranks, and checks upon any such choice made by the
98  * user. So we need to consider this before any automated choice of
99  * the number of thread-MPI ranks.
100  *
101  * \param[in]  useGpuForNonbonded        Whether GPUs will be used for nonbonded interactions.
102  * \param[in]  pmeTarget                 The user's choice for mdrun -pme for where to assign long-ranged PME nonbonded interaction tasks.
103  * \param[in]  gpuIdsToUse               The compatible GPUs that the user permitted us to use.
104  * \param[in]  userGpuTaskAssignment     The user-specified assignment of GPU tasks to device IDs.
105  * \param[in]  canUseGpuForPme           Whether the form of PME chosen can run on a GPU
106  * \param[in]  numRanksPerSimulation     The number of ranks in each simulation.
107  * \param[in]  numPmeRanksPerSimulation  The number of PME ranks in each simulation.
108  *
109  * \returns    Whether the simulation will run PME tasks on GPUs.
110  *
111  * \throws     std::bad_alloc          If out of memory
112  *             InconsistentInputError  If the user requirements are inconsistent. */
113 bool decideWhetherToUseGpusForPmeWithThreadMpi(bool                    useGpuForNonbonded,
114                                                TaskTarget              pmeTarget,
115                                                const std::vector<int> &gpuIdsToUse,
116                                                const std::vector<int> &userGpuTaskAssignment,
117                                                bool                    canUseGpuForPme,
118                                                int                     numRanksPerSimulation,
119                                                int                     numPmeRanksPerSimulation);
120
121 /*! \brief Decide whether the simulation will try to run nonbonded
122  * tasks on GPUs.
123  *
124  * The final decision cannot be made until after the duty of the rank
125  * is known. But we need to know if nonbonded will run on GPUs for
126  * setting up DD (particularly rlist) and determining duty. If the
127  * user requires GPUs for the tasks of that duty, then it will be an
128  * error when none are found.
129  *
130  * With thread-MPI, calls have been made to
131  * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
132  * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
133  * the number of ranks and run some checks, but the final
134  * decision is made in this routine, along with many more
135  * consistency checks.
136  *
137  * \param[in]  nonbondedTarget             The user's choice for mdrun -nb for where to assign short-ranged nonbonded interaction tasks.
138  * \param[in]  userGpuTaskAssignment       The user-specified assignment of GPU tasks to device IDs.
139  * \param[in]  emulateGpuNonbonded         Whether we will emulate GPU calculation of nonbonded interactions.
140  * \param[in]  buildSupportsNonbondedOnGpu Whether GROMACS was build with GPU support.
141  * \param[in]  usingVerletScheme           Whether the nonbondeds are using the Verlet scheme.
142  * \param[in]  nonbondedOnGpuIsUseful      Whether computing nonbonded interactions on a GPU is useful for this calculation.
143  * \param[in]  gpusWereDetected            Whether compatible GPUs were detected on any node.
144  *
145  * \returns    Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
146  *
147  * \throws     std::bad_alloc          If out of memory
148  *             InconsistentInputError  If the user requirements are inconsistent. */
149 bool decideWhetherToUseGpusForNonbonded(TaskTarget              nonbondedTarget,
150                                         const std::vector<int> &userGpuTaskAssignment,
151                                         EmulateGpuNonbonded     emulateGpuNonbonded,
152                                         bool                    buildSupportsNonbondedOnGpu,
153                                         bool                    usingVerletScheme,
154                                         bool                    nonbondedOnGpuIsUseful,
155                                         bool                    gpusWereDetected);
156
157 /*! \brief Decide whether the simulation will try to run tasks of
158  * different types on GPUs.
159  *
160  * The final decision cannot be made until after the duty of the rank
161  * is known. But we need to know if nonbonded will run on GPUs for
162  * setting up DD (particularly rlist) and determining duty. If the
163  * user requires GPUs for the tasks of that duty, then it will be an
164  * error when none are found.
165  *
166  * With thread-MPI, calls have been made to
167  * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
168  * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
169  * the number of ranks and run some checks, but the final
170  * decision is made in this routine, along with many more
171  * consistency checks.
172  *
173  * \param[in]  useGpuForNonbonded        Whether GPUs will be used for nonbonded interactions.
174  * \param[in]  pmeTarget                 The user's choice for mdrun -pme for where to assign long-ranged PME nonbonded interaction tasks.
175  * \param[in]  userGpuTaskAssignment     The user-specified assignment of GPU tasks to device IDs.
176  * \param[in]  canUseGpuForPme           Whether the form of PME chosen can run on a GPU
177  * \param[in]  numRanksPerSimulation     The number of ranks in each simulation.
178  * \param[in]  numPmeRanksPerSimulation  The number of PME ranks in each simulation.
179  * \param[in]  gpusWereDetected          Whether compatible GPUs were detected on any node.
180  *
181  * \returns    Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
182  *
183  * \throws     std::bad_alloc          If out of memory
184  *             InconsistentInputError  If the user requirements are inconsistent. */
185 bool decideWhetherToUseGpusForPme(bool                    useGpuForNonbonded,
186                                   TaskTarget              pmeTarget,
187                                   const std::vector<int> &userGpuTaskAssignment,
188                                   bool                    canUseGpuForPme,
189                                   int                     numRanksPerSimulation,
190                                   int                     numPmeRanksPerSimulation,
191                                   bool                    gpusWereDetected);
192
193 /*! \brief Decide whether the simulation will try to run bonded tasks on GPUs.
194  *
195  * \param[in]  useGpuForNonbonded        Whether GPUs will be used for nonbonded interactions.
196  * \param[in]  useGpuForPme              Whether GPUs will be used for PME interactions.
197  * \param[in]  usingVerletScheme         Whether the nonbondeds are using the Verlet scheme.
198  * \param[in]  bondedTarget              The user's choice for mdrun -bonded for where to assign tasks.
199  * \param[in]  canUseGpuForBonded        Whether the bonded interactions can run on a GPU
200  * \param[in]  usingLJPme                Whether Vdw interactions use LJ-PME.
201  * \param[in]  usingElecPmeOrEwald       Whether a PME or Ewald type method is used for electrostatics.
202  * \param[in]  numPmeRanksPerSimulation  The number of PME ranks in each simulation, can be -1 for auto.
203  * \param[in]  gpusWereDetected          Whether compatible GPUs were detected on any node.
204  *
205  * \returns    Whether the simulation will run bondeded tasks on GPUs.
206  *
207  * \throws     std::bad_alloc          If out of memory
208  *             InconsistentInputError  If the user requirements are inconsistent. */
209 bool decideWhetherToUseGpusForBonded(bool       useGpuForNonbonded,
210                                      bool       useGpuForPme,
211                                      bool       usingVerletScheme,
212                                      TaskTarget bondedTarget,
213                                      bool       canUseGpuForBonded,
214                                      bool       usingLJPme,
215                                      bool       usingElecPmeOrEwald,
216                                      int        numPmeRanksPerSimulation,
217                                      bool       gpusWereDetected);
218
219 }  // namespace gmx
220
221 #endif