Add replacements for pbc enumerations
[gromacs.git] / src / gromacs / taskassignment / decidegpuusage.h
blob818841b722fc82b5777276bd651c4fa1c776c2fe
1 /*
2 * This file is part of the GROMACS molecular simulation package.
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.
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
40 * \inlibraryapi
43 #ifndef GMX_TASKASSIGNMENT_DECIDEGPUUSAGE_H
44 #define GMX_TASKASSIGNMENT_DECIDEGPUUSAGE_H
46 #include <vector>
48 struct gmx_hw_info_t;
49 struct gmx_mtop_t;
50 struct t_inputrec;
52 namespace gmx
55 //! Record where a compute task is targetted.
56 enum class TaskTarget : int
58 Auto,
59 Cpu,
60 Gpu
63 //! Help pass GPU-emulation parameters with type safety.
64 enum class EmulateGpuNonbonded : bool
66 //! Do not emulate GPUs.
67 No,
68 //! Do emulate GPUs.
69 Yes
72 /*! \brief Decide whether this thread-MPI simulation will run
73 * nonbonded tasks on GPUs.
75 * The number of GPU tasks and devices influences both the choice of
76 * the number of ranks, and checks upon any such choice made by the
77 * user. So we need to consider this before any automated choice of
78 * the number of thread-MPI ranks.
80 * \param[in] nonbondedTarget The user's choice for mdrun -nb for where to assign short-ranged nonbonded interaction tasks.
81 * \param[in] gpuIdsToUse The compatible GPUs that the user permitted us to use.
82 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
83 * \param[in] emulateGpuNonbonded Whether we will emulate GPU calculation of nonbonded interactions.
84 * \param[in] buildSupportsNonbondedOnGpu Whether GROMACS was built with GPU support.
85 * \param[in] nonbondedOnGpuIsUseful Whether computing nonbonded interactions on a GPU is useful for this calculation.
86 * \param[in] numRanksPerSimulation The number of ranks in each simulation.
88 * \returns Whether the simulation will run nonbonded tasks on GPUs.
90 * \throws std::bad_alloc If out of memory
91 * InconsistentInputError If the user requirements are inconsistent. */
92 bool decideWhetherToUseGpusForNonbondedWithThreadMpi(TaskTarget nonbondedTarget,
93 const std::vector<int> &gpuIdsToUse,
94 const std::vector<int> &userGpuTaskAssignment,
95 EmulateGpuNonbonded emulateGpuNonbonded,
96 bool buildSupportsNonbondedOnGpu,
97 bool nonbondedOnGpuIsUseful,
98 int numRanksPerSimulation);
100 /*! \brief Decide whether this thread-MPI simulation will run
101 * PME tasks on GPUs.
103 * The number of GPU tasks and devices influences both the choice of
104 * the number of ranks, and checks upon any such choice made by the
105 * user. So we need to consider this before any automated choice of
106 * the number of thread-MPI ranks.
108 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
109 * \param[in] pmeTarget The user's choice for mdrun -pme for where to assign long-ranged PME nonbonded interaction tasks.
110 * \param[in] gpuIdsToUse The compatible GPUs that the user permitted us to use.
111 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
112 * \param[in] hardwareInfo Hardware information
113 * \param[in] inputrec The user input
114 * \param[in] mtop Global system topology
115 * \param[in] numRanksPerSimulation The number of ranks in each simulation.
116 * \param[in] numPmeRanksPerSimulation The number of PME ranks in each simulation.
118 * \returns Whether the simulation will run PME tasks on GPUs.
120 * \throws std::bad_alloc If out of memory
121 * InconsistentInputError If the user requirements are inconsistent. */
122 bool decideWhetherToUseGpusForPmeWithThreadMpi(bool useGpuForNonbonded,
123 TaskTarget pmeTarget,
124 const std::vector<int> &gpuIdsToUse,
125 const std::vector<int> &userGpuTaskAssignment,
126 const gmx_hw_info_t &hardwareInfo,
127 const t_inputrec &inputrec,
128 const gmx_mtop_t &mtop,
129 int numRanksPerSimulation,
130 int numPmeRanksPerSimulation);
132 /*! \brief Decide whether the simulation will try to run nonbonded
133 * tasks on GPUs.
135 * The final decision cannot be made until after the duty of the rank
136 * is known. But we need to know if nonbonded will run on GPUs for
137 * setting up DD (particularly rlist) and determining duty. If the
138 * user requires GPUs for the tasks of that duty, then it will be an
139 * error when none are found.
141 * With thread-MPI, calls have been made to
142 * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
143 * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
144 * the number of ranks and run some checks, but the final
145 * decision is made in this routine, along with many more
146 * consistency checks.
148 * \param[in] nonbondedTarget The user's choice for mdrun -nb for where to assign short-ranged nonbonded interaction tasks.
149 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
150 * \param[in] emulateGpuNonbonded Whether we will emulate GPU calculation of nonbonded interactions.
151 * \param[in] buildSupportsNonbondedOnGpu Whether GROMACS was build with GPU support.
152 * \param[in] nonbondedOnGpuIsUseful Whether computing nonbonded interactions on a GPU is useful for this calculation.
153 * \param[in] gpusWereDetected Whether compatible GPUs were detected on any node.
155 * \returns Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
157 * \throws std::bad_alloc If out of memory
158 * InconsistentInputError If the user requirements are inconsistent. */
159 bool decideWhetherToUseGpusForNonbonded(TaskTarget nonbondedTarget,
160 const std::vector<int> &userGpuTaskAssignment,
161 EmulateGpuNonbonded emulateGpuNonbonded,
162 bool buildSupportsNonbondedOnGpu,
163 bool nonbondedOnGpuIsUseful,
164 bool gpusWereDetected);
166 /*! \brief Decide whether the simulation will try to run tasks of
167 * different types on GPUs.
169 * The final decision cannot be made until after the duty of the rank
170 * is known. But we need to know if nonbonded will run on GPUs for
171 * setting up DD (particularly rlist) and determining duty. If the
172 * user requires GPUs for the tasks of that duty, then it will be an
173 * error when none are found.
175 * With thread-MPI, calls have been made to
176 * decideWhetherToUseGpusForNonbondedWithThreadMpi() and
177 * decideWhetherToUseGpusForPmeWithThreadMpi() to help determine
178 * the number of ranks and run some checks, but the final
179 * decision is made in this routine, along with many more
180 * consistency checks.
182 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
183 * \param[in] pmeTarget The user's choice for mdrun -pme for where to assign long-ranged PME nonbonded interaction tasks.
184 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
185 * \param[in] hardwareInfo Hardware information
186 * \param[in] inputrec The user input
187 * \param[in] mtop Global system topology
188 * \param[in] numRanksPerSimulation The number of ranks in each simulation.
189 * \param[in] numPmeRanksPerSimulation The number of PME ranks in each simulation.
190 * \param[in] gpusWereDetected Whether compatible GPUs were detected on any node.
192 * \returns Whether the simulation will run nonbonded and PME tasks, respectively, on GPUs.
194 * \throws std::bad_alloc If out of memory
195 * InconsistentInputError If the user requirements are inconsistent. */
196 bool decideWhetherToUseGpusForPme(bool useGpuForNonbonded,
197 TaskTarget pmeTarget,
198 const std::vector<int> &userGpuTaskAssignment,
199 const gmx_hw_info_t &hardwareInfo,
200 const t_inputrec &inputrec,
201 const gmx_mtop_t &mtop,
202 int numRanksPerSimulation,
203 int numPmeRanksPerSimulation,
204 bool gpusWereDetected);
206 /*! \brief Decide whether the simulation will try to run bonded tasks on GPUs.
208 * \param[in] useGpuForNonbonded Whether GPUs will be used for nonbonded interactions.
209 * \param[in] useGpuForPme Whether GPUs will be used for PME interactions.
210 * \param[in] bondedTarget The user's choice for mdrun -bonded for where to assign tasks.
211 * \param[in] canUseGpuForBonded Whether the bonded interactions can run on a GPU
212 * \param[in] usingLJPme Whether Vdw interactions use LJ-PME.
213 * \param[in] usingElecPmeOrEwald Whether a PME or Ewald type method is used for electrostatics.
214 * \param[in] numPmeRanksPerSimulation The number of PME ranks in each simulation, can be -1 for auto.
215 * \param[in] gpusWereDetected Whether compatible GPUs were detected on any node.
217 * \returns Whether the simulation will run bondeded tasks on GPUs.
219 * \throws std::bad_alloc If out of memory
220 * InconsistentInputError If the user requirements are inconsistent. */
221 bool decideWhetherToUseGpusForBonded(bool useGpuForNonbonded,
222 bool useGpuForPme,
223 TaskTarget bondedTarget,
224 bool canUseGpuForBonded,
225 bool usingLJPme,
226 bool usingElecPmeOrEwald,
227 int numPmeRanksPerSimulation,
228 bool gpusWereDetected);
230 } // namespace gmx
232 #endif