2 * This file is part of the GROMACS molecular simulation package.
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.
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
37 * \brief This file declares a manager of GPU context and streams needed for
38 * running workloads on GPUs.
40 * \author Mark Abraham <mark.j.abraham@gmail.com>
41 * \author Artem Zhmurov <zhmurov@gmail.com>
44 * \ingroup module_gpu_utils
46 #ifndef GMX_GPU_UTILS_GPUSTREAMMANAGER_H
47 #define GMX_GPU_UTILS_GPUSTREAMMANAGER_H
53 struct DeviceInformation;
59 class SimulationWorkload;
61 /*! \brief Class enum to describe the different logical streams used
64 * Whether the actual streams differ is an implementation detail of
67 enum class DeviceStreamType : int
69 //! Stream primarily for short-ranged local nonbonded work.
71 //! Stream primarily for short-ranged nonlocal nonbonded work.
73 //! Stream primarily for PME work.
75 //! Stream primarily for data exchange between PME and PP ranks.
77 //! Stream primarily for update and constraints.
79 //! Conventional termination of the enumeration.
84 * \brief Device stream and context manager.
86 * Manages the lifetime of the GPU streams and their association
87 * with context and device information that is needed to use them.
89 * If supported by the GPU API, the available runtime and the
90 * indicated device, some streams will be configured at high
91 * priority. Otherwise, all streams will share the default priority
92 * appropriate to the situation.
94 class DeviceStreamManager
97 /*! \brief Constructor.
99 * \throws InternalError If any of the required resources could not be initialized.
101 DeviceStreamManager(const DeviceInformation& deviceInfo,
102 bool havePpDomainDecomposition,
103 SimulationWorkload simulationWork,
105 ~DeviceStreamManager();
107 /*! \brief Get the device information object of the associated device.
109 * \returns reference to device info.
111 const DeviceInformation& deviceInfo() const;
113 /*! \brief Returns a handle to the GPU context.
115 * \todo This relies on the fact that only one unique device
116 * is described by nonbondedDeviceInfo and pmeDeviceInfo.
118 const DeviceContext& context() const;
120 /*! \brief Returns a handle to the requested GPU stream.
122 * \param[in] streamToGet Which stream to get.
124 const DeviceStream& stream(DeviceStreamType streamToGet) const;
126 /*! \brief Returns a handle to the GPU stream to compute bonded forces in.
128 * \param[in] hasPPDomainDecomposition Whether there is a particle-particle domain decomposition.
130 const DeviceStream& bondedStream(bool hasPPDomainDecomposition) const;
132 /*! \brief Return whether the requested GPU stream is valid for use.
134 * \param[in] streamToCheck Which stream to check.
136 * \returns Whether the stream was initialized.
138 bool streamIsValid(DeviceStreamType streamToCheck) const;
142 std::unique_ptr<Impl> impl_;