2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2017,2018,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.
36 * \brief Tests GPU stream manager
38 * \author Mark Abraham <mark.j.abraham@gmail.com>
39 * \author Artem Zhmurov <zhmurov@gmail.com>
41 * \ingroup module_gpu_utils
45 #include "gromacs/gpu_utils/device_stream_manager.h"
49 #include <initializer_list>
52 #include <gtest/gtest.h>
54 #include "gromacs/hardware/device_management.h"
55 #include "gromacs/mdtypes/simulation_workload.h"
56 #include "gromacs/utility/enumerationhelpers.h"
58 #include "testutils/test_hardware_environment.h"
69 //! GPU device stream names for outputs.
70 const EnumerationArray<DeviceStreamType, std::string> c_deviceStreamNames = {
71 { "non-bonded local", "non-bonded non-local", "PME", "PME-PP transfer", "update" }
74 /*! \brief Non-GPU builds return nullptr instead of streams,
75 * so we have to expect that in such build configurations. */
76 constexpr bool c_canExpectValidStreams = (GMX_GPU != 0);
78 //! Helper function to implement readable testing
79 void expectValidStreams(DeviceStreamManager* manager, std::initializer_list<DeviceStreamType> types)
81 if (c_canExpectValidStreams)
83 for (const DeviceStreamType type : types)
85 SCOPED_TRACE("Testing " + c_deviceStreamNames[type] + " stream.");
86 EXPECT_TRUE(manager->streamIsValid(type));
90 //! Helper function to implement readable testing
91 void expectInvalidStreams(DeviceStreamManager* manager, std::initializer_list<DeviceStreamType> types)
93 for (const DeviceStreamType type : types)
95 SCOPED_TRACE("Testing " + c_deviceStreamNames[type] + " stream.");
96 EXPECT_FALSE(manager->streamIsValid(type));
101 class DeviceStreamManagerTest : public ::testing::Test
106 TEST_F(DeviceStreamManagerTest, CorrectStreamsAreReturnedOnNonbondedDevice)
108 // It would be nice to test that the priority is high when it can
109 // be, but that requires calling the same API calls we're testing
110 // that we've called, so it is not very useful.
111 const bool useTiming = false;
113 const auto& testDeviceList = getTestHardwareEnvironment()->getTestDeviceList();
114 for (const auto& testDevice : testDeviceList)
116 const DeviceInformation& deviceInfo = testDevice->deviceInfo();
117 setActiveDevice(deviceInfo);
120 SCOPED_TRACE("No DD, no PME rank, no GPU update");
121 SimulationWorkload simulationWork;
122 simulationWork.useGpuPme = false;
123 simulationWork.useGpuPmePpCommunication = false;
124 simulationWork.useGpuUpdate = false;
125 bool havePpDomainDecomposition = false;
126 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
128 expectValidStreams(&manager, { DeviceStreamType::NonBondedLocal });
129 expectInvalidStreams(&manager,
130 { DeviceStreamType::NonBondedNonLocal,
131 DeviceStreamType::Pme,
132 DeviceStreamType::PmePpTransfer,
133 DeviceStreamType::UpdateAndConstraints });
137 SCOPED_TRACE("With DD, no PME rank, no GPU update");
138 SimulationWorkload simulationWork;
139 simulationWork.useGpuPme = false;
140 simulationWork.useGpuPmePpCommunication = false;
141 simulationWork.useGpuUpdate = false;
142 bool havePpDomainDecomposition = true;
143 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
146 &manager, { DeviceStreamType::NonBondedLocal, DeviceStreamType::NonBondedNonLocal });
147 expectInvalidStreams(&manager,
148 { DeviceStreamType::Pme,
149 DeviceStreamType::PmePpTransfer,
150 DeviceStreamType::UpdateAndConstraints });
154 SCOPED_TRACE("No DD, with PME rank, no GPU update");
155 SimulationWorkload simulationWork;
156 simulationWork.useGpuPme = true;
157 simulationWork.useGpuPmePpCommunication = true;
158 simulationWork.useGpuUpdate = false;
159 bool havePpDomainDecomposition = false;
160 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
162 expectValidStreams(&manager,
163 { DeviceStreamType::Pme,
164 DeviceStreamType::NonBondedLocal,
165 DeviceStreamType::PmePpTransfer,
166 DeviceStreamType::UpdateAndConstraints });
167 expectInvalidStreams(&manager, { DeviceStreamType::NonBondedNonLocal });
171 SCOPED_TRACE("With DD, with PME rank, no GPU update");
172 SimulationWorkload simulationWork;
173 simulationWork.useGpuPme = true;
174 simulationWork.useGpuPmePpCommunication = true;
175 simulationWork.useGpuUpdate = false;
176 bool havePpDomainDecomposition = true;
177 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
179 expectValidStreams(&manager,
180 { DeviceStreamType::Pme,
181 DeviceStreamType::NonBondedLocal,
182 DeviceStreamType::NonBondedNonLocal,
183 DeviceStreamType::PmePpTransfer,
184 DeviceStreamType::UpdateAndConstraints });
188 SCOPED_TRACE("No DD, no PME rank, with GPU update");
189 SimulationWorkload simulationWork;
190 simulationWork.useGpuPme = false;
191 simulationWork.useGpuPmePpCommunication = false;
192 simulationWork.useGpuUpdate = true;
193 bool havePpDomainDecomposition = false;
194 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
197 &manager, { DeviceStreamType::NonBondedLocal, DeviceStreamType::UpdateAndConstraints });
198 expectInvalidStreams(&manager,
199 { DeviceStreamType::NonBondedNonLocal,
200 DeviceStreamType::Pme,
201 DeviceStreamType::PmePpTransfer });
205 SCOPED_TRACE("With DD, no PME rank, with GPU update");
206 SimulationWorkload simulationWork;
207 simulationWork.useGpuPme = false;
208 simulationWork.useGpuPmePpCommunication = false;
209 simulationWork.useGpuUpdate = true;
210 bool havePpDomainDecomposition = true;
211 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
213 expectValidStreams(&manager,
214 { DeviceStreamType::NonBondedLocal,
215 DeviceStreamType::NonBondedNonLocal,
216 DeviceStreamType::UpdateAndConstraints });
217 expectInvalidStreams(&manager, { DeviceStreamType::Pme, DeviceStreamType::PmePpTransfer });
221 SCOPED_TRACE("No DD, with PME rank, with GPU update");
222 SimulationWorkload simulationWork;
223 simulationWork.useGpuPme = true;
224 simulationWork.useGpuPmePpCommunication = true;
225 simulationWork.useGpuUpdate = true;
226 bool havePpDomainDecomposition = false;
227 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
229 expectValidStreams(&manager,
230 { DeviceStreamType::Pme,
231 DeviceStreamType::NonBondedLocal,
232 DeviceStreamType::PmePpTransfer,
233 DeviceStreamType::UpdateAndConstraints });
234 expectInvalidStreams(&manager, { DeviceStreamType::NonBondedNonLocal });
238 SCOPED_TRACE("With DD, with PME rank, with GPU update");
239 SimulationWorkload simulationWork;
240 simulationWork.useGpuPme = true;
241 simulationWork.useGpuPmePpCommunication = true;
242 simulationWork.useGpuUpdate = true;
243 bool havePpDomainDecomposition = true;
244 DeviceStreamManager manager(deviceInfo, havePpDomainDecomposition, simulationWork, useTiming);
246 expectValidStreams(&manager,
247 { DeviceStreamType::Pme,
248 DeviceStreamType::NonBondedLocal,
249 DeviceStreamType::NonBondedNonLocal,
250 DeviceStreamType::PmePpTransfer,
251 DeviceStreamType::UpdateAndConstraints });