Unverified Commit e7d78e5f authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Merge pull request #4645 from peastman/customcpp

Prevent deadlock using CustomCPPForceImpl with multiple GPUs
parents 3b8df952 da106c00
...@@ -8245,15 +8245,29 @@ void CommonCalcCustomCPPForceKernel::initialize(const System& system, CustomCPPF ...@@ -8245,15 +8245,29 @@ void CommonCalcCustomCPPForceKernel::initialize(const System& system, CustomCPPF
addForcesKernel->addArg(cc.getLongForceBuffer()); addForcesKernel->addArg(cc.getLongForceBuffer());
addForcesKernel->addArg(cc.getAtomIndexArray()); addForcesKernel->addArg(cc.getAtomIndexArray());
forceGroupFlag = (1<<force.getOwner().getForceGroup()); forceGroupFlag = (1<<force.getOwner().getForceGroup());
if (cc.getNumContexts() == 1) {
cc.addPreComputation(new StartCalculationPreComputation(*this)); cc.addPreComputation(new StartCalculationPreComputation(*this));
cc.addPostComputation(new AddForcesPostComputation(*this)); cc.addPostComputation(new AddForcesPostComputation(*this));
}
} }
double CommonCalcCustomCPPForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double CommonCalcCustomCPPForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (cc.getNumContexts() == 1) {
// This method does nothing. The actual calculation is started by the pre-computation, continued on // This method does nothing. The actual calculation is started by the pre-computation, continued on
// the worker thread, and finished by the post-computation. // the worker thread, and finished by the post-computation.
return 0; return 0;
}
// When using multiple GPUs, this method is itself called from the worker thread.
// Submitting additional tasks and waiting for them to complete would lead to
// a deadlock.
if (cc.getContextIndex() != 0)
return 0.0;
contextImpl.getPositions(positionsVec);
executeOnWorkerThread(includeForces);
return addForces(includeForces, includeEnergy, -1);
} }
void CommonCalcCustomCPPForceKernel::beginComputation(bool includeForces, bool includeEnergy, int groups) { void CommonCalcCustomCPPForceKernel::beginComputation(bool includeForces, bool includeEnergy, int groups) {
...@@ -8290,6 +8304,7 @@ double CommonCalcCustomCPPForceKernel::addForces(bool includeForces, bool includ ...@@ -8290,6 +8304,7 @@ double CommonCalcCustomCPPForceKernel::addForces(bool includeForces, bool includ
// Wait until executeOnWorkerThread() is finished. // Wait until executeOnWorkerThread() is finished.
if (cc.getNumContexts() == 1)
cc.getWorkThread().flush(); cc.getWorkThread().flush();
// Add in the forces. // Add in the forces.
......
...@@ -33,5 +33,7 @@ ...@@ -33,5 +33,7 @@
#include "TestCustomCPPForce.h" #include "TestCustomCPPForce.h"
void runPlatformTests() { void runPlatformTests() {
platform.setPropertyDefaultValue("DeviceIndex", "0,0");
testForce();
} }
...@@ -33,4 +33,6 @@ ...@@ -33,4 +33,6 @@
#include "TestCustomCPPForce.h" #include "TestCustomCPPForce.h"
void runPlatformTests() { void runPlatformTests() {
platform.setPropertyDefaultValue("DeviceIndex", "0,0");
testForce();
} }
...@@ -33,5 +33,7 @@ ...@@ -33,5 +33,7 @@
#include "TestCustomCPPForce.h" #include "TestCustomCPPForce.h"
void runPlatformTests() { void runPlatformTests() {
platform.setPropertyDefaultValue("DeviceIndex", "0,0");
testForce();
} }
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