Bug fix in call to deviceStreamManager constructor
[alexxy/gromacs.git] / src / gromacs / gpu_utils / device_stream_manager.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019,2020, 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  *
37  * \brief This file declares a manager of GPU context and streams needed for
38  * running workloads on GPUs.
39  *
40  * \author Mark Abraham <mark.j.abraham@gmail.com>
41  * \author Artem Zhmurov <zhmurov@gmail.com>
42  *
43  * \inlibraryapi
44  * \ingroup module_gpu_utils
45  */
46 #ifndef GMX_GPU_UTILS_GPUSTREAMMANAGER_H
47 #define GMX_GPU_UTILS_GPUSTREAMMANAGER_H
48
49 #include <string>
50
51 #include "gromacs/utility/classhelpers.h"
52
53 class DeviceContext;
54 struct DeviceInformation;
55 class DeviceStream;
56
57 namespace gmx
58 {
59
60 class SimulationWorkload;
61
62 /*! \brief Class enum to describe the different logical streams used
63  * for GPU work.
64  *
65  * Whether the actual streams differ is an implementation detail of
66  * the manager class.
67  */
68 enum class DeviceStreamType : int
69 {
70     //! Stream primarily for short-ranged local nonbonded work.
71     NonBondedLocal,
72     //! Stream primarily for short-ranged nonlocal nonbonded work.
73     NonBondedNonLocal,
74     //! Stream primarily for PME work.
75     Pme,
76     //! Stream primarily for data exchange between PME and PP ranks.
77     PmePpTransfer,
78     //! Stream primarily for update and constraints.
79     UpdateAndConstraints,
80     //! Conventional termination of the enumeration.
81     Count
82 };
83
84 /*! \libinternal
85  * \brief Device stream and context manager.
86  *
87  * Manages the lifetime of the GPU streams and their association
88  * with context and device information that is needed to use them.
89  *
90  * If supported by the GPU API, the available runtime and the
91  * indicated device, some streams will be configured at high
92  * priority. Otherwise, all streams will share the default priority
93  * appropriate to the situation.
94  */
95 class DeviceStreamManager
96 {
97 public:
98     /*! \brief Constructor.
99      *
100      * \throws InternalError  If any of the required resources could not be initialized.
101      */
102     DeviceStreamManager(const DeviceInformation& deviceInfo,
103                         bool                     havePpDomainDecomposition,
104                         SimulationWorkload       simulationWork,
105                         bool                     useTiming);
106     ~DeviceStreamManager();
107
108     /*! \brief Get the device information object of the associated device.
109      *
110      * \returns reference to device info.
111      */
112     const DeviceInformation& deviceInfo() const;
113
114     /*! \brief Returns a handle to the GPU context.
115      *
116      * \todo This relies on the fact that only one unique device
117      * is described by nonbondedDeviceInfo and pmeDeviceInfo.
118      */
119     const DeviceContext& context() const;
120
121     /*! \brief Returns a handle to the requested GPU stream.
122      *
123      * \param[in] streamToGet Which stream to get.
124      */
125     const DeviceStream& stream(DeviceStreamType streamToGet) const;
126
127     /*! \brief Returns a handle to the GPU stream to compute bonded forces in.
128      *
129      * \param[in] hasPPDomainDecomposition Whether there is a particle-particle domain decomposition.
130      */
131     const DeviceStream& bondedStream(bool hasPPDomainDecomposition) const;
132
133     /*! \brief Return whether the requested GPU stream is valid for use.
134      *
135      * \param[in] streamToCheck Which stream to check.
136      *
137      * \returns Whether the stream was initialized.
138      */
139     bool streamIsValid(DeviceStreamType streamToCheck) const;
140
141 private:
142     class Impl;
143     PrivateImplPointer<Impl> impl_;
144 };
145
146 } // namespace gmx
147
148 #endif