From c17701575d5c2285b96beb61e68c0e1a4171d55b Mon Sep 17 00:00:00 2001 From: Artem Zhmurov Date: Thu, 3 Jun 2021 20:23:35 +0000 Subject: [PATCH] Make constraints and SETTLE tests backend-agnostic --- src/gromacs/mdlib/tests/CMakeLists.txt | 9 ++--- src/gromacs/mdlib/tests/constr.cpp | 5 ++- src/gromacs/mdlib/tests/constrtestrunners.cpp | 8 ---- src/gromacs/mdlib/tests/constrtestrunners.h | 7 +++- ...strunners.cu => constrtestrunners_gpu.cpp} | 27 +++++++++----- src/gromacs/mdlib/tests/leapfrog.cpp | 6 +-- src/gromacs/mdlib/tests/leapfrogtestrunners.h | 2 +- .../mdlib/tests/leapfrogtestrunners_gpu.cpp | 21 ++++------- src/gromacs/mdlib/tests/settle.cpp | 7 ++-- src/gromacs/mdlib/tests/settletestrunners.cpp | 13 ------- src/gromacs/mdlib/tests/settletestrunners.h | 7 +++- ...strunners.cu => settletestrunners_gpu.cpp} | 37 +++++++++++-------- 12 files changed, 73 insertions(+), 76 deletions(-) rename src/gromacs/mdlib/tests/{constrtestrunners.cu => constrtestrunners_gpu.cpp} (89%) rename src/gromacs/mdlib/tests/{settletestrunners.cu => settletestrunners_gpu.cpp} (85%) diff --git a/src/gromacs/mdlib/tests/CMakeLists.txt b/src/gromacs/mdlib/tests/CMakeLists.txt index e50f85ab4f..5854759fd5 100644 --- a/src/gromacs/mdlib/tests/CMakeLists.txt +++ b/src/gromacs/mdlib/tests/CMakeLists.txt @@ -35,12 +35,12 @@ gmx_add_unit_test(MdlibUnitTest mdlib-test HARDWARE_DETECTION CPP_SOURCE_FILES calc_verletbuf.cpp - calcvir.cpp + calcvir.cpp constr.cpp constrtestdata.cpp constrtestrunners.cpp ebin.cpp - energydrifttracker.cpp + energydrifttracker.cpp energyoutput.cpp expanded.cpp freeenergyparameters.cpp @@ -55,8 +55,7 @@ gmx_add_unit_test(MdlibUnitTest mdlib-test HARDWARE_DETECTION updategroups.cpp updategroupscog.cpp GPU_CPP_SOURCE_FILES + constrtestrunners_gpu.cpp leapfrogtestrunners_gpu.cpp - CUDA_CU_SOURCE_FILES - constrtestrunners.cu - settletestrunners.cu + settletestrunners_gpu.cpp ) diff --git a/src/gromacs/mdlib/tests/constr.cpp b/src/gromacs/mdlib/tests/constr.cpp index 2331b1f649..39b7227ce6 100644 --- a/src/gromacs/mdlib/tests/constr.cpp +++ b/src/gromacs/mdlib/tests/constr.cpp @@ -530,8 +530,9 @@ public: // Add runners for CPU versions of SHAKE and LINCS runners.emplace_back(std::make_unique()); runners.emplace_back(std::make_unique()); - // If using CUDA, add runners for the GPU version of LINCS for each available GPU - if (GMX_GPU_CUDA) + // If supported, add runners for the GPU version of LINCS for each available GPU + const bool addGpuRunners = GPU_CONSTRAINTS_SUPPORTED; + if (addGpuRunners) { for (const auto& testDevice : getTestHardwareEnvironment()->getTestDeviceList()) { diff --git a/src/gromacs/mdlib/tests/constrtestrunners.cpp b/src/gromacs/mdlib/tests/constrtestrunners.cpp index 608e05a2b7..125ce3a420 100644 --- a/src/gromacs/mdlib/tests/constrtestrunners.cpp +++ b/src/gromacs/mdlib/tests/constrtestrunners.cpp @@ -176,13 +176,5 @@ void LincsConstraintsRunner::applyConstraints(ConstraintsTestData* testData, t_p done_lincs(lincsd); } -#if !GMX_GPU_CUDA -void LincsDeviceConstraintsRunner::applyConstraints(ConstraintsTestData* /* testData */, t_pbc /* pbc */) -{ - GMX_UNUSED_VALUE(testDevice_); - FAIL() << "Dummy LINCS CUDA function was called instead of the real one."; -} -#endif // !GMX_GPU_CUDA - } // namespace test } // namespace gmx diff --git a/src/gromacs/mdlib/tests/constrtestrunners.h b/src/gromacs/mdlib/tests/constrtestrunners.h index d479e5537c..04a900075c 100644 --- a/src/gromacs/mdlib/tests/constrtestrunners.h +++ b/src/gromacs/mdlib/tests/constrtestrunners.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -53,6 +53,11 @@ #include "constrtestdata.h" +/* + * GPU version of constraints is only available with CUDA. + */ +#define GPU_CONSTRAINTS_SUPPORTED (GMX_GPU_CUDA) + struct t_pbc; namespace gmx diff --git a/src/gromacs/mdlib/tests/constrtestrunners.cu b/src/gromacs/mdlib/tests/constrtestrunners_gpu.cpp similarity index 89% rename from src/gromacs/mdlib/tests/constrtestrunners.cu rename to src/gromacs/mdlib/tests/constrtestrunners_gpu.cpp index 1f45f0ccab..3a5eff99f9 100644 --- a/src/gromacs/mdlib/tests/constrtestrunners.cu +++ b/src/gromacs/mdlib/tests/constrtestrunners_gpu.cpp @@ -42,27 +42,26 @@ */ #include "gmxpre.h" -#include "constrtestrunners.h" - -#include +#include "config.h" -#include +#include -#include -#include +#include "constrtestrunners.h" -#include "gromacs/gpu_utils/devicebuffer.cuh" +#if GPU_CONSTRAINTS_SUPPORTED +# include "gromacs/gpu_utils/devicebuffer.h" +#endif #include "gromacs/gpu_utils/gputraits.h" -#include "gromacs/hardware/device_information.h" #include "gromacs/mdlib/lincs_gpu.h" #include "gromacs/pbcutil/pbc.h" -#include "gromacs/utility/unique_cptr.h" namespace gmx { namespace test { +#if GPU_CONSTRAINTS_SUPPORTED + void LincsDeviceConstraintsRunner::applyConstraints(ConstraintsTestData* testData, t_pbc pbc) { const DeviceContext& deviceContext = testDevice_.deviceContext(); @@ -109,5 +108,15 @@ void LincsDeviceConstraintsRunner::applyConstraints(ConstraintsTestData* testDat freeDeviceBuffer(&d_v); } +#else // GPU_CONSTRAINTS_SUPPORTED + +void LincsDeviceConstraintsRunner::applyConstraints(ConstraintsTestData* /* testData */, t_pbc /* pbc */) +{ + GMX_UNUSED_VALUE(testDevice_); + FAIL() << "Dummy LINCS GPU function was called instead of the real one."; +} + +#endif // GPU_CONSTRAINTS_SUPPORTED + } // namespace test } // namespace gmx diff --git a/src/gromacs/mdlib/tests/leapfrog.cpp b/src/gromacs/mdlib/tests/leapfrog.cpp index 504b9600c2..d557422f87 100644 --- a/src/gromacs/mdlib/tests/leapfrog.cpp +++ b/src/gromacs/mdlib/tests/leapfrog.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019,2020, by the GROMACS development team, led by + * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -209,8 +209,8 @@ TEST_P(LeapFrogTest, SimpleIntegration) std::vector> runners; // Add runners for CPU version runners.emplace_back(std::make_unique()); - // If using CUDA, add runners for the GPU version for each available GPU - const bool addGpuRunners = HAVE_GPU_LEAPFROG; + // If supported, add runners for the GPU version for each available GPU + const bool addGpuRunners = GPU_LEAPFROG_SUPPORTED; if (addGpuRunners) { for (const auto& testDevice : getTestHardwareEnvironment()->getTestDeviceList()) diff --git a/src/gromacs/mdlib/tests/leapfrogtestrunners.h b/src/gromacs/mdlib/tests/leapfrogtestrunners.h index 37810d22dc..117a2d51a7 100644 --- a/src/gromacs/mdlib/tests/leapfrogtestrunners.h +++ b/src/gromacs/mdlib/tests/leapfrogtestrunners.h @@ -57,7 +57,7 @@ /* * LeapFrog is available with CUDA and SYCL. */ -#define HAVE_GPU_LEAPFROG (GMX_GPU_CUDA || GMX_GPU_SYCL) +#define GPU_LEAPFROG_SUPPORTED (GMX_GPU_CUDA || GMX_GPU_SYCL) namespace gmx { diff --git a/src/gromacs/mdlib/tests/leapfrogtestrunners_gpu.cpp b/src/gromacs/mdlib/tests/leapfrogtestrunners_gpu.cpp index 97c9c29481..ee38a6e10e 100644 --- a/src/gromacs/mdlib/tests/leapfrogtestrunners_gpu.cpp +++ b/src/gromacs/mdlib/tests/leapfrogtestrunners_gpu.cpp @@ -48,19 +48,11 @@ #include "leapfrogtestrunners.h" -#if GMX_GPU_CUDA -# include "gromacs/gpu_utils/devicebuffer.cuh" +#if GPU_LEAPFROG_SUPPORTED +# include "gromacs/gpu_utils/devicebuffer.h" #endif -#if GMX_GPU_SYCL -# include "gromacs/gpu_utils/devicebuffer_sycl.h" -#endif - -#if HAVE_GPU_LEAPFROG -# include "gromacs/mdlib/leapfrog_gpu.h" -#endif - #include "gromacs/gpu_utils/gputraits.h" -#include "gromacs/hardware/device_information.h" +#include "gromacs/mdlib/leapfrog_gpu.h" #include "gromacs/mdlib/stat.h" namespace gmx @@ -68,7 +60,8 @@ namespace gmx namespace test { -#if HAVE_GPU_LEAPFROG +#if GPU_LEAPFROG_SUPPORTED + void LeapFrogDeviceTestRunner::integrate(LeapFrogTestData* testData, int numSteps) { const DeviceContext& deviceContext = testDevice_.deviceContext(); @@ -127,7 +120,7 @@ void LeapFrogDeviceTestRunner::integrate(LeapFrogTestData* testData, int numStep freeDeviceBuffer(&d_f); } -#else // HAVE_GPU_LEAPFROG +#else // GPU_LEAPFROG_SUPPORTED void LeapFrogDeviceTestRunner::integrate(LeapFrogTestData* /* testData */, int /* numSteps */) { @@ -135,7 +128,7 @@ void LeapFrogDeviceTestRunner::integrate(LeapFrogTestData* /* testData */, int / FAIL() << "Dummy Leap-Frog GPU function was called instead of the real one."; } -#endif // HAVE_GPU_LEAPFROG +#endif // GPU_LEAPFROG_SUPPORTED } // namespace test } // namespace gmx diff --git a/src/gromacs/mdlib/tests/settle.cpp b/src/gromacs/mdlib/tests/settle.cpp index 1d71b0f420..b56020ffd1 100644 --- a/src/gromacs/mdlib/tests/settle.cpp +++ b/src/gromacs/mdlib/tests/settle.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2016,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2016,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -312,8 +312,9 @@ TEST_P(SettleTest, SatisfiesConstraints) std::vector> runners; // Add runners for CPU version runners.emplace_back(std::make_unique()); - // If using CUDA, add runners for the GPU version for each available GPU - if (GMX_GPU_CUDA) + // If supported, add runners for the GPU version for each available GPU + const bool addGpuRunners = GPU_SETTLE_SUPPORTED; + if (addGpuRunners) { for (const auto& testDevice : getTestHardwareEnvironment()->getTestDeviceList()) { diff --git a/src/gromacs/mdlib/tests/settletestrunners.cpp b/src/gromacs/mdlib/tests/settletestrunners.cpp index c494341cc2..80e8db0e91 100644 --- a/src/gromacs/mdlib/tests/settletestrunners.cpp +++ b/src/gromacs/mdlib/tests/settletestrunners.cpp @@ -85,18 +85,5 @@ void SettleHostTestRunner::applySettle(SettleTestData* testData, EXPECT_FALSE(errorOccured) << testDescription; } -#if !GMX_GPU_CUDA - -void SettleDeviceTestRunner::applySettle(SettleTestData* /* testData */, - const t_pbc /* pbc */, - const bool /* updateVelocities */, - const bool /* calcVirial */, - const std::string& /* testDescription */) -{ - GMX_UNUSED_VALUE(testDevice_); - FAIL() << "Dummy SETTLE GPU function was called instead of the real one in the SETTLE test."; -} - -#endif } // namespace test } // namespace gmx diff --git a/src/gromacs/mdlib/tests/settletestrunners.h b/src/gromacs/mdlib/tests/settletestrunners.h index 3f643f605e..f890cbd78d 100644 --- a/src/gromacs/mdlib/tests/settletestrunners.h +++ b/src/gromacs/mdlib/tests/settletestrunners.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -52,6 +52,11 @@ #include "settletestdata.h" +/* + * GPU version of SETTLE is only available with CUDA. + */ +#define GPU_SETTLE_SUPPORTED (GMX_GPU_CUDA) + struct t_pbc; namespace gmx diff --git a/src/gromacs/mdlib/tests/settletestrunners.cu b/src/gromacs/mdlib/tests/settletestrunners_gpu.cpp similarity index 85% rename from src/gromacs/mdlib/tests/settletestrunners.cu rename to src/gromacs/mdlib/tests/settletestrunners_gpu.cpp index b35cf0be9b..c6f34cf4ca 100644 --- a/src/gromacs/mdlib/tests/settletestrunners.cu +++ b/src/gromacs/mdlib/tests/settletestrunners_gpu.cpp @@ -40,40 +40,31 @@ */ #include "gmxpre.h" -#include "settletestrunners.h" - #include "config.h" -#include +#include -#include - -#include -#include +#include "settletestrunners.h" -#include "gromacs/gpu_utils/devicebuffer.cuh" +#if GPU_SETTLE_SUPPORTED +# include "gromacs/gpu_utils/devicebuffer.h" +#endif #include "gromacs/gpu_utils/gputraits.h" -#include "gromacs/hardware/device_information.h" #include "gromacs/mdlib/settle_gpu.h" -#include "gromacs/utility/unique_cptr.h" - -#include "testutils/test_device.h" namespace gmx { namespace test { +#if GPU_SETTLE_SUPPORTED + void SettleDeviceTestRunner::applySettle(SettleTestData* testData, const t_pbc pbc, const bool updateVelocities, const bool calcVirial, const std::string& /* testDescription */) { - // These should never fail since this function should only be called if CUDA is enabled and - // there is a CUDA-capable device available. - GMX_RELEASE_ASSERT(GMX_GPU_CUDA, "CUDA version of SETTLE was called from non-CUDA build."); - const DeviceContext& deviceContext = testDevice_.deviceContext(); const DeviceStream& deviceStream = testDevice_.deviceStream(); setActiveDevice(testDevice_.deviceInfo()); @@ -116,5 +107,19 @@ void SettleDeviceTestRunner::applySettle(SettleTestData* testData, freeDeviceBuffer(&d_v); } +#else // GPU_SETTLE_SUPPORTED + +void SettleDeviceTestRunner::applySettle(SettleTestData* /* testData */, + const t_pbc /* pbc */, + const bool /* updateVelocities */, + const bool /* calcVirial */, + const std::string& /* testDescription */) +{ + GMX_UNUSED_VALUE(testDevice_); + FAIL() << "Dummy SETTLE GPU function was called instead of the real one in the SETTLE test."; +} + +#endif // GPU_SETTLE_SUPPORTED + } // namespace test } // namespace gmx -- 2.22.0