Add createNbnxmCPU, usage, and test
authorJoe Jordan <ejjordan12@gmail.com>
Fri, 11 Jun 2021 15:01:24 +0000 (15:01 +0000)
committerJoe Jordan <ejjordan12@gmail.com>
Fri, 11 Jun 2021 15:01:24 +0000 (15:01 +0000)
api/nblib/gmxsetup.cpp
api/nblib/nbnxmsetuphelpers.cpp
api/nblib/nbnxmsetuphelpers.h
api/nblib/tests/nbnxmsetup.cpp

index ba679f8451dbbca8ca9be980565ecf626942bdee..27ead291e8675b69ea2660253d7c92d1a75b252f 100644 (file)
@@ -102,37 +102,8 @@ void NbvSetupUtil::setAtomProperties(const std::vector<int>&  particleTypeIdOfAl
 //! Sets up and returns a Nbnxm object for the given options and system
 void NbvSetupUtil::setupNbnxmInstance(const size_t numParticleTypes, const NBKernelOptions& options)
 {
-    const auto pinPolicy  = (options.useGpu ? gmx::PinningPolicy::PinnedIfSupported
-                                            : gmx::PinningPolicy::CannotBePinned);
-    const int  numThreads = options.numOpenMPThreads;
-    // Note: the options and Nbnxm combination rule enums values should match
-    const int combinationRule = static_cast<int>(options.ljCombinationRule);
-
-    checkKernelSetup(options.nbnxmSimd); // throws exception is setup is invalid
-
-    Nbnxm::KernelSetup kernelSetup = getKernelSetup(options);
-
-    PairlistParams pairlistParams(kernelSetup.kernelType, false, options.pairlistCutoff, false);
-    Nbnxm::GridSet gridSet(
-            PbcType::Xyz, false, nullptr, nullptr, pairlistParams.pairlistType, false, numThreads, pinPolicy);
-    auto pairlistSets = std::make_unique<PairlistSets>(pairlistParams, false, 0);
-    auto pairSearch   = std::make_unique<PairSearch>(
-            PbcType::Xyz, false, nullptr, nullptr, pairlistParams.pairlistType, false, numThreads, pinPolicy);
-
-    auto atomData = std::make_unique<nbnxn_atomdata_t>(pinPolicy,
-                                                       gmx::MDLogger(),
-                                                       kernelSetup.kernelType,
-                                                       combinationRule,
-                                                       numParticleTypes,
-                                                       nonbondedParameters_,
-                                                       1,
-                                                       numThreads);
-
-    // Put everything together
-    auto nbv = std::make_unique<nonbonded_verlet_t>(
-            std::move(pairlistSets), std::move(pairSearch), std::move(atomData), kernelSetup, nullptr, nullptr);
-
-    gmxForceCalculator_->nbv_ = std::move(nbv);
+
+    gmxForceCalculator_->nbv_ = createNbnxmCPU(numParticleTypes, options, 1, nonbondedParameters_);
 }
 
 void NbvSetupUtil::setupStepWorkload(const NBKernelOptions& options)
index 709ced3ce7d89ac5d78aba0dfe835330ed0015c4..a1b4c9c22fee217ebce22f652bdc884a75a72a7f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2021, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -245,6 +245,41 @@ interaction_const_t createInteractionConst(const NBKernelOptions& options)
     return interactionConst;
 }
 
+std::unique_ptr<nonbonded_verlet_t> createNbnxmCPU(const size_t              numParticleTypes,
+                                                   const NBKernelOptions&    options,
+                                                   int                       numEnergyGroups,
+                                                   gmx::ArrayRef<const real> nonbondedParameters)
+{
+    const auto pinPolicy  = gmx::PinningPolicy::CannotBePinned;
+    const int  numThreads = options.numOpenMPThreads;
+    // Note: the options and Nbnxm combination rule enums values should match
+    const int combinationRule = static_cast<int>(options.ljCombinationRule);
+
+    Nbnxm::KernelSetup kernelSetup = createKernelSetupCPU(options);
+
+    PairlistParams pairlistParams(kernelSetup.kernelType, false, options.pairlistCutoff, false);
+
+    auto pairlistSets = std::make_unique<PairlistSets>(pairlistParams, false, 0);
+    auto pairSearch   = std::make_unique<PairSearch>(
+            PbcType::Xyz, false, nullptr, nullptr, pairlistParams.pairlistType, false, numThreads, pinPolicy);
+
+    // Needs to be called with the number of unique ParticleTypes
+    auto atomData = std::make_unique<nbnxn_atomdata_t>(pinPolicy,
+                                                       gmx::MDLogger(),
+                                                       kernelSetup.kernelType,
+                                                       combinationRule,
+                                                       numParticleTypes,
+                                                       nonbondedParameters,
+                                                       numEnergyGroups,
+                                                       numThreads);
+
+    // Put everything together
+    auto nbv = std::make_unique<nonbonded_verlet_t>(
+            std::move(pairlistSets), std::move(pairSearch), std::move(atomData), kernelSetup, nullptr, nullptr);
+
+    return nbv;
+}
+
 void setGmxNonBondedNThreads(int numThreads)
 {
     gmx_omp_nthreads_set(ModuleMultiThread::Pairsearch, numThreads);
index decaa71e767c91ba080128bcaa03c724fdc9e92a..b3a2dc504b8a8d5699f2cb0e88739a331f2477cf 100644 (file)
@@ -107,6 +107,12 @@ real ewaldCoeff(real ewald_rtol, real pairlistCutoff);
 //! Creates an interaction_const_t object from NBKernelOptions
 interaction_const_t createInteractionConst(const NBKernelOptions& options);
 
+//! Create nonbonded_verlet_t object
+std::unique_ptr<nonbonded_verlet_t> createNbnxmCPU(size_t                    numParticleTypes,
+                                                   const NBKernelOptions&    options,
+                                                   int                       numEnergyGroups,
+                                                   gmx::ArrayRef<const real> nonbondedParameters);
+
 //! Set number of OpenMP threads in the GROMACS backend
 void setGmxNonBondedNThreads(int numThreads);
 
index 5b02de6f000627ff86f56de3c1de346780bd2636..a928ed4aa65d5df112e34bd905444bf59f94587d 100644 (file)
@@ -58,6 +58,7 @@ namespace test
 {
 namespace
 {
+
 TEST(NbnxmSetupTest, findNumEnergyGroups)
 {
     std::vector<int64_t> v(10);
@@ -178,6 +179,16 @@ TEST(NbnxmSetupTest, cannotCreateKernelSetupCPU4XM)
 }
 #endif
 
+TEST(NbnxmSetupTest, CanCreateNbnxmCPU)
+{
+    size_t          numParticles = 1;
+    NBKernelOptions nbKernelOptions;
+    nbKernelOptions.nbnxmSimd             = SimdKernels::SimdNo;
+    int               numEnergyGroups     = 1;
+    std::vector<real> nonbondedParameters = { 1, 1 };
+    EXPECT_NO_THROW(createNbnxmCPU(numParticles, nbKernelOptions, numEnergyGroups, nonbondedParameters));
+}
+
 } // namespace
 } // namespace test
 } // namespace nblib