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 SHAKE and LINCS tests runners.
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.
43 * \author Artem Zhmurov <zhmurov@gmail.com>
44 * \ingroup module_mdlib
47 #ifndef GMX_MDLIB_TESTS_CONSTRTESTRUNNERS_H
48 #define GMX_MDLIB_TESTS_CONSTRTESTRUNNERS_H
50 #include <gtest/gtest.h>
52 #include "testutils/test_device.h"
54 #include "constrtestdata.h"
57 * GPU version of constraints is only available with CUDA.
59 #define GPU_CONSTRAINTS_SUPPORTED (GMX_GPU_CUDA)
68 /* \brief Constraints test runner interface.
70 * Wraps the actual implementation of constraints algorithm into common interface.
72 class IConstraintsTestRunner
75 //! Virtual destructor.
76 virtual ~IConstraintsTestRunner() {}
77 /*! \brief Abstract constraining function. Should be overriden.
79 * \param[in] testData Test data structure.
80 * \param[in] pbc Periodic boundary data.
82 virtual void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) = 0;
84 /*! \brief Get the name of the implementation.
86 * \return "<algorithm> on <device>", depending on the actual implementation used. E.g., "LINCS on #0: NVIDIA GeForce GTX 1660 SUPER".
88 virtual std::string name() = 0;
91 // Runner for the CPU implementation of SHAKE constraints algorithm.
92 class ShakeConstraintsRunner : public IConstraintsTestRunner
95 //! Default constructor.
96 ShakeConstraintsRunner() {}
97 /*! \brief Apply SHAKE constraints to the test data.
99 * \param[in] testData Test data structure.
100 * \param[in] pbc Periodic boundary data.
102 void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) override;
103 /*! \brief Get the name of the implementation.
105 * \return "SHAKE" string;
107 std::string name() override { return "SHAKE on CPU"; }
110 // Runner for the CPU implementation of LINCS constraints algorithm.
111 class LincsConstraintsRunner : public IConstraintsTestRunner
114 //! Default constructor.
115 LincsConstraintsRunner() {}
116 /*! \brief Apply LINCS constraints to the test data on the CPU.
118 * \param[in] testData Test data structure.
119 * \param[in] pbc Periodic boundary data.
121 void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) override;
122 /*! \brief Get the name of the implementation.
124 * \return "LINCS" string;
126 std::string name() override { return "LINCS on CPU"; }
129 // Runner for the GPU implementation of LINCS constraints algorithm.
130 class LincsDeviceConstraintsRunner : public IConstraintsTestRunner
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 LincsDeviceConstraintsRunner(const TestDevice& testDevice) : testDevice_(testDevice) {}
138 /*! \brief Apply LINCS constraints to the test data on the GPU.
140 * \param[in] testData Test data structure.
141 * \param[in] pbc Periodic boundary data.
143 void applyConstraints(ConstraintsTestData* testData, t_pbc pbc) override;
144 /*! \brief Get the name of the implementation.
146 * \return "LINCS_GPU" string;
148 std::string name() override { return "LINCS on " + testDevice_.description(); }
151 //! Test device to be used in the runner.
152 const TestDevice& testDevice_;
158 #endif // GMX_MDLIB_TESTS_CONSTRTESTRUNNERS_H