//! 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)
/*
* 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.
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);
//! 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);
{
namespace
{
+
TEST(NbnxmSetupTest, findNumEnergyGroups)
{
std::vector<int64_t> v(10);
}
#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