2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,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.
36 * \brief SETTLE tests runners.
38 * Declares test runner class for SETTLE algorithm. The test runners abstract
39 * class is used to unify the interfaces for CPU and GPU implementations of the
40 * SETTLE algorithm. This allows to run the same test on the same data using
41 * different implementations of the parent class, that inherit its interfaces.
43 * \author Artem Zhmurov <zhmurov@gmail.com>
44 * \ingroup module_mdlib
46 #ifndef GMX_MDLIB_TESTS_SETTLETESTRUNNERS_H
47 #define GMX_MDLIB_TESTS_SETTLETESTRUNNERS_H
49 #include <gtest/gtest.h>
51 #include "testutils/test_device.h"
53 #include "settletestdata.h"
56 * GPU version of SETTLE is only available with CUDA.
58 #define GPU_SETTLE_SUPPORTED (GMX_GPU_CUDA)
67 /* \brief SETTLE test runner interface.
69 * Wraps the actual implementation of SETTLE into common interface.
71 class ISettleTestRunner
74 //! Virtual destructor.
75 virtual ~ISettleTestRunner() {}
77 /*! \brief Apply SETTLE using CPU version of the algorithm
79 * Initializes SETTLE object, applies algorithm, destroys the object. The coordinates, velocities
80 * and virial are updated in the testData object.
82 * \param[in,out] testData An object, containing all the data structures needed by SETTLE.
83 * \param[in] pbc Periodic boundary setup.
84 * \param[in] updateVelocities If the velocities should be updated.
85 * \param[in] calcVirial If the virial should be computed.
86 * \param[in] testDescription Brief description that will be printed in case of test failure.
88 virtual void applySettle(SettleTestData* testData,
90 bool updateVelocities,
92 const std::string& testDescription) = 0;
93 /*! \brief Get the hardware description
95 * \returns A string, describing hardware used by the runner.
97 virtual std::string hardwareDescription() = 0;
100 // Runner for the CPU implementation of SETTLE.
101 class SettleHostTestRunner : public ISettleTestRunner
104 //! Default constructor.
105 SettleHostTestRunner() {}
106 /*! \brief Apply SETTLE using CPU version of the algorithm
108 * Initializes SETTLE object, applies algorithm, destroys the object. The coordinates, velocities
109 * and virial are updated in the testData object.
111 * \param[in,out] testData An object, containing all the data structures needed by SETTLE.
112 * \param[in] pbc Periodic boundary setup.
113 * \param[in] updateVelocities If the velocities should be updated.
114 * \param[in] calcVirial If the virial should be computed.
115 * \param[in] testDescription Brief description that will be printed in case of test failure.
117 void applySettle(SettleTestData* testData,
119 bool updateVelocities,
121 const std::string& testDescription) override;
122 /*! \brief Get the hardware description
124 * \returns "CPU" string.
126 std::string hardwareDescription() override { return "CPU"; }
129 // Runner for the GPU implementation of SETTLE.
130 class SettleDeviceTestRunner : public ISettleTestRunner
133 /*! \brief Constructor. Keeps a copy of the hardware context.
135 * \param[in] testDevice The device hardware context to be used by the runner.
137 SettleDeviceTestRunner(const TestDevice& testDevice) : testDevice_(testDevice) {}
138 /*! \brief Apply SETTLE using GPU version of the algorithm
140 * Initializes SETTLE object, copied data to the GPU, applies algorithm, copies the data back,
141 * destroys the object. The coordinates, velocities and virial are updated in the testData object.
143 * \param[in,out] testData An object, containing all the data structures needed by SETTLE.
144 * \param[in] pbc Periodic boundary setup.
145 * \param[in] updateVelocities If the velocities should be updated.
146 * \param[in] calcVirial If the virial should be computed.
147 * \param[in] testDescription Brief description that will be printed in case of test failure.
149 void applySettle(SettleTestData* testData,
151 bool updateVelocities,
153 const std::string& testDescription) override;
154 /*! \brief Get the hardware description
156 * \returns A string with GPU description.
158 std::string hardwareDescription() override { return testDevice_.description(); }
161 //! Test test device to be used in the runner.
162 const TestDevice& testDevice_;
168 #endif // GMX_MDLIB_TESTS_SETTLETESTRUNNERS_H