Rework nblib kernel checks and setup code
authorJoe Jordan <ejjordan12@gmail.com>
Mon, 16 Aug 2021 13:49:41 +0000 (13:49 +0000)
committerMark Abraham <mark.j.abraham@gmail.com>
Mon, 16 Aug 2021 13:49:41 +0000 (13:49 +0000)
api/nblib/gmxsetup.cpp
api/nblib/gmxsetup.h
api/nblib/nbnxmsetuphelpers.cpp
api/nblib/nbnxmsetuphelpers.h
api/nblib/tests/nbnxmsetup.cpp

index 27ead291e8675b69ea2660253d7c92d1a75b252f..e90cba391027dddcc2b4ef87f145ff9fac6f20aa 100644 (file)
@@ -76,15 +76,10 @@ void NbvSetupUtil::setExecutionContext(const NBKernelOptions& options)
     setGmxNonBondedNThreads(options.numOpenMPThreads);
 }
 
-Nbnxm::KernelSetup NbvSetupUtil::getKernelSetup(const NBKernelOptions& options)
-{
-    return createKernelSetupCPU(options);
-}
-
 void NbvSetupUtil::setParticleInfoAllVdv(const size_t numParticles)
 
 {
-    particleInfoAllVdw_ = createParticleInfoAllVdv(numParticles);
+    particleInfoAllVdw_ = createParticleInfoAllVdw(numParticles);
 }
 
 void NbvSetupUtil::setNonBondedParameters(const std::vector<ParticleType>& particleTypes,
index 3382cf17ecfde5f148c4f642eba6f64ae95b7234..bef3ee740d7b6a7679a73af85acbfed7179a3d2e 100644 (file)
@@ -85,9 +85,6 @@ public:
     //! Marks particles to have Van der Waals interactions
     void setParticleInfoAllVdv(size_t numParticles);
 
-    //! Returns the kernel setup
-    Nbnxm::KernelSetup getKernelSetup(const NBKernelOptions& options);
-
     //! Set up StepWorkload data
     void setupStepWorkload(const NBKernelOptions& options);
 
index a1b4c9c22fee217ebce22f652bdc884a75a72a7f..027a0fdeb1d4018e55a498ea9262b3fac4afeb2f 100644 (file)
@@ -86,7 +86,7 @@ Nbnxm::KernelType translateBenchmarkEnum(const SimdKernels& kernel)
     return static_cast<Nbnxm::KernelType>(kernelInt);
 }
 
-void checkKernelSetup(const SimdKernels nbnxmSimd)
+void checkKernelSetupSimd(const SimdKernels nbnxmSimd)
 {
     if (nbnxmSimd >= SimdKernels::Count || nbnxmSimd == SimdKernels::SimdAuto)
     {
@@ -106,14 +106,14 @@ void checkKernelSetup(const SimdKernels nbnxmSimd)
     }
 }
 
-Nbnxm::KernelSetup createKernelSetupCPU(const NBKernelOptions& options)
+Nbnxm::KernelSetup createKernelSetupCPU(const SimdKernels nbnxmSimd, const bool useTabulatedEwaldCorr)
 {
-    checkKernelSetup(options.nbnxmSimd);
+    checkKernelSetupSimd(nbnxmSimd);
 
     Nbnxm::KernelSetup kernelSetup;
 
     // The int enum options.nbnxnSimd is set up to match Nbnxm::KernelType + 1
-    kernelSetup.kernelType = translateBenchmarkEnum(options.nbnxmSimd);
+    kernelSetup.kernelType = translateBenchmarkEnum(nbnxmSimd);
 
     // The plain-C kernel does not support analytical ewald correction
     if (kernelSetup.kernelType == Nbnxm::KernelType::Cpu4x4_PlainC)
@@ -122,16 +122,14 @@ Nbnxm::KernelSetup createKernelSetupCPU(const NBKernelOptions& options)
     }
     else
     {
-        kernelSetup.ewaldExclusionType = options.useTabulatedEwaldCorr
-                                                 ? Nbnxm::EwaldExclusionType::Table
-                                                 : Nbnxm::EwaldExclusionType::Analytical;
+        kernelSetup.ewaldExclusionType = useTabulatedEwaldCorr ? Nbnxm::EwaldExclusionType::Table
+                                                               : Nbnxm::EwaldExclusionType::Analytical;
     }
 
     return kernelSetup;
 }
 
-std::vector<int64_t> createParticleInfoAllVdv(const size_t numParticles)
-
+std::vector<int64_t> createParticleInfoAllVdw(const size_t numParticles)
 {
     std::vector<int64_t> particleInfoAllVdw(numParticles);
     for (size_t particleI = 0; particleI < numParticles; particleI++)
@@ -255,7 +253,8 @@ std::unique_ptr<nonbonded_verlet_t> createNbnxmCPU(const size_t              num
     // Note: the options and Nbnxm combination rule enums values should match
     const int combinationRule = static_cast<int>(options.ljCombinationRule);
 
-    Nbnxm::KernelSetup kernelSetup = createKernelSetupCPU(options);
+    Nbnxm::KernelSetup kernelSetup =
+            createKernelSetupCPU(options.nbnxmSimd, options.useTabulatedEwaldCorr);
 
     PairlistParams pairlistParams(kernelSetup.kernelType, false, options.pairlistCutoff, false);
 
index b3a2dc504b8a8d5699f2cb0e88739a331f2477cf..9c3ee71f4697b764f7bef79cf70823c018491b75 100644 (file)
@@ -82,17 +82,17 @@ int64_t findNumEnergyGroups(gmx::ArrayRef<int64_t> particleInteractionFlags);
 //! Helper to translate between the different enumeration values.
 Nbnxm::KernelType translateBenchmarkEnum(const SimdKernels& kernel);
 
-/*! \brief Checks the kernel setup
+/*! \brief Checks the kernel SIMD setup in CPU case
  *
  * Throws an exception when the kernel is not available.
  */
-void checkKernelSetup(SimdKernels nbnxmSimd);
+void checkKernelSetupSimd(SimdKernels nbnxmSimd);
 
-//! Creates and returns the kernel setup
-Nbnxm::KernelSetup createKernelSetupCPU(const NBKernelOptions& options);
+//! Creates and returns the kernel setup for CPU
+Nbnxm::KernelSetup createKernelSetupCPU(const SimdKernels nbnxmSimd, const bool useTabulatedEwaldCorr);
 
 //! Create Particle info array to mark those that undergo VdV interaction
-std::vector<int64_t> createParticleInfoAllVdv(size_t numParticles);
+std::vector<int64_t> createParticleInfoAllVdw(size_t numParticles);
 
 //! Create the non-bonded parameter vector in GROMACS format
 std::vector<real> createNonBondedParameters(const std::vector<ParticleType>& particleTypes,
index a928ed4aa65d5df112e34bd905444bf59f94587d..a7bff00fdf72a013374580a90cdd89b8cc24c95c 100644 (file)
@@ -43,8 +43,9 @@
  */
 #include <cmath>
 
-#include "gromacs/utility/arrayref.h"
 #include "gromacs/mdtypes/forcerec.h"
+#include "gromacs/mdtypes/interaction_const.h"
+#include "gromacs/mdtypes/simulation_workload.h"
 #include "gromacs/nbnxm/nbnxm.h"
 #include "gromacs/nbnxm/nbnxm_simd.h"
 #include "nblib/box.h"
@@ -99,19 +100,20 @@ TEST(NbnxmSetupTest, canTranslateBenchmarkEnum4XM)
 
 TEST(NbnxmSetupTest, CheckKernelSetupThrowsAuto)
 {
-    EXPECT_ANY_THROW(checkKernelSetup(SimdKernels::SimdAuto));
+    EXPECT_ANY_THROW(checkKernelSetupSimd(SimdKernels::SimdAuto));
 }
 
 TEST(NbnxmSetupTest, CheckKernelSetupThrowsCount)
 {
-    EXPECT_ANY_THROW(checkKernelSetup(SimdKernels::Count));
+    EXPECT_ANY_THROW(checkKernelSetupSimd(SimdKernels::Count));
 }
 
 TEST(NbnxmSetupTest, canCreateKernelSetupPlain)
 {
     NBKernelOptions nbKernelOptions;
-    nbKernelOptions.nbnxmSimd      = SimdKernels::SimdNo;
-    Nbnxm::KernelSetup kernelSetup = createKernelSetupCPU(nbKernelOptions);
+    nbKernelOptions.nbnxmSimd = SimdKernels::SimdNo;
+    Nbnxm::KernelSetup kernelSetup =
+            createKernelSetupCPU(nbKernelOptions.nbnxmSimd, nbKernelOptions.useTabulatedEwaldCorr);
     EXPECT_EQ(kernelSetup.kernelType, Nbnxm::KernelType::Cpu4x4_PlainC);
     EXPECT_EQ(kernelSetup.ewaldExclusionType, Nbnxm::EwaldExclusionType::Table);
 }
@@ -123,7 +125,7 @@ TEST(NbnxmSetupTest, canCreateParticleInfoAllVdv)
     mask |= gmx::sc_atomInfo_HasVdw;
     mask |= gmx::sc_atomInfo_HasCharge;
     std::vector<int64_t> refParticles  = { mask, mask };
-    std::vector<int64_t> testParticles = createParticleInfoAllVdv(numParticles);
+    std::vector<int64_t> testParticles = createParticleInfoAllVdw(numParticles);
     EXPECT_EQ(refParticles, testParticles);
 }
 
@@ -154,7 +156,7 @@ TEST(NbnxmSetupTest, canCheckKernelSetup)
 #ifdef GMX_NBNXN_SIMD_2XNN
     nbKernelOptions.nbnxmSimd = SimdKernels::Simd2XMM;
 #endif
-    EXPECT_NO_THROW(checkKernelSetup(nbKernelOptions.nbnxmSimd));
+    EXPECT_NO_THROW(checkKernelSetupSimd(nbKernelOptions.nbnxmSimd));
 }
 
 // check if the user is allowed to ask for SimdKernels::Simd2XMM when NBLIB is not compiled with it
@@ -164,7 +166,7 @@ TEST(NbnxmSetupTest, cannotCreateKernelSetupCPU2XM)
     NBKernelOptions nbKernelOptions;
     nbKernelOptions.nbnxmSimd             = SimdKernels::Simd2XMM;
     nbKernelOptions.useTabulatedEwaldCorr = true;
-    EXPECT_ANY_THROW(createKernelSetupCPU(nbKernelOptions));
+    EXPECT_ANY_THROW(createKernelSetupCPU(nbKernelOptions.nbnxmSimd, nbKernelOptions.useTabulatedEwaldCorr));
 }
 #endif
 
@@ -175,7 +177,7 @@ TEST(NbnxmSetupTest, cannotCreateKernelSetupCPU4XM)
     NBKernelOptions nbKernelOptions;
     nbKernelOptions.nbnxmSimd             = SimdKernels::Simd4XM;
     nbKernelOptions.useTabulatedEwaldCorr = false;
-    EXPECT_ANY_THROW(createKernelSetupCPU(nbKernelOptions));
+    EXPECT_ANY_THROW(createKernelSetupCPU(nbKernelOptions.nbnxmSimd, nbKernelOptions.useTabulatedEwaldCorr));
 }
 #endif