2 * This file is part of the GROMACS molecular simulation package.
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.
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
51 #include "gromacs/utility/classhelpers.h"
54 struct DeviceInformation
;
60 /*! \brief Class enum to describe the different logical streams used
63 * Whether the actual streams differ is an implementation detail of
66 enum class DeviceStreamType
: int
68 //! Stream primarily for short-ranged local nonbonded work.
70 //! Stream primarily for short-ranged nonlocal nonbonded work.
72 //! Stream primarily for PME work.
74 //! Stream primarily for data exchange between PME and PP ranks.
76 //! Stream primarily for update and constraints.
78 //! Conventional termination of the enumeration.
83 * \brief Device stream and context manager.
85 * Manages the lifetime of the GPU streams and their association
86 * with context and device information that is needed to use them.
88 * If supported by the GPU API, the available runtime and the
89 * indicated device, some streams will be configured at high
90 * priority. Otherwise, all streams will share the default priority
91 * appropriate to the situation.
93 class DeviceStreamManager
96 /*! \brief Constructor.
98 * \throws InternalError If any of the required resources could not be initialized.
100 DeviceStreamManager(const DeviceInformation
& deviceInfo
,
102 bool havePpDomainDecomposition
,
103 bool doGpuPmePpTransfer
,
104 bool useGpuForUpdate
,
106 ~DeviceStreamManager();
108 /*! \brief Get the device information object of the associated device.
110 * \returns reference to device info.
112 const DeviceInformation
& deviceInfo() const;
114 /*! \brief Returns a handle to the GPU context.
116 * \todo This relies on the fact that only one unique device
117 * is described by nonbondedDeviceInfo and pmeDeviceInfo.
119 const DeviceContext
& context() const;
121 /*! \brief Returns a handle to the requested GPU stream.
123 * \param[in] streamToGet Which stream to get.
125 const DeviceStream
& stream(DeviceStreamType streamToGet
) const;
127 /*! \brief Returns a handle to the GPU stream to compute bonded forces in.
129 * \param[in] hasPPDomainDecomposition Whether there is a particle-particle domain decomposition.
131 const DeviceStream
& bondedStream(bool hasPPDomainDecomposition
) const;
133 /*! \brief Return whether the requested GPU stream is valid for use.
135 * \param[in] streamToCheck Which stream to check.
137 * \returns Whether the stream was initialized.
139 bool streamIsValid(DeviceStreamType streamToCheck
) const;
143 PrivateImplPointer
<Impl
> impl_
;