"examples/benchmark/benchmark.py" did not exist on "2c36e9b34d046f09be4887ff60e7fdac02cf3cdb"
Unverified Commit 01e99e77 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Uniform interface for FFTs (#4911)

* Unified interface for FFTs

* AMOEBA uses unified interface for FFTs

* HIP implementation of common FFT interface
parent a3909c8e
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. * * Portions copyright (c) 2008-2025 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman * * Authors: Mark Friedrichs, Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/common/ComputeContext.h" #include "openmm/common/ComputeContext.h"
#include "openmm/common/ComputeArray.h" #include "openmm/common/ComputeArray.h"
#include "openmm/common/FFT3D.h"
#include "openmm/common/NonbondedUtilities.h" #include "openmm/common/NonbondedUtilities.h"
namespace OpenMM { namespace OpenMM {
...@@ -152,10 +153,6 @@ public: ...@@ -152,10 +153,6 @@ public:
* @param nz the number of grid points along the Z axis * @param nz the number of grid points along the Z axis
*/ */
void getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const; void getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const;
/**
* Compute the FFT.
*/
virtual void computeFFT(bool forward) = 0;
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
...@@ -238,6 +235,7 @@ protected: ...@@ -238,6 +235,7 @@ protected:
ComputeKernel pmeFixedPotentialKernel, pmeInducedPotentialKernel, pmeFixedForceKernel, pmeInducedForceKernel, pmeRecordInducedFieldDipolesKernel; ComputeKernel pmeFixedPotentialKernel, pmeInducedPotentialKernel, pmeFixedForceKernel, pmeInducedForceKernel, pmeRecordInducedFieldDipolesKernel;
ComputeKernel pmeTransformMultipolesKernel, pmeTransformPotentialKernel; ComputeKernel pmeTransformMultipolesKernel, pmeTransformPotentialKernel;
ComputeEvent syncEvent; ComputeEvent syncEvent;
FFT3D* fft;
CommonCalcAmoebaGeneralizedKirkwoodForceKernel* gkKernel; CommonCalcAmoebaGeneralizedKirkwoodForceKernel* gkKernel;
static const int PmeOrder = 5; static const int PmeOrder = 5;
static const int MaxPrevDIISDipoles = 20; static const int MaxPrevDIISDipoles = 20;
...@@ -424,6 +422,7 @@ private: ...@@ -424,6 +422,7 @@ private:
class CommonCalcHippoNonbondedForceKernel : public CalcHippoNonbondedForceKernel { class CommonCalcHippoNonbondedForceKernel : public CalcHippoNonbondedForceKernel {
public: public:
CommonCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, ComputeContext& cc, const System& system); CommonCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, ComputeContext& cc, const System& system);
virtual ~CommonCalcHippoNonbondedForceKernel();
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
...@@ -431,10 +430,6 @@ public: ...@@ -431,10 +430,6 @@ public:
* @param force the HippoNonbondedForce this kernel will be used for * @param force the HippoNonbondedForce this kernel will be used for
*/ */
void initialize(const System& system, const HippoNonbondedForce& force); void initialize(const System& system, const HippoNonbondedForce& force);
/**
* Compute the FFT.
*/
virtual void computeFFT(bool forward, bool dispersion) = 0;
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
...@@ -534,6 +529,8 @@ protected: ...@@ -534,6 +529,8 @@ protected:
ComputeArray lastPositions; ComputeArray lastPositions;
ComputeArray exceptionScales[6]; ComputeArray exceptionScales[6];
ComputeArray exceptionAtoms; ComputeArray exceptionAtoms;
FFT3D* fft;
FFT3D* dfft;
ComputeKernel computeMomentsKernel, recordInducedDipolesKernel, mapTorqueKernel; ComputeKernel computeMomentsKernel, recordInducedDipolesKernel, mapTorqueKernel;
ComputeKernel fixedFieldKernel, fixedFieldExceptionKernel, mutualFieldKernel, mutualFieldExceptionKernel, computeExceptionsKernel; ComputeKernel fixedFieldKernel, fixedFieldExceptionKernel, mutualFieldKernel, mutualFieldExceptionKernel, computeExceptionsKernel;
ComputeKernel pmeSpreadFixedMultipolesKernel, pmeSpreadInducedDipolesKernel, pmeFinishSpreadChargeKernel, pmeConvolutionKernel; ComputeKernel pmeSpreadFixedMultipolesKernel, pmeSpreadInducedDipolesKernel, pmeFinishSpreadChargeKernel, pmeConvolutionKernel;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. * * Portions copyright (c) 2008-2025 Stanford University and the Authors. *
* Authors: Peter Eastman, Mark Friedrichs * * Authors: Peter Eastman, Mark Friedrichs *
* Contributors: * * Contributors: *
* * * *
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "openmm/internal/AmoebaVdwForceImpl.h" #include "openmm/internal/AmoebaVdwForceImpl.h"
#include "openmm/internal/NonbondedForceImpl.h" #include "openmm/internal/NonbondedForceImpl.h"
#include "CudaBondedUtilities.h" #include "CudaBondedUtilities.h"
#include "CudaFFT3D.h"
#include "CudaForceInfo.h" #include "CudaForceInfo.h"
#include "CudaKernelSources.h" #include "CudaKernelSources.h"
#include "SimTKOpenMMRealType.h" #include "SimTKOpenMMRealType.h"
...@@ -79,44 +78,6 @@ static void setPeriodicBoxArgs(ComputeContext& cc, ComputeKernel kernel, int ind ...@@ -79,44 +78,6 @@ static void setPeriodicBoxArgs(ComputeContext& cc, ComputeKernel kernel, int ind
} }
} }
/* -------------------------------------------------------------------------- *
* AmoebaMultipole *
* -------------------------------------------------------------------------- */
CudaCalcAmoebaMultipoleForceKernel::~CudaCalcAmoebaMultipoleForceKernel() {
ContextSelector selector(cc);
if (hasInitializedFFT)
cufftDestroy(fft);
}
void CudaCalcAmoebaMultipoleForceKernel::initialize(const System& system, const AmoebaMultipoleForce& force) {
CommonCalcAmoebaMultipoleForceKernel::initialize(system, force);
if (usePME) {
ContextSelector selector(cc);
cufftResult result = cufftPlan3d(&fft, gridSizeX, gridSizeY, gridSizeZ, cc.getUseDoublePrecision() ? CUFFT_Z2Z : CUFFT_C2C);
if (result != CUFFT_SUCCESS)
throw OpenMMException("Error initializing FFT: "+cc.intToString(result));
hasInitializedFFT = true;
}
}
void CudaCalcAmoebaMultipoleForceKernel::computeFFT(bool forward) {
CudaArray& grid1 = dynamic_cast<CudaContext&>(cc).unwrap(pmeGrid1);
CudaArray& grid2 = dynamic_cast<CudaContext&>(cc).unwrap(pmeGrid2);
if (forward) {
if (cc.getUseDoublePrecision())
cufftExecZ2Z(fft, (double2*) grid1.getDevicePointer(), (double2*) grid2.getDevicePointer(), CUFFT_FORWARD);
else
cufftExecC2C(fft, (float2*) grid1.getDevicePointer(), (float2*) grid2.getDevicePointer(), CUFFT_FORWARD);
}
else {
if (cc.getUseDoublePrecision())
cufftExecZ2Z(fft, (double2*) grid2.getDevicePointer(), (double2*) grid1.getDevicePointer(), CUFFT_INVERSE);
else
cufftExecC2C(fft, (float2*) grid2.getDevicePointer(), (float2*) grid1.getDevicePointer(), CUFFT_INVERSE);
}
}
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* HippoNonbondedForce * * HippoNonbondedForce *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
...@@ -125,12 +86,6 @@ CudaCalcHippoNonbondedForceKernel::~CudaCalcHippoNonbondedForceKernel() { ...@@ -125,12 +86,6 @@ CudaCalcHippoNonbondedForceKernel::~CudaCalcHippoNonbondedForceKernel() {
ContextSelector selector(cc); ContextSelector selector(cc);
if (sort != NULL) if (sort != NULL)
delete sort; delete sort;
if (hasInitializedFFT) {
cufftDestroy(fftForward);
cufftDestroy(fftBackward);
cufftDestroy(dfftForward);
cufftDestroy(dfftBackward);
}
} }
void CudaCalcHippoNonbondedForceKernel::initialize(const System& system, const HippoNonbondedForce& force) { void CudaCalcHippoNonbondedForceKernel::initialize(const System& system, const HippoNonbondedForce& force) {
...@@ -139,38 +94,6 @@ void CudaCalcHippoNonbondedForceKernel::initialize(const System& system, const H ...@@ -139,38 +94,6 @@ void CudaCalcHippoNonbondedForceKernel::initialize(const System& system, const H
ContextSelector selector(cc); ContextSelector selector(cc);
CudaContext& cu = dynamic_cast<CudaContext&>(cc); CudaContext& cu = dynamic_cast<CudaContext&>(cc);
sort = new CudaSort(cu, new SortTrait(), cc.getNumAtoms()); sort = new CudaSort(cu, new SortTrait(), cc.getNumAtoms());
cufftResult result = cufftPlan3d(&fftForward, gridSizeX, gridSizeY, gridSizeZ, cc.getUseDoublePrecision() ? CUFFT_D2Z : CUFFT_R2C);
if (result != CUFFT_SUCCESS)
throw OpenMMException("Error initializing FFT: "+cc.intToString(result));
result = cufftPlan3d(&fftBackward, gridSizeX, gridSizeY, gridSizeZ, cc.getUseDoublePrecision() ? CUFFT_Z2D : CUFFT_C2R);
if (result != CUFFT_SUCCESS)
throw OpenMMException("Error initializing FFT: "+cc.intToString(result));
result = cufftPlan3d(&dfftForward, dispersionGridSizeX, dispersionGridSizeY, dispersionGridSizeZ, cc.getUseDoublePrecision() ? CUFFT_D2Z : CUFFT_R2C);
if (result != CUFFT_SUCCESS)
throw OpenMMException("Error initializing FFT: "+cc.intToString(result));
result = cufftPlan3d(&dfftBackward, dispersionGridSizeX, dispersionGridSizeY, dispersionGridSizeZ, cc.getUseDoublePrecision() ? CUFFT_Z2D : CUFFT_C2R);
if (result != CUFFT_SUCCESS)
throw OpenMMException("Error initializing FFT: "+cc.intToString(result));
hasInitializedFFT = true;
}
}
void CudaCalcHippoNonbondedForceKernel::computeFFT(bool forward, bool dispersion) {
CudaArray& grid1 = dynamic_cast<CudaContext&>(cc).unwrap(pmeGrid1);
CudaArray& grid2 = dynamic_cast<CudaContext&>(cc).unwrap(pmeGrid2);
if (forward) {
cufftHandle fft = dispersion ? dfftForward : fftForward;
if (cc.getUseDoublePrecision())
cufftExecD2Z(fft, (double*) grid1.getDevicePointer(), (double2*) grid2.getDevicePointer());
else
cufftExecR2C(fft, (float*) grid1.getDevicePointer(), (float2*) grid2.getDevicePointer());
}
else {
cufftHandle fft = dispersion ? dfftBackward : fftBackward;
if (cc.getUseDoublePrecision())
cufftExecZ2D(fft, (double2*) grid2.getDevicePointer(), (double*) grid1.getDevicePointer());
else
cufftExecC2R(fft, (float2*) grid2.getDevicePointer(), (float*) grid1.getDevicePointer());
} }
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. * * Portions copyright (c) 2008-2025 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman * * Authors: Mark Friedrichs, Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "CudaNonbondedUtilities.h" #include "CudaNonbondedUtilities.h"
#include "CudaSort.h" #include "CudaSort.h"
#include "AmoebaCommonKernels.h" #include "AmoebaCommonKernels.h"
#include <cufft.h>
namespace OpenMM { namespace OpenMM {
...@@ -44,29 +43,14 @@ namespace OpenMM { ...@@ -44,29 +43,14 @@ namespace OpenMM {
class CudaCalcAmoebaMultipoleForceKernel : public CommonCalcAmoebaMultipoleForceKernel { class CudaCalcAmoebaMultipoleForceKernel : public CommonCalcAmoebaMultipoleForceKernel {
public: public:
CudaCalcAmoebaMultipoleForceKernel(const std::string& name, const Platform& platform, CudaContext& cu, const System& system) : CudaCalcAmoebaMultipoleForceKernel(const std::string& name, const Platform& platform, CudaContext& cu, const System& system) :
CommonCalcAmoebaMultipoleForceKernel(name, platform, cu, system), hasInitializedFFT(false) { CommonCalcAmoebaMultipoleForceKernel(name, platform, cu, system) {
} }
~CudaCalcAmoebaMultipoleForceKernel();
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the AmoebaMultipoleForce this kernel will be used for
*/
void initialize(const System& system, const AmoebaMultipoleForce& force);
/**
* Compute the FFT.
*/
void computeFFT(bool forward);
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
bool useFixedPointChargeSpreading() const { bool useFixedPointChargeSpreading() const {
return cc.getUseDoublePrecision(); return cc.getUseDoublePrecision();
} }
private:
bool hasInitializedFFT;
cufftHandle fft;
}; };
/** /**
...@@ -75,7 +59,7 @@ private: ...@@ -75,7 +59,7 @@ private:
class CudaCalcHippoNonbondedForceKernel : public CommonCalcHippoNonbondedForceKernel { class CudaCalcHippoNonbondedForceKernel : public CommonCalcHippoNonbondedForceKernel {
public: public:
CudaCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, CudaContext& cu, const System& system) : CudaCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, CudaContext& cu, const System& system) :
CommonCalcHippoNonbondedForceKernel(name, platform, cu, system), sort(NULL), hasInitializedFFT(false) { CommonCalcHippoNonbondedForceKernel(name, platform, cu, system), sort(NULL) {
} }
~CudaCalcHippoNonbondedForceKernel(); ~CudaCalcHippoNonbondedForceKernel();
/** /**
...@@ -85,10 +69,6 @@ public: ...@@ -85,10 +69,6 @@ public:
* @param force the HippoNonbondedForce this kernel will be used for * @param force the HippoNonbondedForce this kernel will be used for
*/ */
void initialize(const System& system, const HippoNonbondedForce& force); void initialize(const System& system, const HippoNonbondedForce& force);
/**
* Compute the FFT.
*/
void computeFFT(bool forward, bool dispersion);
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
...@@ -110,9 +90,7 @@ private: ...@@ -110,9 +90,7 @@ private:
const char* getMaxValue() const {return "make_int2(2147483647, 2147483647)";} const char* getMaxValue() const {return "make_int2(2147483647, 2147483647)";}
const char* getSortKey() const {return "value.y";} const char* getSortKey() const {return "value.y";}
}; };
bool hasInitializedFFT;
CudaSort* sort; CudaSort* sort;
cufftHandle fftForward, fftBackward, dfftForward, dfftBackward;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "openmm/internal/AmoebaVdwForceImpl.h" #include "openmm/internal/AmoebaVdwForceImpl.h"
#include "openmm/internal/NonbondedForceImpl.h" #include "openmm/internal/NonbondedForceImpl.h"
#include "HipBondedUtilities.h" #include "HipBondedUtilities.h"
#include "HipFFT3D.h"
#include "HipForceInfo.h" #include "HipForceInfo.h"
#include "HipKernelSources.h" #include "HipKernelSources.h"
#include "SimTKOpenMMRealType.h" #include "SimTKOpenMMRealType.h"
...@@ -53,30 +52,6 @@ ...@@ -53,30 +52,6 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
/* -------------------------------------------------------------------------- *
* AmoebaMultipole *
* -------------------------------------------------------------------------- */
HipCalcAmoebaMultipoleForceKernel::~HipCalcAmoebaMultipoleForceKernel() {
ContextSelector selector(cc);
if (fft != NULL)
delete fft;
}
void HipCalcAmoebaMultipoleForceKernel::initialize(const System& system, const AmoebaMultipoleForce& force) {
CommonCalcAmoebaMultipoleForceKernel::initialize(system, force);
if (usePME) {
ContextSelector selector(cc);
HipArray& grid1 = cu.unwrap(pmeGrid1);
HipArray& grid2 = cu.unwrap(pmeGrid2);
fft = new HipFFT3D(cu, gridSizeX, gridSizeY, gridSizeZ, false, cu.getCurrentStream(), grid1, grid2);
}
}
void HipCalcAmoebaMultipoleForceKernel::computeFFT(bool forward) {
fft->execFFT(forward);
}
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* HippoNonbondedForce * * HippoNonbondedForce *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
...@@ -85,10 +60,6 @@ HipCalcHippoNonbondedForceKernel::~HipCalcHippoNonbondedForceKernel() { ...@@ -85,10 +60,6 @@ HipCalcHippoNonbondedForceKernel::~HipCalcHippoNonbondedForceKernel() {
ContextSelector selector(cc); ContextSelector selector(cc);
if (sort != NULL) if (sort != NULL)
delete sort; delete sort;
if (fft != NULL)
delete fft;
if (dfft != NULL)
delete dfft;
} }
void HipCalcHippoNonbondedForceKernel::initialize(const System& system, const HippoNonbondedForce& force) { void HipCalcHippoNonbondedForceKernel::initialize(const System& system, const HippoNonbondedForce& force) {
...@@ -96,19 +67,6 @@ void HipCalcHippoNonbondedForceKernel::initialize(const System& system, const Hi ...@@ -96,19 +67,6 @@ void HipCalcHippoNonbondedForceKernel::initialize(const System& system, const Hi
if (usePME) { if (usePME) {
ContextSelector selector(cc); ContextSelector selector(cc);
sort = new HipSort(cu, new SortTrait(), cc.getNumAtoms()); sort = new HipSort(cu, new SortTrait(), cc.getNumAtoms());
HipArray& grid1 = cu.unwrap(pmeGrid1);
HipArray& grid2 = cu.unwrap(pmeGrid2);
fft = new HipFFT3D(cu, gridSizeX, gridSizeY, gridSizeZ, true, cu.getCurrentStream(), grid1, grid2);
dfft = new HipFFT3D(cu, dispersionGridSizeX, dispersionGridSizeY, dispersionGridSizeZ, true, cu.getCurrentStream(), grid1, grid2);
}
}
void HipCalcHippoNonbondedForceKernel::computeFFT(bool forward, bool dispersion) {
if (dispersion) {
dfft->execFFT(forward);
}
else {
fft->execFFT(forward);
} }
} }
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "HipContext.h" #include "HipContext.h"
#include "HipNonbondedUtilities.h" #include "HipNonbondedUtilities.h"
#include "HipSort.h" #include "HipSort.h"
#include "HipFFT3D.h"
#include "AmoebaCommonKernels.h" #include "AmoebaCommonKernels.h"
namespace OpenMM { namespace OpenMM {
...@@ -45,20 +44,8 @@ namespace OpenMM { ...@@ -45,20 +44,8 @@ namespace OpenMM {
class HipCalcAmoebaMultipoleForceKernel : public CommonCalcAmoebaMultipoleForceKernel { class HipCalcAmoebaMultipoleForceKernel : public CommonCalcAmoebaMultipoleForceKernel {
public: public:
HipCalcAmoebaMultipoleForceKernel(const std::string& name, const Platform& platform, HipContext& cu, const System& system) : HipCalcAmoebaMultipoleForceKernel(const std::string& name, const Platform& platform, HipContext& cu, const System& system) :
CommonCalcAmoebaMultipoleForceKernel(name, platform, cu, system), cu(cu), fft(NULL) { CommonCalcAmoebaMultipoleForceKernel(name, platform, cu, system), cu(cu) {
} }
~HipCalcAmoebaMultipoleForceKernel();
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the AmoebaMultipoleForce this kernel will be used for
*/
void initialize(const System& system, const AmoebaMultipoleForce& force);
/**
* Compute the FFT.
*/
void computeFFT(bool forward);
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
...@@ -67,7 +54,6 @@ public: ...@@ -67,7 +54,6 @@ public:
} }
private: private:
HipContext& cu; HipContext& cu;
HipFFT3D* fft;
}; };
/** /**
...@@ -76,7 +62,7 @@ private: ...@@ -76,7 +62,7 @@ private:
class HipCalcHippoNonbondedForceKernel : public CommonCalcHippoNonbondedForceKernel { class HipCalcHippoNonbondedForceKernel : public CommonCalcHippoNonbondedForceKernel {
public: public:
HipCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, HipContext& cu, const System& system) : HipCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, HipContext& cu, const System& system) :
CommonCalcHippoNonbondedForceKernel(name, platform, cu, system), cu(cu), sort(NULL), fft(NULL), dfft(NULL) { CommonCalcHippoNonbondedForceKernel(name, platform, cu, system), cu(cu), sort(NULL) {
} }
~HipCalcHippoNonbondedForceKernel(); ~HipCalcHippoNonbondedForceKernel();
/** /**
...@@ -86,10 +72,6 @@ public: ...@@ -86,10 +72,6 @@ public:
* @param force the HippoNonbondedForce this kernel will be used for * @param force the HippoNonbondedForce this kernel will be used for
*/ */
void initialize(const System& system, const HippoNonbondedForce& force); void initialize(const System& system, const HippoNonbondedForce& force);
/**
* Compute the FFT.
*/
void computeFFT(bool forward, bool dispersion);
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
...@@ -113,8 +95,6 @@ private: ...@@ -113,8 +95,6 @@ private:
}; };
HipContext& cu; HipContext& cu;
HipSort* sort; HipSort* sort;
HipFFT3D* fft;
HipFFT3D* dfft;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -29,30 +29,6 @@ ...@@ -29,30 +29,6 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
/* -------------------------------------------------------------------------- *
* AmoebaMultipole *
* -------------------------------------------------------------------------- */
OpenCLCalcAmoebaMultipoleForceKernel::~OpenCLCalcAmoebaMultipoleForceKernel() {
if (fft != NULL)
delete fft;
}
void OpenCLCalcAmoebaMultipoleForceKernel::initialize(const System& system, const AmoebaMultipoleForce& force) {
CommonCalcAmoebaMultipoleForceKernel::initialize(system, force);
if (usePME)
fft = new OpenCLFFT3D(dynamic_cast<OpenCLContext&>(cc), gridSizeX, gridSizeY, gridSizeZ, false);
}
void OpenCLCalcAmoebaMultipoleForceKernel::computeFFT(bool forward) {
OpenCLArray& grid1 = dynamic_cast<OpenCLContext&>(cc).unwrap(pmeGrid1);
OpenCLArray& grid2 = dynamic_cast<OpenCLContext&>(cc).unwrap(pmeGrid2);
if (forward)
fft->execFFT(grid1, grid2, true);
else
fft->execFFT(grid2, grid1, false);
}
/* -------------------------------------------------------------------------- * /* -------------------------------------------------------------------------- *
* HippoNonbondedForce * * HippoNonbondedForce *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
...@@ -60,10 +36,6 @@ void OpenCLCalcAmoebaMultipoleForceKernel::computeFFT(bool forward) { ...@@ -60,10 +36,6 @@ void OpenCLCalcAmoebaMultipoleForceKernel::computeFFT(bool forward) {
OpenCLCalcHippoNonbondedForceKernel::~OpenCLCalcHippoNonbondedForceKernel() { OpenCLCalcHippoNonbondedForceKernel::~OpenCLCalcHippoNonbondedForceKernel() {
if (sort != NULL) if (sort != NULL)
delete sort; delete sort;
if (hasInitializedFFT) {
delete fftForward;
delete dfftForward;
}
} }
void OpenCLCalcHippoNonbondedForceKernel::initialize(const System& system, const HippoNonbondedForce& force) { void OpenCLCalcHippoNonbondedForceKernel::initialize(const System& system, const HippoNonbondedForce& force) {
...@@ -71,22 +43,9 @@ void OpenCLCalcHippoNonbondedForceKernel::initialize(const System& system, const ...@@ -71,22 +43,9 @@ void OpenCLCalcHippoNonbondedForceKernel::initialize(const System& system, const
if (usePME) { if (usePME) {
OpenCLContext& cl = dynamic_cast<OpenCLContext&>(cc); OpenCLContext& cl = dynamic_cast<OpenCLContext&>(cc);
sort = new OpenCLSort(cl, new SortTrait(), cc.getNumAtoms()); sort = new OpenCLSort(cl, new SortTrait(), cc.getNumAtoms());
fftForward = new OpenCLFFT3D(cl, gridSizeX, gridSizeY, gridSizeZ, true);
dfftForward = new OpenCLFFT3D(cl, dispersionGridSizeX, dispersionGridSizeY, dispersionGridSizeZ, true);
hasInitializedFFT = true;
} }
} }
void OpenCLCalcHippoNonbondedForceKernel::computeFFT(bool forward, bool dispersion) {
OpenCLArray& grid1 = dynamic_cast<OpenCLContext&>(cc).unwrap(pmeGrid1);
OpenCLArray& grid2 = dynamic_cast<OpenCLContext&>(cc).unwrap(pmeGrid2);
OpenCLFFT3D* fft = (dispersion ? dfftForward : fftForward);
if (forward)
fft->execFFT(grid1, grid2, true);
else
fft->execFFT(grid2, grid1, false);
}
void OpenCLCalcHippoNonbondedForceKernel::sortGridIndex() { void OpenCLCalcHippoNonbondedForceKernel::sortGridIndex() {
sort->sort(dynamic_cast<OpenCLContext&>(cc).unwrap(pmeAtomGridIndex)); sort->sort(dynamic_cast<OpenCLContext&>(cc).unwrap(pmeAtomGridIndex));
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2021 Stanford University and the Authors. * * Portions copyright (c) 2008-2025 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman * * Authors: Mark Friedrichs, Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "openmm/System.h" #include "openmm/System.h"
#include "AmoebaCommonKernels.h" #include "AmoebaCommonKernels.h"
#include "OpenCLContext.h" #include "OpenCLContext.h"
#include "OpenCLFFT3D.h"
#include "OpenCLSort.h" #include "OpenCLSort.h"
namespace OpenMM { namespace OpenMM {
...@@ -43,28 +42,14 @@ namespace OpenMM { ...@@ -43,28 +42,14 @@ namespace OpenMM {
class OpenCLCalcAmoebaMultipoleForceKernel : public CommonCalcAmoebaMultipoleForceKernel { class OpenCLCalcAmoebaMultipoleForceKernel : public CommonCalcAmoebaMultipoleForceKernel {
public: public:
OpenCLCalcAmoebaMultipoleForceKernel(const std::string& name, const Platform& platform, OpenCLContext& cl, const System& system) : OpenCLCalcAmoebaMultipoleForceKernel(const std::string& name, const Platform& platform, OpenCLContext& cl, const System& system) :
CommonCalcAmoebaMultipoleForceKernel(name, platform, cl, system), fft(NULL) { CommonCalcAmoebaMultipoleForceKernel(name, platform, cl, system) {
} }
~OpenCLCalcAmoebaMultipoleForceKernel();
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param force the AmoebaMultipoleForce this kernel will be used for
*/
void initialize(const System& system, const AmoebaMultipoleForce& force);
/**
* Compute the FFT.
*/
void computeFFT(bool forward);
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
bool useFixedPointChargeSpreading() const { bool useFixedPointChargeSpreading() const {
return true; return true;
} }
private:
OpenCLFFT3D* fft;
}; };
...@@ -74,7 +59,7 @@ private: ...@@ -74,7 +59,7 @@ private:
class OpenCLCalcHippoNonbondedForceKernel : public CommonCalcHippoNonbondedForceKernel { class OpenCLCalcHippoNonbondedForceKernel : public CommonCalcHippoNonbondedForceKernel {
public: public:
OpenCLCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, OpenCLContext& cl, const System& system) : OpenCLCalcHippoNonbondedForceKernel(const std::string& name, const Platform& platform, OpenCLContext& cl, const System& system) :
CommonCalcHippoNonbondedForceKernel(name, platform, cl, system), sort(NULL), hasInitializedFFT(false) { CommonCalcHippoNonbondedForceKernel(name, platform, cl, system), sort(NULL) {
} }
~OpenCLCalcHippoNonbondedForceKernel(); ~OpenCLCalcHippoNonbondedForceKernel();
/** /**
...@@ -84,10 +69,6 @@ public: ...@@ -84,10 +69,6 @@ public:
* @param force the HippoNonbondedForce this kernel will be used for * @param force the HippoNonbondedForce this kernel will be used for
*/ */
void initialize(const System& system, const HippoNonbondedForce& force); void initialize(const System& system, const HippoNonbondedForce& force);
/**
* Compute the FFT.
*/
void computeFFT(bool forward, bool dispersion);
/** /**
* Get whether charge spreading should be done in fixed point. * Get whether charge spreading should be done in fixed point.
*/ */
...@@ -109,9 +90,7 @@ private: ...@@ -109,9 +90,7 @@ private:
const char* getMaxValue() const {return "make_int2(2147483647, 2147483647)";} const char* getMaxValue() const {return "make_int2(2147483647, 2147483647)";}
const char* getSortKey() const {return "value.y";} const char* getSortKey() const {return "value.y";}
}; };
bool hasInitializedFFT;
OpenCLSort* sort; OpenCLSort* sort;
OpenCLFFT3D *fftForward, *fftBackward, *dfftForward, *dfftBackward;
}; };
} // namespace OpenMM } // namespace OpenMM
......
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