1 /* 2 * This file is part of the GROMACS molecular simulation package. 3 * 4 * Copyright (c) 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. 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 /*! \internal \file 36 * \brief SHAKE and LINCS tests runners. 37 * 38 * Declares test runner class for constraints. The test runner abstract class is used 39 * to unify the interfaces for different constraints methods, running on different 40 * hardware. This allows to run the same test on the same data using different 41 * implementations of the parent class, that inherit its interfaces. 42 * 43 * \author Artem Zhmurov <zhmurov@gmail.com> 44 * \ingroup module_mdlib 45 */ 46 47 #ifndef GMX_MDLIB_TESTS_CONSTRTESTRUNNERS_H 48 #define GMX_MDLIB_TESTS_CONSTRTESTRUNNERS_H 49 50 #include <gtest/gtest.h> 51 52 #include "testutils/test_device.h" 53 54 #include "constrtestdata.h" 55 56 struct t_pbc; 57 58 namespace gmx 59 { 60 namespace test 61 { 62 63 /* \brief Constraints test runner interface. 64 * 65 * Wraps the actual implementation of constraints algorithm into common interface. 66 */ 67 class IConstraintsTestRunner 68 { 69 public: 70 //! Virtual destructor. ~IConstraintsTestRunner()71 virtual ~IConstraintsTestRunner() {} 72 /*! \brief Abstract constraining function. Should be overriden. 73 * 74 * \param[in] testData Test data structure. 75 * \param[in] pbc Periodic boundary data. 76 */ 77 virtual void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) = 0; 78 79 /*! \brief Get the name of the implementation. 80 * 81 * \return "<algorithm> on <device>", depending on the actual implementation used. E.g., "LINCS on #0: NVIDIA GeForce GTX 1660 SUPER". 82 */ 83 virtual std::string name() = 0; 84 }; 85 86 // Runner for the CPU implementation of SHAKE constraints algorithm. 87 class ShakeConstraintsRunner : public IConstraintsTestRunner 88 { 89 public: 90 //! Default constructor. ShakeConstraintsRunner()91 ShakeConstraintsRunner() {} 92 /*! \brief Apply SHAKE constraints to the test data. 93 * 94 * \param[in] testData Test data structure. 95 * \param[in] pbc Periodic boundary data. 96 */ 97 void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) override; 98 /*! \brief Get the name of the implementation. 99 * 100 * \return "SHAKE" string; 101 */ name()102 std::string name() override { return "SHAKE on CPU"; } 103 }; 104 105 // Runner for the CPU implementation of LINCS constraints algorithm. 106 class LincsConstraintsRunner : public IConstraintsTestRunner 107 { 108 public: 109 //! Default constructor. LincsConstraintsRunner()110 LincsConstraintsRunner() {} 111 /*! \brief Apply LINCS constraints to the test data on the CPU. 112 * 113 * \param[in] testData Test data structure. 114 * \param[in] pbc Periodic boundary data. 115 */ 116 void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) override; 117 /*! \brief Get the name of the implementation. 118 * 119 * \return "LINCS" string; 120 */ name()121 std::string name() override { return "LINCS on CPU"; } 122 }; 123 124 // Runner for the GPU implementation of LINCS constraints algorithm. 125 class LincsDeviceConstraintsRunner : public IConstraintsTestRunner 126 { 127 public: 128 /*! \brief Constructor. Keeps a copy of the hardware context. 129 * 130 * \param[in] testDevice The device hardware context to be used by the runner. 131 */ LincsDeviceConstraintsRunner(const TestDevice & testDevice)132 LincsDeviceConstraintsRunner(const TestDevice& testDevice) : testDevice_(testDevice) {} 133 /*! \brief Apply LINCS constraints to the test data on the GPU. 134 * 135 * \param[in] testData Test data structure. 136 * \param[in] pbc Periodic boundary data. 137 */ 138 void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) override; 139 /*! \brief Get the name of the implementation. 140 * 141 * \return "LINCS_GPU" string; 142 */ name()143 std::string name() override { return "LINCS on " + testDevice_.description(); } 144 145 private: 146 //! Test device to be used in the runner. 147 const TestDevice& testDevice_; 148 }; 149 150 } // namespace test 151 } // namespace gmx 152 153 #endif // GMX_MDLIB_TESTS_CONSTRTESTRUNNERS_H 154