Make constraints and SETTLE tests backend-agnostic
authorArtem Zhmurov <zhmurov@gmail.com>
Thu, 3 Jun 2021 20:23:35 +0000 (20:23 +0000)
committerJoe Jordan <ejjordan12@gmail.com>
Thu, 3 Jun 2021 20:23:35 +0000 (20:23 +0000)
12 files changed:
src/gromacs/mdlib/tests/CMakeLists.txt
src/gromacs/mdlib/tests/constr.cpp
src/gromacs/mdlib/tests/constrtestrunners.cpp
src/gromacs/mdlib/tests/constrtestrunners.h
src/gromacs/mdlib/tests/constrtestrunners_gpu.cpp [moved from src/gromacs/mdlib/tests/constrtestrunners.cu with 89% similarity]
src/gromacs/mdlib/tests/leapfrog.cpp
src/gromacs/mdlib/tests/leapfrogtestrunners.h
src/gromacs/mdlib/tests/leapfrogtestrunners_gpu.cpp
src/gromacs/mdlib/tests/settle.cpp
src/gromacs/mdlib/tests/settletestrunners.cpp
src/gromacs/mdlib/tests/settletestrunners.h
src/gromacs/mdlib/tests/settletestrunners_gpu.cpp [moved from src/gromacs/mdlib/tests/settletestrunners.cu with 85% similarity]

index e50f85ab4f847cccf15a8f7b2ce03176dfdf5adb..5854759fd50be71daa015fa4551b091e54d5457d 100644 (file)
 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
         )
index 2331b1f6492b698a98a0ad90f3e2e147bd7d5521..39b7227ce65fd6e649c6b8d8ed0a7aa695b57b4e 100644 (file)
@@ -530,8 +530,9 @@ public:
         // Add runners for CPU versions of SHAKE and LINCS
         runners.emplace_back(std::make_unique<ShakeConstraintsRunner>());
         runners.emplace_back(std::make_unique<LincsConstraintsRunner>());
-        // 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())
             {
index 608e05a2b73d41d0e72ae2c7519dbae93cbbc3c9..125ce3a4201a231540d64b8b9f7dcd958eb6c110 100644 (file)
@@ -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
index d479e5537cd4f7875e3514d26e562aa0cd2152d5..04a900075c438e8d4314bba4bda36fa045190bc4 100644 (file)
@@ -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.
 
 #include "constrtestdata.h"
 
+/*
+ * GPU version of constraints is only available with CUDA.
+ */
+#define GPU_CONSTRAINTS_SUPPORTED (GMX_GPU_CUDA)
+
 struct t_pbc;
 
 namespace gmx
similarity index 89%
rename from src/gromacs/mdlib/tests/constrtestrunners.cu
rename to src/gromacs/mdlib/tests/constrtestrunners_gpu.cpp
index 1f45f0ccab210a294b3a7a0e419a91b1f6d29800..3a5eff99f9f4402d7e81331178d253319be27939 100644 (file)
  */
 #include "gmxpre.h"
 
-#include "constrtestrunners.h"
-
-#include <assert.h>
+#include "config.h"
 
-#include <cmath>
+#include <gtest/gtest.h>
 
-#include <algorithm>
-#include <vector>
+#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
index 504b9600c279c7fc8b2943d9c632b56b3b6aa505..d557422f874803c6e1c5e39740882598da9935c7 100644 (file)
@@ -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<std::unique_ptr<ILeapFrogTestRunner>> runners;
     // Add runners for CPU version
     runners.emplace_back(std::make_unique<LeapFrogHostTestRunner>());
-    // 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())
index 37810d22dc4cf8baf10640c03791367dd0496d1d..117a2d51a73269d6aad2e08406199dd37c3f16bc 100644 (file)
@@ -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
 {
index 97c9c2948125f4cc3b588cdb78506a5d13b02628..ee38a6e10e2fb17a3f5001c5c985b326ab613997 100644 (file)
 
 #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
index 1d71b0f420ebd3e0ef9afcca20c047cce0c8e031..b56020ffd105ab5a30e6ff4ec71a953f0ca4c30a 100644 (file)
@@ -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<std::unique_ptr<ISettleTestRunner>> runners;
     // Add runners for CPU version
     runners.emplace_back(std::make_unique<SettleHostTestRunner>());
-    // 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())
         {
index c494341cc2b836967ee24222176d6fc2d1e4a910..80e8db0e91e2dd441ac31217a7548951c2455525 100644 (file)
@@ -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
index 3f643f605e30b7c7c4ea62a74212e9ff2e857613..f890cbd78d18e2f277bb4c5eb00268fc7e99fbb5 100644 (file)
@@ -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.
 
 #include "settletestdata.h"
 
+/*
+ * GPU version of SETTLE is only available with CUDA.
+ */
+#define GPU_SETTLE_SUPPORTED (GMX_GPU_CUDA)
+
 struct t_pbc;
 
 namespace gmx
similarity index 85%
rename from src/gromacs/mdlib/tests/settletestrunners.cu
rename to src/gromacs/mdlib/tests/settletestrunners_gpu.cpp
index b35cf0be9b03ec11643c6896b127fba61dcdcfc2..c6f34cf4cacd1c38a4c9e239a88e310291cb352b 100644 (file)
  */
 #include "gmxpre.h"
 
-#include "settletestrunners.h"
-
 #include "config.h"
 
-#include <assert.h>
+#include <gtest/gtest.h>
 
-#include <cmath>
-
-#include <algorithm>
-#include <vector>
+#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