Split simulationWork.useGpuBufferOps into separate x and f flags
[alexxy/gromacs.git] / src / gromacs / taskassignment / decidesimulationworkload.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
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 /*! \internal \file
36  * \brief
37  * Defines routine for building simulation workload task description.
38  *
39  * \author Paul Bauer <paul.bauer.q@gmail.com>
40  * \ingroup module_taskassignment
41  */
42 #include "gmxpre.h"
43
44 #include "decidesimulationworkload.h"
45
46 #include "gromacs/ewald/pme.h"
47 #include "gromacs/mdtypes/multipletimestepping.h"
48 #include "gromacs/taskassignment/decidegpuusage.h"
49 #include "gromacs/taskassignment/taskassignment.h"
50 #include "gromacs/utility/arrayref.h"
51
52 namespace gmx
53 {
54
55 SimulationWorkload createSimulationWorkload(const t_inputrec& inputrec,
56                                             const bool        disableNonbondedCalculation,
57                                             const DevelopmentFeatureFlags& devFlags,
58                                             bool       havePpDomainDecomposition,
59                                             bool       haveSeparatePmeRank,
60                                             bool       useGpuForNonbonded,
61                                             PmeRunMode pmeRunMode,
62                                             bool       useGpuForBonded,
63                                             bool       useGpuForUpdate,
64                                             bool       useGpuDirectHalo)
65 {
66     SimulationWorkload simulationWorkload;
67     simulationWorkload.computeNonbonded = !disableNonbondedCalculation;
68     simulationWorkload.computeNonbondedAtMtsLevel1 =
69             simulationWorkload.computeNonbonded && inputrec.useMts
70             && inputrec.mtsLevels.back().forceGroups[static_cast<int>(MtsForceGroups::Nonbonded)];
71     simulationWorkload.computeMuTot    = inputrecNeedMutot(&inputrec);
72     simulationWorkload.useCpuNonbonded = !useGpuForNonbonded;
73     simulationWorkload.useGpuNonbonded = useGpuForNonbonded;
74     simulationWorkload.useCpuPme       = (pmeRunMode == PmeRunMode::CPU);
75     simulationWorkload.useGpuPme = (pmeRunMode == PmeRunMode::GPU || pmeRunMode == PmeRunMode::Mixed);
76     simulationWorkload.useGpuPmeFft = (pmeRunMode == PmeRunMode::Mixed);
77     simulationWorkload.useGpuBonded = useGpuForBonded;
78     simulationWorkload.useGpuUpdate = useGpuForUpdate;
79     simulationWorkload.useGpuXBufferOps =
80             (devFlags.enableGpuBufferOps || useGpuForUpdate) && !inputrec.useMts;
81     simulationWorkload.useGpuFBufferOps =
82             (devFlags.enableGpuBufferOps || useGpuForUpdate) && !inputrec.useMts;
83     if (simulationWorkload.useGpuXBufferOps || simulationWorkload.useGpuFBufferOps)
84     {
85         GMX_ASSERT(simulationWorkload.useGpuNonbonded,
86                    "Can only offload X/F buffer ops if nonbonded computation is also offloaded");
87     }
88     simulationWorkload.havePpDomainDecomposition = havePpDomainDecomposition;
89     simulationWorkload.useCpuHaloExchange        = havePpDomainDecomposition && !useGpuDirectHalo;
90     simulationWorkload.useGpuHaloExchange        = useGpuDirectHalo;
91     if (pmeRunMode == PmeRunMode::None)
92     {
93         GMX_RELEASE_ASSERT(!haveSeparatePmeRank, "Can not have separate PME rank(s) without PME.");
94     }
95     simulationWorkload.haveSeparatePmeRank = haveSeparatePmeRank;
96     simulationWorkload.useGpuPmePpCommunication =
97             haveSeparatePmeRank && devFlags.enableGpuPmePPComm && (pmeRunMode == PmeRunMode::GPU);
98     simulationWorkload.useCpuPmePpCommunication =
99             haveSeparatePmeRank && !simulationWorkload.useGpuPmePpCommunication;
100     GMX_RELEASE_ASSERT(!(simulationWorkload.useGpuPmePpCommunication
101                          && simulationWorkload.useCpuPmePpCommunication),
102                        "Cannot do PME-PP communication on both CPU and GPU");
103     simulationWorkload.useGpuDirectCommunication =
104             devFlags.enableGpuHaloExchange || devFlags.enableGpuPmePPComm;
105     simulationWorkload.haveEwaldSurfaceContribution = haveEwaldSurfaceContribution(inputrec);
106     simulationWorkload.useMts                       = inputrec.useMts;
107
108     return simulationWorkload;
109 }
110
111 } // namespace gmx