"plugins/amoeba/openmmapi/vscode:/vscode.git/clone" did not exist on "bceea302af81bfdb0290245d69e62fd691c1a43c"
Unverified Commit f55abcaa authored by Evan Pretti's avatar Evan Pretti Committed by GitHub
Browse files

Add constant potential method (#4870)



* Initial implementation of C++ API

* Add kernel interface and information for API generation

* API updates for updating electrode parameters

* Add serialization proxy for ConstantPotentialForce

* Update file headers

* Add CG error tolerance and fix units on getCharges() return value

* Initial implementation of matrix solver

* Fixes and conjugate gradient solver

* Try to fix Linux and Windows builds

* Make sure charge constraint target is on total charge

* Restore handling of exceptions like NonbondedForce since they won't involve electrode atoms

* Ameliorate numerical instability in constrained conjugate gradient

* Fix uninitialized pointers, memory leak, and style

* Set CG tolerance units in Python API

* Test ConstantPotentialForce serialization

* Read/write ExceptionsUsePeriodicBoundaryConditions as bool

* Improve constrained conjugate gradient robustness to roundoff error accumulation

* Recompute matrix if electrode atoms move due to setPositions()

* Tolerance is now in gradient (potential) units again

* Add neutralizing background correction

* Add Python API tests

* Fixes for CG and nonbonded exceptions

* Add initial tests checking against existing NonbondedForce behavior

* Expand test suite and fix some implementation issues

* Add additional tests using larger reference system

* Add Gaussian test

* Finish test against reference computation

* CPU platform implementation

* Fixes for compilation on some platforms

* Fixes for constant potential with AVX/AVX2

* Test linking CPU PME library to constant potential test directly

* Older SWIG versions don't support Python set to C++ set conversion

* Add user guide entry

* Increase speed of reference test

* Conditional building constant potential CPU test is unreliable

* Debugging

* Miscellaneous fixes and improvements for CI

* Cache charges so solver will not run if system and coordinates have not changed

* Preconditioner flag, stability, and automatic detection improvements

* Add GPU platform-specific constant potential kernel classes

* PME and device-host I/O changes to support constant potential

* Initial common constant potential implementation

* Constant potential fixes:

* Fix preconditioner PME position/charge save/restore logic

* Fix reduction synchronization in constant potential solver kernels

* Add double-float accumulation for conjugate gradient solver when
  double unsupported by hardware

* Improve conditioning of a test system, and make sure particles are in or
out of cutoff for consistency and ease of comparing between platforms

* Reorder guess charges for CG when atom reordering changes positions

* Remove PME queue for now

* Trying to debug optimized direct space derivative kernel

* Remove extraneous debugging lines

* Style updates; just make CPU preconditioner double precision

* Debugging updated optimized direct derivatives kernel for all but OpenCL CPU

* OpenCL CPU implementation of direct space derivatives, and cleanup

* Try to make test even shorter to not time out on CI

* Temporary - Debugging

* Debugging

* Debugging

* Debugging

* Debugging

* Remove debugging code and fix reduction synchronization

* Fix other reductions

* Debugging - are tests hanging or just slow on CI?

* Debugging

* Debugging

* Fix macro for case when double precision is available on hardware

* Remove changes for debugging again

* Try to improve matrix solver cache locality by uploading transpose

* Fixes for atom ordering and periodic images

* Can't rely on reorder listener for cell offset updates

* Test reducing number of contexts and timing for CI

* Debugging

* Remove timing code and revert debugging changes

* Matrix solver and plasma term optimizations

* Reduce CG solver kernel calls and downloads

* Don't read back convergence flag from global memory

* Update PME due to refactoring in master branch

* Faster matrix solver (1st step)

* Faster matrix solver for CUDA

* Faster matrix solver compatibility with non-CUDA platforms

* Matrix solver fixes

* Use warp shuffle reductions when possible

* Attempt to work around intermittent compiler crash in Intel CPU OpenCL

* Optimize CG solver kernel 1

* Rework CG solver so some kernels can use more than 1 block

* Don't run out of shared memory

* Asynchronously download convergence flag while clearing buffers

---------
Co-authored-by: default avatarEvan Pretti <pretti@sh03-17n15.int>
parent 0ad62341
......@@ -32,10 +32,6 @@ CpuNonbondedForce* createCpuNonbondedForceVec4(const CpuNeighborList& neighbors)
CpuNonbondedForce* createCpuNonbondedForceAvx(const CpuNeighborList& neighbors);
CpuNonbondedForce* createCpuNonbondedForceAvx2(const CpuNeighborList& neighbors);
bool isAvx2Supported();
#include <iostream>
CpuNonbondedForce* createCpuNonbondedForceVec(const CpuNeighborList& neighbors) {
if (isAvx2Supported())
return createCpuNonbondedForceAvx2(neighbors);
......
......@@ -69,6 +69,7 @@ CpuPlatform::CpuPlatform() {
registerKernelFactory(CalcPeriodicTorsionForceKernel::Name(), factory);
registerKernelFactory(CalcRBTorsionForceKernel::Name(), factory);
registerKernelFactory(CalcNonbondedForceKernel::Name(), factory);
registerKernelFactory(CalcConstantPotentialForceKernel::Name(), factory);
registerKernelFactory(CalcCustomNonbondedForceKernel::Name(), factory);
registerKernelFactory(CalcCustomManyParticleForceKernel::Name(), factory);
registerKernelFactory(CalcGBSAOBCForceKernel::Name(), factory);
......
......@@ -17,7 +17,18 @@ FILE(GLOB TEST_PROGS "*Test*.cpp")
FOREACH(TEST_PROG ${TEST_PROGS})
GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE)
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
IF(TEST_ROOT MATCHES ".*ConstantPotentialForce.*")
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/plugins/cpupme/include)
IF(OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${TEST_ROOT} OpenMMPME)
ELSE(OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${TEST_ROOT} OpenMMPME_static)
ENDIF(OPENMM_BUILD_SHARED_LIB)
ELSE()
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
ENDIF()
IF (OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET})
ELSE (OPENMM_BUILD_SHARED_LIB)
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2025 Stanford University and the Authors. *
* Authors: Evan Pretti *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "CpuTests.h"
#include "TestConstantPotentialForce.h"
#include "internal/windowsExportPme.h"
extern "C" OPENMM_EXPORT_PME void registerCpuPmeKernelFactories();
void platformInitialize() {
Platform::registerPlatform(&platform);
registerCpuPmeKernelFactories();
}
void runPlatformTests(ConstantPotentialForce::ConstantPotentialMethod method, bool usePreconditioner) {
testEnergyConservation(method, usePreconditioner, 10);
testCompareToReferencePlatform(method, usePreconditioner);
}
......@@ -34,6 +34,7 @@
#include "openmm/System.h"
#include "openmm/common/CommonKernels.h"
#include "openmm/common/CommonCalcNonbondedForce.h"
#include "openmm/common/CommonCalcConstantPotentialForce.h"
#include "openmm/common/ComputeSort.h"
#include "openmm/common/FFT3D.h"
......@@ -102,6 +103,25 @@ private:
CudaContext& cu;
};
/**
* This kernel is invoked by ConstantPotentialForce to calculate the forces acting on the system.
*/
class CudaCalcConstantPotentialForceKernel : public CommonCalcConstantPotentialForceKernel {
public:
CudaCalcConstantPotentialForceKernel(std::string name, const Platform& platform, CudaContext& cu, const System& system) :
CommonCalcConstantPotentialForceKernel(name, platform, cu, system), cu(cu) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the ConstantPotentialForce this kernel will be used for
*/
void initialize(const System& system, const ConstantPotentialForce& force);
private:
CudaContext& cu;
};
/**
* This kernel is invoked by CustomCVForce to calculate the forces acting on the system and the energy of the system.
*/
......
......@@ -289,6 +289,7 @@ CudaContext::CudaContext(const System& system, int deviceIndex, bool useBlocking
compilationDefines["ATAN"] = useDoublePrecision ? "atan" : "atanf";
compilationDefines["ERF"] = useDoublePrecision ? "erf" : "erff";
compilationDefines["ERFC"] = useDoublePrecision ? "erfc" : "erfcf";
compilationDefines["FMA"] = useDoublePrecision ? "fma" : "fmaf";
// Set defines for applying periodic boundary conditions.
......
......@@ -103,6 +103,8 @@ KernelImpl* CudaKernelFactory::createKernelImpl(std::string name, const Platform
return new CommonCalcCustomTorsionForceKernel(name, platform, cu, context.getSystem());
if (name == CalcNonbondedForceKernel::Name())
return new CudaCalcNonbondedForceKernel(name, platform, cu, context.getSystem());
if (name == CalcConstantPotentialForceKernel::Name())
return new CudaCalcConstantPotentialForceKernel(name, platform, cu, context.getSystem());
if (name == CalcCustomNonbondedForceKernel::Name())
return new CommonCalcCustomNonbondedForceKernel(name, platform, cu, context.getSystem());
if (name == CalcGBSAOBCForceKernel::Name())
......
......@@ -54,6 +54,11 @@ using namespace std;
throw OpenMMException(m.str());\
}
static void getCudaPmeParameters(CudaContext& cu, bool& usePmeQueue, bool& useFixedPointChargeSpreading) {
usePmeQueue = (!cu.getPlatformData().disablePmeStream && !cu.getPlatformData().useCpuPme);
useFixedPointChargeSpreading = cu.getUseDoublePrecision() || cu.getPlatformData().deterministicForces;
}
void CudaCalcForcesAndEnergyKernel::initialize(const System& system) {
}
......@@ -88,7 +93,13 @@ double CudaCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, bo
}
void CudaCalcNonbondedForceKernel::initialize(const System& system, const NonbondedForce& force) {
bool usePmeQueue = (!cu.getPlatformData().disablePmeStream && !cu.getPlatformData().useCpuPme);
bool useFixedPointChargeSpreading = cu.getUseDoublePrecision() || cu.getPlatformData().deterministicForces;
bool usePmeQueue, useFixedPointChargeSpreading;
getCudaPmeParameters(cu, usePmeQueue, useFixedPointChargeSpreading);
commonInitialize(system, force, usePmeQueue, false, useFixedPointChargeSpreading, cu.getPlatformData().useCpuPme);
}
void CudaCalcConstantPotentialForceKernel::initialize(const System& system, const ConstantPotentialForce& force) {
bool usePmeQueue, useFixedPointChargeSpreading;
getCudaPmeParameters(cu, usePmeQueue, useFixedPointChargeSpreading);
commonInitialize(system, force, false, useFixedPointChargeSpreading);
}
......@@ -84,6 +84,7 @@ CudaPlatform::CudaPlatform() {
registerKernelFactory(CalcCMAPTorsionForceKernel::Name(), factory);
registerKernelFactory(CalcCustomTorsionForceKernel::Name(), factory);
registerKernelFactory(CalcNonbondedForceKernel::Name(), factory);
registerKernelFactory(CalcConstantPotentialForceKernel::Name(), factory);
registerKernelFactory(CalcCustomNonbondedForceKernel::Name(), factory);
registerKernelFactory(CalcGBSAOBCForceKernel::Name(), factory);
registerKernelFactory(CalcCustomGBForceKernel::Name(), factory);
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2025 Stanford University and the Authors. *
* Authors: Evan Pretti *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "CudaTests.h"
#include "TestConstantPotentialForce.h"
void platformInitialize() {
}
void runPlatformTests(ConstantPotentialForce::ConstantPotentialMethod method, bool usePreconditioner) {
testEnergyConservation(method, usePreconditioner, 10);
testCompareToReferencePlatform(method, usePreconditioner);
}
......@@ -35,6 +35,7 @@
#include "openmm/System.h"
#include "openmm/common/CommonKernels.h"
#include "openmm/common/CommonCalcNonbondedForce.h"
#include "openmm/common/CommonCalcConstantPotentialForce.h"
#include "openmm/common/ComputeSort.h"
#include "openmm/common/FFT3D.h"
......@@ -103,6 +104,25 @@ private:
HipContext& cu;
};
/**
* This kernel is invoked by ConstantPotentialForce to calculate the forces acting on the system.
*/
class HipCalcConstantPotentialForceKernel : public CommonCalcConstantPotentialForceKernel {
public:
HipCalcConstantPotentialForceKernel(std::string name, const Platform& platform, HipContext& cu, const System& system) :
CommonCalcConstantPotentialForceKernel(name, platform, cu, system), cu(cu) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the ConstantPotentialForce this kernel will be used for
*/
void initialize(const System& system, const ConstantPotentialForce& force);
private:
HipContext& cu;
};
/**
* This kernel is invoked by CustomCVForce to calculate the forces acting on the system and the energy of the system.
*/
......
......@@ -284,6 +284,7 @@ HipContext::HipContext(const System& system, int deviceIndex, bool useBlockingSy
compilationDefines["ATAN"] = useDoublePrecision ? "atan" : "atanf";
compilationDefines["ERF"] = useDoublePrecision ? "erf" : "erff";
compilationDefines["ERFC"] = useDoublePrecision ? "erfc" : "erfcf";
compilationDefines["FMA"] = useDoublePrecision ? "fma" : "fmaf";
// Set defines for applying periodic boundary conditions.
......
......@@ -104,6 +104,8 @@ KernelImpl* HipKernelFactory::createKernelImpl(std::string name, const Platform&
return new CommonCalcCustomTorsionForceKernel(name, platform, cu, context.getSystem());
if (name == CalcNonbondedForceKernel::Name())
return new HipCalcNonbondedForceKernel(name, platform, cu, context.getSystem());
if (name == CalcConstantPotentialForceKernel::Name())
return new HipCalcConstantPotentialForceKernel(name, platform, cu, context.getSystem());
if (name == CalcCustomNonbondedForceKernel::Name())
return new CommonCalcCustomNonbondedForceKernel(name, platform, cu, context.getSystem());
if (name == CalcGBSAOBCForceKernel::Name())
......
......@@ -56,6 +56,11 @@ using namespace std;
throw OpenMMException(m.str());\
}
static void getHipPmeParameters(HipContext& cu, bool& usePmeQueue, bool& useFixedPointChargeSpreading) {
usePmeQueue = (!cu.getPlatformData().disablePmeStream && !cu.getPlatformData().useCpuPme);
useFixedPointChargeSpreading = cu.getUseDoublePrecision() || !cu.getSupportsHardwareFloatGlobalAtomicAdd() || cu.getPlatformData().deterministicForces;
}
void HipCalcForcesAndEnergyKernel::initialize(const System& system) {
}
......@@ -90,7 +95,13 @@ double HipCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, boo
}
void HipCalcNonbondedForceKernel::initialize(const System& system, const NonbondedForce& force) {
bool usePmeQueue = (!cu.getPlatformData().disablePmeStream && !cu.getPlatformData().useCpuPme);
bool useFixedPointChargeSpreading = cu.getUseDoublePrecision() || !cu.getSupportsHardwareFloatGlobalAtomicAdd() || cu.getPlatformData().deterministicForces;
bool usePmeQueue, useFixedPointChargeSpreading;
getHipPmeParameters(cu, usePmeQueue, useFixedPointChargeSpreading);
commonInitialize(system, force, usePmeQueue, false, useFixedPointChargeSpreading, cu.getPlatformData().useCpuPme);
}
void HipCalcConstantPotentialForceKernel::initialize(const System& system, const ConstantPotentialForce& force) {
bool usePmeQueue, useFixedPointChargeSpreading;
getHipPmeParameters(cu, usePmeQueue, useFixedPointChargeSpreading);
commonInitialize(system, force, false, useFixedPointChargeSpreading);
}
......@@ -85,6 +85,7 @@ HipPlatform::HipPlatform() {
registerKernelFactory(CalcCMAPTorsionForceKernel::Name(), factory);
registerKernelFactory(CalcCustomTorsionForceKernel::Name(), factory);
registerKernelFactory(CalcNonbondedForceKernel::Name(), factory);
registerKernelFactory(CalcConstantPotentialForceKernel::Name(), factory);
registerKernelFactory(CalcCustomNonbondedForceKernel::Name(), factory);
registerKernelFactory(CalcGBSAOBCForceKernel::Name(), factory);
registerKernelFactory(CalcCustomGBForceKernel::Name(), factory);
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2025 Stanford University and the Authors. *
* Authors: Evan Pretti *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "HipTests.h"
#include "TestConstantPotentialForce.h"
void platformInitialize() {
}
void runPlatformTests(ConstantPotentialForce::ConstantPotentialMethod method, bool usePreconditioner) {
testEnergyConservation(method, usePreconditioner, 10);
testCompareToReferencePlatform(method, usePreconditioner);
}
......@@ -33,6 +33,7 @@
#include "openmm/System.h"
#include "openmm/common/CommonKernels.h"
#include "openmm/common/CommonCalcNonbondedForce.h"
#include "openmm/common/CommonCalcConstantPotentialForce.h"
#include "openmm/common/ComputeArray.h"
#include "openmm/common/ComputeSort.h"
#include "openmm/common/FFT3D.h"
......@@ -102,6 +103,25 @@ private:
OpenCLContext& cl;
};
/**
* This kernel is invoked by ConstantPotentialForce to calculate the forces acting on the system.
*/
class OpenCLCalcConstantPotentialForceKernel : public CommonCalcConstantPotentialForceKernel {
public:
OpenCLCalcConstantPotentialForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) :
CommonCalcConstantPotentialForceKernel(name, platform, cl, system), cl(cl) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the ConstantPotentialForce this kernel will be used for
*/
void initialize(const System& system, const ConstantPotentialForce& force);
private:
OpenCLContext& cl;
};
/**
* This kernel is invoked by CustomCVForce to calculate the forces acting on the system and the energy of the system.
*/
......
......@@ -434,6 +434,7 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
compilationDefines["ATAN"] = "atan";
compilationDefines["ERF"] = "erf";
compilationDefines["ERFC"] = "erfc";
compilationDefines["FMA"] = "fma";
// Set defines for applying periodic boundary conditions.
......
......@@ -101,6 +101,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
return new CommonCalcCustomTorsionForceKernel(name, platform, cl, context.getSystem());
if (name == CalcNonbondedForceKernel::Name())
return new OpenCLCalcNonbondedForceKernel(name, platform, cl, context.getSystem());
if (name == CalcConstantPotentialForceKernel::Name())
return new OpenCLCalcConstantPotentialForceKernel(name, platform, cl, context.getSystem());
if (name == CalcCustomNonbondedForceKernel::Name())
return new CommonCalcCustomNonbondedForceKernel(name, platform, cl, context.getSystem());
if (name == CalcGBSAOBCForceKernel::Name())
......
......@@ -49,6 +49,13 @@
using namespace OpenMM;
using namespace std;
static void getOpenCLPmeParameters(OpenCLContext& cl, bool& usePmeQueue, bool& deviceIsCpu) {
string vendor = cl.getDevice().getInfo<CL_DEVICE_VENDOR>();
bool isNvidia = (vendor.size() >= 6 && vendor.substr(0, 6) == "NVIDIA");
usePmeQueue = (!cl.getPlatformData().disablePmeStream && !cl.getPlatformData().useCpuPme && isNvidia);
deviceIsCpu = (cl.getDevice().getInfo<CL_DEVICE_TYPE>() == CL_DEVICE_TYPE_CPU);
}
void OpenCLCalcForcesAndEnergyKernel::initialize(const System& system) {
}
......@@ -82,9 +89,13 @@ double OpenCLCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context,
}
void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const NonbondedForce& force) {
string vendor = cl.getDevice().getInfo<CL_DEVICE_VENDOR>();
bool isNvidia = (vendor.size() >= 6 && vendor.substr(0, 6) == "NVIDIA");
bool usePmeQueue = (!cl.getPlatformData().disablePmeStream && !cl.getPlatformData().useCpuPme && isNvidia);
bool deviceIsCpu = (cl.getDevice().getInfo<CL_DEVICE_TYPE>() == CL_DEVICE_TYPE_CPU);
bool usePmeQueue, deviceIsCpu;
getOpenCLPmeParameters(cl, usePmeQueue, deviceIsCpu);
commonInitialize(system, force, usePmeQueue, deviceIsCpu, true, cl.getPlatformData().useCpuPme);
}
void OpenCLCalcConstantPotentialForceKernel::initialize(const System& system, const ConstantPotentialForce& force) {
bool usePmeQueue, deviceIsCpu;
getOpenCLPmeParameters(cl, usePmeQueue, deviceIsCpu);
commonInitialize(system, force, deviceIsCpu, true);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment