"vscode:/vscode.git/clone" did not exist on "96b61389de9b3bfa9d9b0fc7bf769fc093c39453"
Commit b25a17ae authored by Mark Friedrichs's avatar Mark Friedrichs
Browse files

Initial unit tests for StandardMMForceField pass

parent 4492ca24
......@@ -59,8 +59,9 @@ BrookBonded::BrookBonded( ){
// ---------------------------------------------------------------------------------------
_numberOfAtoms = 0;
_ljScale = 1.0;
_coulombFactor = 332.0;
_ljScale = (BrookOpenMMFloat) 0.83333333;
//_coulombFactor = 332.0;
_coulombFactor = (BrookOpenMMFloat) 138.935485;
_atomIndicesStream = NULL;
_chargeStream = NULL;
......@@ -354,6 +355,24 @@ BrookFloatStreamInternal* BrookBonded::getAtomIndicesStream( void ) const {
return _atomIndicesStream;
}
/**
* Get bonded charge stream
*
* @return charge stream
*
*/
BrookFloatStreamInternal* BrookBonded::getChargeStream( void ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookBonded::getChargeStream";
// ---------------------------------------------------------------------------------------
return _chargeStream;
}
/**
* Get array of bonded parameter streams
*
......@@ -593,8 +612,7 @@ int BrookBonded::matchBond( int i, int j, int nbondeds, int *atoms, int *flag ){
*flag = 1;
return n;
}
}
else if( ( i == ATOMS(n, 1) && j == ATOMS(n, 2) ) ||( i == ATOMS(n, 2) && j == ATOMS(n, 1) ) ){
} else if( ( i == ATOMS(n, 1) && j == ATOMS(n, 2) ) ||( i == ATOMS(n, 2) && j == ATOMS(n, 1) ) ){
*flag = 1;
return n;
}
......@@ -880,7 +898,7 @@ int BrookBonded::addBonds( int *nbondeds, int *atoms, float *params[], const vec
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookBonded::addBonds";
static const int debug = 0;
static const int debug = 1;
// ---------------------------------------------------------------------------------------
......@@ -899,8 +917,17 @@ int BrookBonded::addBonds( int *nbondeds, int *atoms, float *params[], const vec
int i = atomsIndices[index++];
int j = atomsIndices[index++];
// insure i < j
if( i > j ){
int k = i;
i = j;
j = k;
}
int flag;
int ibonded = matchBond( i, j, *nbondeds, atoms, &flag );
int saveIbond = ibonded;
if( ibonded < 0 ){
ibonded = *nbondeds;
ATOMS( ibonded, 0 ) = i;
......@@ -918,7 +945,7 @@ int BrookBonded::addBonds( int *nbondeds, int *atoms, float *params[], const vec
}
if( debug && getLog() ){
(void) fprintf( getLog(), " %d [%d %d ] flag=%d %.3e %.3e\n", ibonded, i, j, flag,
(void) fprintf( getLog(), " %d (%5d) [%6d %6d ] flag=%2d %.3e %.3e\n", ibonded, saveIbond, i, j, flag,
bndParameters[0], bndParameters[1] );
}
}
......@@ -951,9 +978,9 @@ int BrookBonded::addPairs( int *nbondeds, int *atoms, BrookOpenMMFloat* params[]
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookBonded::BrookBonded";
static const std::string methodName = "BrookBonded::addPairs";
static const double oneSixth = 1.0/6.0;
static const int debug = 0;
static const int debug = 1;
// ---------------------------------------------------------------------------------------
......@@ -980,13 +1007,16 @@ int BrookBonded::addPairs( int *nbondeds, int *atoms, BrookOpenMMFloat* params[]
vector<double> iParameters = nonbondedParameters[i];
vector<double> jParameters = nonbondedParameters[j];
double c6 = iParameters[0] + jParameters[0];
double c12 = lj14Scale*(iParameters[1] * jParameters[1]);
double c6 = 0.5*(iParameters[1] + jParameters[1]);
//double c12 = lj14Scale*(iParameters[2] * jParameters[2]);
double c12 = 2.0*(iParameters[2] * jParameters[2]);
double sig, eps;
if( c12 != 0.0 ){
eps = c6*c6/c12;
sig = pow( c12/c6, oneSixth );
//eps = c6*c6/c12;
//sig = pow( c12/c6, oneSixth );
eps = c12;
sig = c6;
} else {
eps = 0.0;
sig = 1.0;
......@@ -997,11 +1027,11 @@ int BrookBonded::addPairs( int *nbondeds, int *atoms, BrookOpenMMFloat* params[]
// a little wasteful, but ...
charges[i] = (BrookOpenMMFloat) iParameters[2];
charges[j] = (BrookOpenMMFloat) jParameters[2];
charges[i] = (BrookOpenMMFloat) iParameters[0];
charges[j] = (BrookOpenMMFloat) jParameters[0];
if( debug ){
(void) fprintf( getLog(), "\n %d [%d %d ] %.3e %.3e", ibonded, i, j, sig, eps );
(void) fprintf( getLog(), " %d [%d %d ] %.3e %.3e\n", ibonded, i, j, sig, eps );
}
}
......@@ -1037,22 +1067,32 @@ int BrookBonded::loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookP
int atomStreamSize = brookPlatform.getStreamSize( getNumberOfAtoms(), atomStreamWidth, NULL );
_inverseMapStreamWidth = atomStreamWidth;
// ---------------------------------------------------------------------------------------
// allocate temp memory
float4** invmaps = new float4*[getMaxInverseMapStreamCount()];
float* block = new float[4*getMaxInverseMapStreamCount()*atomStreamSize];
//memset( block, 0, 4*getMaxInverseMapStreamCount()*atomStreamSize*sizeof( float ) );
float* blockPtr = block;
for( int ii = 0; ii < getMaxInverseMapStreamCount(); ii++ ){
invmaps[ii] = (float4*) block;
block += 4*atomStreamSize;
invmaps[ii] = (float4*) blockPtr;
blockPtr += 4*atomStreamSize;
}
int* counts = new int[atomStreamSize];
// ---------------------------------------------------------------------------------------
// get inverse maps and load into streams
// create streams
// done independently from loading since for test cases some stream counts == 0, but kernels expect stream to
// have been created even though unused
// load streams -- initialize all streams even if unused since gather methods will still pick up
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
for( int jj = 0; jj < getMaxInverseMapStreamCount(ii); jj++ ){
_inverseStreamMaps[ii][jj] = new BrookFloatStreamInternal( BrookCommon::BondedInverseMapStreams, atomStreamSize,
......@@ -1060,28 +1100,60 @@ int BrookBonded::loadInvMaps( int nbondeds, int natoms, int *atoms, const BrookP
}
}
if( getLog() ){
(void) fprintf( getLog(), "%s force stream strms=%d nbondeds=%d max counts=[%d %d %d %d] strSz&Wd=%d %d\n", methodName.c_str(), getNumberOfForceStreams(),
nbondeds, getMaxInverseMapStreamCount(0), getMaxInverseMapStreamCount(1), getMaxInverseMapStreamCount(2), getMaxInverseMapStreamCount(3),
atomStreamSize, atomStreamWidth );
(void) fflush( getLog() );
}
// load data
for( int ii = 0; ii < getNumberOfForceStreams(); ii++ ){
gpuCalcInvMap( ii, 4, nbondeds, natoms, atoms, getInverseMapStreamCount( ii ), counts, invmaps, &(_inverseMapStreamCount[ii]) );
//gpuPrintInvMaps( _inverseMapStreamCount[ii], natoms, counts, invmaps, getLog() );
validateInverseMapStreamCount( ii, _inverseMapStreamCount[ii] );
for( int jj = 0; jj < _inverseMapStreamCount[ii]; jj++ ){
_inverseStreamMaps[ii][jj]->loadFromArray( invmaps[jj] );
(void) fprintf( getLog(), "%s inverseMap stream strms=%d count=%d index=%d %d InverseMapStreamCount[ii]=%d max=%d\n",
methodName.c_str(), getNumberOfForceStreams(), _inverseMapStreamCount[ii], ii, jj,
getInverseMapStreamCount( ii ), getMaxInverseMapStreamCount( ii ) );
/*
for( int kk = 0; kk < atomStreamSize; kk++ ){
(void) fprintf( getLog(), "%8d [ %.1f %.1f %.1f %.1f]\n", kk, invmaps[jj][kk].x, invmaps[jj][kk].y, invmaps[jj][kk].z, invmaps[jj][kk].w );
}
*/
}
// for small systems, must all initialize inverse maps to negative values in order to
// keep invalid entries from being included in forces
if( _inverseMapStreamCount[ii] < getMaxInverseMapStreamCount( ii ) ){
for( int jj = 0; jj < 4*atomStreamSize; jj++ ){
block[jj] = -1.0f;
}
for( int jj = _inverseMapStreamCount[ii]; jj < getMaxInverseMapStreamCount( ii ); jj++ ){
_inverseStreamMaps[ii][jj]->loadFromArray( invmaps[0] );
}
}
}
// diagnostics
if( getLog() ){
(void) fprintf( getLog(), "%s done\n", methodName.c_str() );
(void) fflush( getLog() );
//gpuPrintInvMaps( bp->nimaps, natoms, counts, invmaps, gpu->log );
}
// free memory
delete counts;
delete invmaps[0];
delete invmaps;
delete[] counts;
delete[] invmaps[0];
delete[] invmaps;
return DefaultReturnValue;
}
......@@ -1191,7 +1263,13 @@ int BrookBonded::setup( int numberOfAtoms,
for( int ii = 0; ii < getNumberOfParameterStreams(); ii++ ){
params[ii] = new BrookOpenMMFloat[4*maxBonds];
}
BrookOpenMMFloat* charges = new BrookOpenMMFloat[numberOfAtoms];
// ---------------------------------------------------------------------------------------
// build streams
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() );
int atomStreamWidth = brookStreamFactory.getDefaultAtomStreamWidth();
// Initialize all atom indices to -1 to indicate empty slots
// All parameters must be initialized to values that will
......@@ -1222,6 +1300,19 @@ int BrookBonded::setup( int numberOfAtoms,
addAngles( &nbondeds, atoms, params, angleIndices, angleParameters );
addBonds( &nbondeds, atoms, params, bondIndices, bondParameters );
// ---------------------------------------------------------------------------------------
// charge stream
_chargeStream = new BrookFloatStreamInternal( BrookCommon::BondedChargeStream, numberOfAtoms, atomStreamWidth,
BrookStreamInternal::Float, dangleValue );
BrookOpenMMFloat* charges = new BrookOpenMMFloat[_chargeStream->getStreamSize()];
memset( charges, 0, _chargeStream->getStreamSize()*sizeof( BrookOpenMMFloat ) );
// ---------------------------------------------------------------------------------------
//(void) fprintf( getLog(), "%s Post addBonds atoms=%d number of bonds=%d maxBonds=%d\n", methodName.c_str(), numberOfAtoms, nbondeds, maxBonds );
addPairs( &nbondeds, atoms, params, charges, bonded14Indices, nonbondedParameters, lj14Scale, coulombScale );
// check that number of bonds not too large for memory allocated
......@@ -1235,25 +1326,42 @@ int BrookBonded::setup( int numberOfAtoms,
(void) fflush( getLog() );
}
const BrookStreamFactory& brookStreamFactory = dynamic_cast<const BrookStreamFactory&> (brookPlatform.getDefaultStreamFactory() );
int atomStreamWidth = brookStreamFactory.getDefaultAtomStreamWidth();
// ---------------------------------------------------------------------------------------
// build streams
// atom indices stream
_atomIndicesStream = new BrookFloatStreamInternal( BrookCommon::BondedAtomIndicesStream, nbondeds, atomStreamWidth,
BrookStreamInternal::Float4, dangleValue );
_atomIndicesStream->loadFromArray( atoms, BrookStreamInternal::Integer );
_chargeStream = new BrookFloatStreamInternal( BrookCommon::BondedChargeStream, numberOfAtoms, atomStreamWidth,
BrookStreamInternal::Float, dangleValue );
int* buffer = new int[4*_atomIndicesStream->getStreamSize()];
memset( buffer, 0, sizeof( int )*4*_atomIndicesStream->getStreamSize() );
int index = 0;
for( int ii = 0; ii < nbondeds; ii++ ){
for( int jj = 0; jj < 4; jj++ ){
buffer[index++] = ATOMS( ii, jj );
//(void) fprintf( getLog(), "%s atomIndices %d %d %d buffer=%d atoms=%d\n", methodName.c_str(), ii, jj, index, buffer[index-1], ATOMS( ii, jj ) );
}
}
_atomIndicesStream->loadFromArray( buffer, BrookStreamInternal::Integer );
delete[] buffer;
// ---------------------------------------------------------------------------------------
_chargeStream->loadFromArray( charges );
// ---------------------------------------------------------------------------------------
// bonded parameters
for( int ii = 0; ii < getNumberOfParameterStreams(); ii++ ){
_bondedParameters[ii] = new BrookFloatStreamInternal( BrookCommon::BondedParametersStream, nbondeds, atomStreamWidth,
BrookStreamInternal::Float4, dangleValue );
_bondedParameters[ii]->loadFromArray( params[ii] );
}
// ---------------------------------------------------------------------------------------
// debug stuff
if( 1 && getLog() ){
......@@ -1300,19 +1408,22 @@ int BrookBonded::setup( int numberOfAtoms,
loadInvMaps( nbondeds, getNumberOfAtoms(), atoms, brookPlatform );
// ---------------------------------------------------------------------------------------
// free memory
for( int ii = 0; ii < getNumberOfParameterStreams(); ii++ ){
delete[] params[ii];
}
delete[] params;
delete[] atoms;
delete[] charges;
// set the fudge factors
_ljScale = (BrookOpenMMFloat) lj14Scale;
_coulombFactor = (BrookOpenMMFloat) coulombScale;
//_ljScale = (BrookOpenMMFloat) lj14Scale;
//_coulombFactor = (BrookOpenMMFloat) coulombScale;
// initialize output streams
......
......@@ -186,6 +186,15 @@ class BrookBonded : public BrookCommon {
BrookFloatStreamInternal* getAtomIndicesStream( void ) const;
/**
* Get bonded charge stream
*
* @return charge stream
*
*/
BrookFloatStreamInternal* getChargeStream( void ) const;
/**
* Get array of bonded parameter streams
*
......
......@@ -223,19 +223,109 @@ void BrookCalcStandardMMForceFieldKernel::executeForces( const Stream& positions
static const int K_Stream = 2;
static const int L_Stream = 3;
static const int PrintOn = 0;
static const float4 dummyParameters( 0.0, 0.0, 0.0, 0.0 );
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
// bonded
// ---------------------------------------------------------------------------------------
const BrookStreamImpl& positionStreamC = dynamic_cast<const BrookStreamImpl&> (positions.getImpl());
BrookStreamImpl& positionStream = const_cast<BrookStreamImpl&> (positionStreamC);
BrookStreamImpl& forceStream = dynamic_cast<BrookStreamImpl&> (forces.getImpl());
float epsfac = (float) (_brookBonded->getLJ_14Scale()*_brookBonded->getCoulombFactor());
// nonbonded forces
// added charge stream to knbforce_CDLJ4
// libs generated from ~/src/gmxgpu-nsqOpenMM
BrookFloatStreamInternal** nonbondedForceStreams = _brookNonBonded->getForceStreams();
float epsfac = 138.935485f;
knbforce_CDLJ4(
(float) _brookNonBonded->getNumberOfAtoms(),
(float) _brookNonBonded->getAtomSizeCeiling(),
(float) _brookNonBonded->getDuplicationFactor(),
(float) _brookNonBonded->getAtomStreamHeight( ),
(float) _brookNonBonded->getAtomStreamWidth( ),
(float) _brookNonBonded->getJStreamWidth( ),
(float) _brookNonBonded->getPartialForceStreamWidth( ),
epsfac,
dummyParameters,
positionStream.getBrookStream(),
_brookNonBonded->getChargeStream()->getBrookStream(),
_brookNonBonded->getOuterVdwStream()->getBrookStream(),
_brookNonBonded->getInnerSigmaStream()->getBrookStream(),
_brookNonBonded->getInnerEpsilonStream()->getBrookStream(),
_brookNonBonded->getExclusionStream()->getBrookStream(),
nonbondedForceStreams[0]->getBrookStream(),
nonbondedForceStreams[1]->getBrookStream(),
nonbondedForceStreams[2]->getBrookStream(),
nonbondedForceStreams[3]->getBrookStream()
);
/*
float zerof = 0.0f;
nonbondedForceStreams[0]->fillWithValue( &zerof );
nonbondedForceStreams[1]->fillWithValue( &zerof );
nonbondedForceStreams[2]->fillWithValue( &zerof );
nonbondedForceStreams[3]->fillWithValue( &zerof );
*/
// diagnostics
if( PrintOn ){
(void) fprintf( getLog(), "\nPost knbforce_CDLJ4: atoms=%6d ceiling=%3d dupFac=%3d", _brookNonBonded->getNumberOfAtoms(),
_brookNonBonded->getAtomSizeCeiling(),
_brookNonBonded->getDuplicationFactor() );
(void) fprintf( getLog(), "\n hght=%6d width=%3d jWid=%3d", _brookNonBonded->getAtomStreamHeight( ),
_brookNonBonded->getAtomStreamWidth( ),
_brookNonBonded->getJStreamWidth( ) );
(void) fprintf( getLog(), "\n pFrc=%6d eps=%12.5e\n", _brookNonBonded->getPartialForceStreamWidth( ), epsfac );
(void) fprintf( getLog(), "\nOuterVdwStreamd\n" );
_brookNonBonded->getOuterVdwStream()->printToFile( getLog() );
(void) fprintf( getLog(), "\nInnerSigmaStream\n" );
_brookNonBonded->getInnerSigmaStream()->printToFile( getLog() );
(void) fprintf( getLog(), "\nInnerEpsilonStream\n" );
_brookNonBonded->getInnerEpsilonStream()->printToFile( getLog() );
(void) fprintf( getLog(), "\nExclusionStream\n" );
_brookNonBonded->getExclusionStream()->printToFile( getLog() );
(void) fprintf( getLog(), "\nChargeStream\n" );
_brookNonBonded->getChargeStream()->printToFile( getLog() );
for( int ii = 0; ii < 4; ii++ ){
(void) fprintf( getLog(), "\nForce stream %d\n", ii );
nonbondedForceStreams[ii]->printToFile( getLog() );
}
}
// gather forces
kMergeFloat3_4_nobranch( (float) _brookNonBonded->getDuplicationFactor(),
(float) _brookNonBonded->getAtomStreamWidth(),
(float) _brookNonBonded->getPartialForceStreamWidth(),
(float) _brookNonBonded->getNumberOfAtoms(),
(float) _brookNonBonded->getAtomSizeCeiling(),
(float) _brookNonBonded->getOuterLoopUnroll(),
nonbondedForceStreams[0]->getBrookStream(),
nonbondedForceStreams[1]->getBrookStream(),
nonbondedForceStreams[2]->getBrookStream(),
nonbondedForceStreams[3]->getBrookStream(),
forceStream.getBrookStream() );
// bonded
epsfac = (float) (_brookBonded->getLJ_14Scale()*_brookBonded->getCoulombFactor());
float width = (float) (_brookBonded->getInverseMapStreamWidth());
// bonded forces
......@@ -253,6 +343,7 @@ void BrookCalcStandardMMForceFieldKernel::executeForces( const Stream& positions
(float) bondedForceStreams[0]->getStreamWidth(),
dummyParameters,
positionStream.getBrookStream(),
_brookBonded->getChargeStream()->getBrookStream(),
_brookBonded->getAtomIndicesStream()->getBrookStream(),
bondedParameters[0]->getBrookStream(),
bondedParameters[1]->getBrookStream(),
......@@ -264,6 +355,37 @@ void BrookCalcStandardMMForceFieldKernel::executeForces( const Stream& positions
bondedForceStreams[2]->getBrookStream(),
bondedForceStreams[3]->getBrookStream() );
// diagnostics
if( 1 && PrintOn ){
int countPrintInvMap[4] = { 3, 5, 2, 4 };
(void) fprintf( getLog(), "\nPost kbonded_CDLJ: epsFac=%.6f %.6f %.6f", epsfac, _brookBonded->getLJ_14Scale(), _brookBonded->getCoulombFactor());
(void) fprintf( getLog(), "\nAtom indices stream\n" );
_brookBonded->getAtomIndicesStream()->printToFile( getLog() );
(void) fprintf( getLog(), "\nCharge stream\n" );
_brookBonded->getChargeStream()->printToFile( getLog() );
for( int ii = 0; ii < 5; ii++ ){
(void) fprintf( getLog(), "\nParam stream %d\n", ii );
bondedParameters[ii]->printToFile( getLog() );
}
for( int ii = 0; ii < 4; ii++ ){
(void) fprintf( getLog(), "\nForce stream %d\n", ii );
bondedForceStreams[ii]->printToFile( getLog() );
}
(void) fprintf( getLog(), "\nInverse map streams\n" );
for( int ii = 0; ii < 4; ii++ ){
for( int jj = 0; jj < countPrintInvMap[ii]; jj++ ){
(void) fprintf( getLog(), "\n Inverse map streams index=%d %d\n", ii, jj );
inverseStreamMaps[ii][jj]->printToFile( getLog() );
}
}
}
// gather forces
if( _brookBonded->getInverseMapStreamCount( K_Stream ) <= 4 ){
......@@ -329,50 +451,6 @@ void BrookCalcStandardMMForceFieldKernel::executeForces( const Stream& positions
forceStream.getBrookStream(), forceStream.getBrookStream() );
// ---------------------------------------------------------------------------------------
// nonbonded forces
BrookFloatStreamInternal** nonbondedForceStreams = _brookNonBonded->getForceStreams();
knbforce_CDLJ4(
(float) _brookNonBonded->getNumberOfAtoms(),
(float) _brookNonBonded->getAtomSizeCeiling(),
(float) _brookNonBonded->getDuplicationFactor(),
(float) _brookNonBonded->getAtomStreamHeight( ),
(float) _brookNonBonded->getAtomStreamWidth( ),
(float) _brookNonBonded->getJStreamWidth( ),
(float) _brookNonBonded->getPartialForceStreamWidth( ),
epsfac,
dummyParameters,
positionStream.getBrookStream(),
_brookNonBonded->getOuterVdwStream()->getBrookStream(),
_brookNonBonded->getInnerSigmaStream()->getBrookStream(),
_brookNonBonded->getInnerEpsilonStream()->getBrookStream(),
_brookNonBonded->getExclusionStream()->getBrookStream(),
nonbondedForceStreams[0]->getBrookStream(),
nonbondedForceStreams[1]->getBrookStream(),
nonbondedForceStreams[2]->getBrookStream(),
nonbondedForceStreams[3]->getBrookStream()
);
// strF is assummed to be zero here
// gather forces
kMergeFloat3_4_nobranch( (float) _brookNonBonded->getDuplicationFactor(),
(float) _brookNonBonded->getAtomStreamWidth(),
(float) _brookNonBonded->getPartialForceStreamWidth(),
(float) _brookNonBonded->getNumberOfAtoms(),
(float) _brookNonBonded->getAtomSizeCeiling(),
(float) _brookNonBonded->getOuterLoopUnroll(),
nonbondedForceStreams[0]->getBrookStream(),
nonbondedForceStreams[1]->getBrookStream(),
nonbondedForceStreams[2]->getBrookStream(),
nonbondedForceStreams[3]->getBrookStream(),
forceStream.getBrookStream() );
// ---------------------------------------------------------------------------------------
}
/**
......
......@@ -54,7 +54,6 @@ BrookFloatStreamInternal::BrookFloatStreamInternal( const std::string& name, int
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookFloatStreamInternal::BrookFloatStreamInternal";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
......@@ -119,6 +118,7 @@ BrookFloatStreamInternal::BrookFloatStreamInternal( const std::string& name, int
// set stream height based on specified stream _width
if( streamWidth < 1 ){
std::stringstream message;
message << methodName << " stream=" << name << " input stream width=" << streamWidth << " is less than 1.";
throw OpenMMException( message.str() );
......@@ -155,6 +155,9 @@ BrookFloatStreamInternal::BrookFloatStreamInternal( const std::string& name, int
_data = new float[streamSize*_width];
//printf( "%s %s data=%u stream=%d [%d %d] width=%d\n", methodName.c_str(), getName().c_str(), (unsigned int) _data, streamSize, _streamHeight, _streamWidth, _width );
//fflush( stdout );
}
/**
......@@ -166,12 +169,15 @@ BrookFloatStreamInternal::~BrookFloatStreamInternal( ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookFloatStreamInternal::~BrookFloatStreamInternal";
// static const int debug = 1;
static const std::string methodName = "BrookFloatStreamInternal::~BrookFloatStreamInternal";
// ---------------------------------------------------------------------------------------
//delete _aStream;
//printf( "%s %s data=%u stream=%d [%d %d] width=%d\n", methodName.c_str(), getName().c_str(), (unsigned int) _data, getStreamSize(), _streamHeight, _streamWidth, _width );
//fflush( stdout );
delete[] _data;
}
......@@ -218,7 +224,7 @@ void BrookFloatStreamInternal::loadFromArray( const void* array ){
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*
* @throw exception if baseType not float or double
* @throw exception if baseType not float, double, or integer
*
*/
......@@ -227,11 +233,11 @@ void BrookFloatStreamInternal::loadFromArray( const void* array, BrookStreamInte
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookFloatStreamInternal::loadFromArray";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
int totalSize = getSize()*getWidth();
//int totalSize = getSize();
if( baseType == BrookStreamInternal::Float ){
......@@ -293,6 +299,8 @@ void BrookFloatStreamInternal::saveToArray( void* array ){
if( baseType == BrookStreamInternal::Float ){
//printf( "%s Basetype is float\n", methodName.c_str() );
//fflush( stdout );
memcpy( array, _data, sizeof( float )*totalSize );
/*
float* arrayData = (float*) array;
......@@ -303,6 +311,9 @@ void BrookFloatStreamInternal::saveToArray( void* array ){
} else if( baseType == BrookStreamInternal::Double ){
//printf( "%s Basetype is double\n", methodName.c_str() );
//fflush( stdout );
double* arrayData = (double*) array;
for( int ii = 0; ii < totalSize; ii++ ){
arrayData[ii] = (double) _data[ii];
......@@ -310,6 +321,9 @@ void BrookFloatStreamInternal::saveToArray( void* array ){
} else if( baseType == BrookStreamInternal::Integer ){
//printf( "%s Basetype is int\n", methodName.c_str() );
//fflush( stdout );
int* arrayData = (int*) array;
for( int ii = 0; ii < totalSize; ii++ ){
arrayData[ii] = (int) _data[ii];
......@@ -410,8 +424,7 @@ void BrookFloatStreamInternal::_loadDanglingValues( float danglingValue ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamInternal::_loadDanglingValues";
// static const int debug = 1;
static const std::string methodName = "BrookFloatStreamInternal::_loadDanglingValues";
// ---------------------------------------------------------------------------------------
......@@ -420,6 +433,9 @@ void BrookFloatStreamInternal::_loadDanglingValues( float danglingValue ){
int arraySize = getSize()*width;
int streamSize = getStreamSize()*width;
//printf( "%s array=%d stream=%d width=%d %s\n", methodName.c_str(), arraySize, streamSize, width, getName().c_str() );
//fflush( stdout );
if( arraySize < streamSize ){
for( int ii = arraySize; ii < streamSize; ii++ ){
_data[ii] = danglingValue;
......@@ -489,3 +505,68 @@ const std::string BrookFloatStreamInternal::getContentsString( int level ) const
return message.str();
}
/*
* Print array contents of object to file
*
* @param log file to print to
*
* @return DefaultReturnValue
*
* */
int BrookFloatStreamInternal::_bodyPrintToFile( FILE* log ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookStreamInternal::_bodyPrintToFile";
// ---------------------------------------------------------------------------------------
void* dataArrayV = getDataArray( );
saveToArray( dataArrayV );
int streamSize = getStreamSize();
int width = getWidth();
int index = 0;
float* dataArray = (float*) dataArrayV;
for( int ii = 0; ii < streamSize; ii++ ){
std::stringstream message;
message.width( 15 );
message.precision( 5 );
message << ii << " [ ";
for( int jj = 0; jj < width; jj++ ){
message << dataArray[index++] << " ";
}
message << "]\n";
(void) fprintf( log, "%s", message.str().c_str() );
}
delete[] dataArrayV;
return DefaultReturnValue;
}
/**
* Get array of appropritate size for loading data
*
* @return data array -- user's responsibility to free
*/
void* BrookFloatStreamInternal::getDataArray( void ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookStreamInternal::getDataArray";
// ---------------------------------------------------------------------------------------
int totalSize = getStreamSize()*getWidth();
BrookStreamInternal::DataType baseType = getBaseDataType();
if( baseType == Double || baseType == Double2 || baseType == Double3 || baseType == Double4 ){
totalSize *= 2;
}
return new float[totalSize];
}
......@@ -132,6 +132,13 @@ class BrookFloatStreamInternal : public BrookStreamInternal {
void* getData( int readFromBoard );
/**
* Get array of appropritate size for loading data
*
* @return data array -- user's responsibility to free
*/
void* getDataArray( void );
/**
* Get dangle value
*
......@@ -163,6 +170,16 @@ class BrookFloatStreamInternal : public BrookStreamInternal {
void _loadDanglingValues( void );
void _loadDanglingValues( float );
/*
* Print array to file
*
* @param log log file
*
* @return DefaultReturnValue
*
* */
int _bodyPrintToFile( FILE* log );
};
} // namespace OpenMM
......
......@@ -194,6 +194,24 @@ void BrookIntStreamInternal::fillWithValue( void* value ){
}
}
/**
* Get array of appropritate size for loading data
*
* @return data array -- user's responsibility to free
*/
void* BrookIntStreamInternal::getDataArray( void ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookIntStreamInternal::getDataArray";
// ---------------------------------------------------------------------------------------
int totalSize = getStreamSize()*getWidth();
return new int[totalSize];
}
/**
* Get data
*
......@@ -205,3 +223,119 @@ void* BrookIntStreamInternal::getData( void ){
return _data;
}
/**
* Get data
*
* @param readFromBoard if set, read values on board
*
* @return data array
*
*/
void* BrookIntStreamInternal::getData( int readFromBoard ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamInternal::getData";
// ---------------------------------------------------------------------------------------
if( readFromBoard ){
_aStream.write( _data );
}
return (void*) _data;
}
/*
* Print array contents of object to file
*
* @param log file to print to
*
* @return DefaultReturnValue
*
* */
int BrookIntStreamInternal::_bodyPrintToFile( FILE* log ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookIntStreamInternal::_bodyPrintToFile";
// ---------------------------------------------------------------------------------------
void* dataArrayV = getDataArray( );
saveToArray( dataArrayV );
int streamSize = getStreamSize();
int width = getWidth();
int index = 0;
int* dataArray = (int*) dataArrayV;
for( int ii = 0; ii < streamSize; ii++ ){
std::stringstream message;
message.width( 10 );
message << ii << " [ ";
for( int jj = 0; jj < width; jj++ ){
message << dataArray[index++] << " ";
}
message << "]\n";
(void) fprintf( log, "%s", message.str().c_str() );
}
delete[] dataArrayV;
return DefaultReturnValue;
}
/*
* Get contents of object
*
* @param level level of dump
*
* @return string containing contents
*
* */
const std::string BrookIntStreamInternal::getContentsString( int level ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamInternal::getContentsString";
static const unsigned int MAX_LINE_CHARS = 256;
char value[MAX_LINE_CHARS];
//static const char* Set = "Set";
//static const char* NotSet = "Not set";
// ---------------------------------------------------------------------------------------
std::stringstream message;
std::string tab = " ";
#ifdef WIN32
#define LOCAL_SPRINTF(a,b,c) sprintf_s( (a), MAX_LINE_CHARS, (b), (c) );
#else
#define LOCAL_SPRINTF(a,b,c) sprintf( (a), (b), (c) );
#endif
(void) LOCAL_SPRINTF( value, "%s", getName().c_str() );
message << _getLine( tab, "Name:", value );
(void) LOCAL_SPRINTF( value, "%d", getWidth() );
message << _getLine( tab, "Width:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamSize() );
message << _getLine( tab, "Stream size:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamWidth() );
message << _getLine( tab, "Stream width:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamHeight() );
message << _getLine( tab, "Stream height:", value );
return message.str();
}
......@@ -123,11 +123,53 @@ public:
void* getData( void );
/**
* Get data
*
* @param readFromBoard if set, read values on board
*
* @return data array
*
*/
void* getData( int readFromBoard );
/**
* Get array of appropritate size for loading data
*
* @return data array -- user's responsibility to free
*/
void* getDataArray( void );
/*
* Get contents of object
*
*
* @param level level of dump
*
* @return string containing contents
*
* */
const std::string getContentsString( int level = 0 ) const;
private:
int _dangleValue;
int* _data;
/*
* Print array to file
*
* @param log log file
*
* @return DefaultReturnValue
*
* */
int _bodyPrintToFile( FILE* log );
};
} // namespace OpenMM
......
......@@ -103,7 +103,7 @@ void BrookIntegrateLangevinStepKernel::execute( Stream& positions, Stream& veloc
// ---------------------------------------------------------------------------------------
double epsilon = 1.0e-04;
//static const std::string methodName = "BrookIntegrateLangevinStepKernel::execute";
static const std::string methodName = "BrookIntegrateLangevinStepKernel::execute";
// ---------------------------------------------------------------------------------------
......@@ -121,7 +121,17 @@ void BrookIntegrateLangevinStepKernel::execute( Stream& positions, Stream& veloc
if( fabs( differences[0] ) < epsilon || fabs( differences[1] ) < epsilon || fabs( differences[2] ) < epsilon ){
_brookStochasticDynamics->updateParameters( temperature, friction, stepSize );
}
_brookStochasticDynamics->update( positions, velocities, forces, (_brookShakeAlgorithm ? *_brookShakeAlgorithm : NULL),
*_brookRandomNumberGenerator );
assert( _brookShakeAlgorithm );
/*
if( _brookShakeAlgorithm == NULL ){
std::stringstream message;
message << methodName << " _brookShakeAlgorithm is not set -- case not handled.";
throw OpenMMException( message.str() );
return NULL;
}
*/
_brookStochasticDynamics->update( positions, velocities, forces, *_brookShakeAlgorithm, *_brookRandomNumberGenerator );
}
......@@ -86,7 +86,7 @@ class BrookIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel {
*
*/
void execute( Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize);
void execute( Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize );
protected:
......
This diff is collapsed.
......@@ -391,7 +391,7 @@ class BrookNonBonded : public BrookCommon {
*
* */
int initializeExclusionStreamSize( int atomStreamSize, int atomStreamWidth );
int _initializeExclusionStreamSize( int atomStreamSize, int atomStreamWidth );
/**
* Initialize exclusion stream dimensions and stream
......@@ -402,7 +402,7 @@ class BrookNonBonded : public BrookCommon {
*
*/
int initializeExclusionStream( const Platform& platform );
int _initializeExclusionStream( const Platform& platform );
/**
* Set exclusion (4x4)
......@@ -416,7 +416,7 @@ class BrookNonBonded : public BrookCommon {
*
*/
int setExclusion( int i, int j, int exclusionStreamWidth, BrookOpenMMFloat* exclusion );
int _setExclusion( int i, int j, int exclusionStreamWidth, BrookOpenMMFloat* exclusion );
/**
* Initialize exclusions
......@@ -428,7 +428,7 @@ class BrookNonBonded : public BrookCommon {
*
*/
int initializeExclusions( const std::vector<std::set<int> >& exclusionsVector, const Platform& platform );
int _initializeExclusions( const std::vector<std::set<int> >& exclusionsVector, const Platform& platform );
/**
* Initialize stream dimensions
......@@ -440,7 +440,7 @@ class BrookNonBonded : public BrookCommon {
*
*/
int initializeStreamSizes( int numberOfAtoms, const Platform& platform );
int _initializeStreamSizes( int numberOfAtoms, const Platform& platform );
/**
* Initialize stream dimensions and streams
......@@ -451,7 +451,7 @@ class BrookNonBonded : public BrookCommon {
*
*/
int initializeStreams( const Platform& platform );
int _initializeStreams( const Platform& platform );
/*
* Setup of j-stream dimensions
......@@ -465,7 +465,7 @@ class BrookNonBonded : public BrookCommon {
*
* */
int initializeJStreamSize( int atomStreamSize, int atomStreamWidth );
int _initializeJStreamSize( int atomStreamSize, int atomStreamWidth );
/*
* Setup of outer vdw stream size
......@@ -479,7 +479,7 @@ class BrookNonBonded : public BrookCommon {
*
* */
int initializeOuterVdwStreamSize( int atomStreamSize, int atomStreamWidth );
int _initializeOuterVdwStreamSize( int atomStreamSize, int atomStreamWidth );
/**
* Set sigma & epsilon given c6 & c12 (geometric rule)
......@@ -493,7 +493,7 @@ class BrookNonBonded : public BrookCommon {
*
*/
int setSigmaEpsilon( double c6, double c12, double* sigma , double* epsilon );
int _setSigmaEpsilon( double c6, double c12, double* sigma , double* epsilon );
/**
* Initialize vdw & charge
......@@ -505,7 +505,19 @@ class BrookNonBonded : public BrookCommon {
*
*/
int initializeVdwAndCharge( const std::vector<std::vector<double> >& nonbondedParameters, const Platform& platform );
int _initializeVdwAndCharge( const std::vector<std::vector<double> >& nonbondedParameters, const Platform& platform );
/**
* Initialize vdw & charge
*
* @param exclusions vector of sets containing exclusions (1 set entry for every atom)
* @param platform platform
*
* @return nonzero value if error
*
*/
int _initializeJStreamVdw( const std::vector<std::vector<double> >& nonbondedParameters, const Platform& platform );
/*
* Setup of stream dimensions for partial force streams
......@@ -517,7 +529,7 @@ class BrookNonBonded : public BrookCommon {
*
* */
int initializePartialForceStreamSize( int atomStreamSize, int atomStreamWidth );
int _initializePartialForceStreamSize( int atomStreamSize, int atomStreamWidth );
};
......
......@@ -40,7 +40,7 @@ const std::string BrookStreamFactory::AtomPositions = "atomPosition
const std::string BrookStreamFactory::AtomVelocities = "atomVelocities";
const std::string BrookStreamFactory::AtomForces = "atomForces";
const double DefaultDangleValue = 1.0e+38;
const double DefaultDangleValue = 1.0e+08;
/**
* BrookStreamFactory constructor
*
......@@ -55,7 +55,7 @@ BrookStreamFactory::BrookStreamFactory( void ){
// ---------------------------------------------------------------------------------------
_defaultDangleValue = 1.0e+38;
_defaultDangleValue = 1.0e+08;
_defaultAtomStreamWidth = DefaultStreamAtomWidth;
_defaultStreamRandomNumberWidth = DefaultStreamRandomNumberWidth;
_defaultStreamRandomNumberSize = DefaultStreamRandomNumberSize;
......
......@@ -281,3 +281,82 @@ std::string BrookStreamInternal::_getLine( const std::string& tab,
}
/*
* Print contents of object to file
*
* @param log file to print to
*
* @return DefaultReturnValue
*
* */
int BrookStreamInternal::printToFile( FILE* log ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookStreamInternal::printToFile";
// ---------------------------------------------------------------------------------------
if( log == NULL ){
log = stderr;
}
std::string contents = getContentsString();
(void) fprintf( log, "%s\n", contents.c_str() );
_bodyPrintToFile( log );
return DefaultReturnValue;
}
/*
* Get contents of object
*
* @param level level of dump
*
* @return string containing contents
*
* */
const std::string BrookStreamInternal::getContentsString( int level ) const {
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamInternal::getContentsString";
static const unsigned int MAX_LINE_CHARS = 256;
char value[MAX_LINE_CHARS];
//static const char* Set = "Set";
//static const char* NotSet = "Not set";
// ---------------------------------------------------------------------------------------
std::stringstream message;
std::string tab = " ";
#ifdef WIN32
#define LOCAL_SPRINTF(a,b,c) sprintf_s( (a), MAX_LINE_CHARS, (b), (c) );
#else
#define LOCAL_SPRINTF(a,b,c) sprintf( (a), (b), (c) );
#endif
(void) LOCAL_SPRINTF( value, "%s", getName().c_str() );
message << _getLine( tab, "Name:", value );
(void) LOCAL_SPRINTF( value, "%d", getWidth() );
message << _getLine( tab, "Width:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamSize() );
message << _getLine( tab, "Stream size:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamWidth() );
message << _getLine( tab, "Stream width:", value );
(void) LOCAL_SPRINTF( value, "%d", getStreamHeight() );
message << _getLine( tab, "Stream height:", value );
return message.str();
}
......@@ -50,6 +50,13 @@ class BrookStreamInternal {
*/
enum DataType { Float, Float2, Float3, Float4, Double, Double2, Double3, Double4, Integer, Integer2, Integer3, Integer4, Unknown };
// return values
static const int DefaultReturnValue = 0;
static const int ErrorReturnValue = -1;
// ---------------------------------------------------------------------------------------
/**
* BrookStreamInternal constructor
*
......@@ -101,7 +108,7 @@ class BrookStreamInternal {
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
virtual void loadFromArray(const void* array) = 0;
virtual void loadFromArray( const void* array ) = 0;
/**
* Copy the contents of an array into this stream.
......@@ -121,14 +128,14 @@ class BrookStreamInternal {
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
virtual void saveToArray(void* array) = 0;
virtual void saveToArray( void* array ) = 0;
/**
* Set every element of this stream to the same value.
*
* @param a pointer to the value. It is assumed to be of the correct data type for this stream.
*/
virtual void fillWithValue(void* value) = 0;
virtual void fillWithValue( void* value ) = 0;
/**
* Get data
......@@ -137,6 +144,22 @@ class BrookStreamInternal {
*/
virtual void* getData( void ) = 0;
/**
* Get data
*
* @param readFromBoard read data from board
*
* @return data array
*/
virtual void* getData( int readFromBoard ) = 0;
/**
* Get array of appropritate size for loading data
*
* @return data array -- user's responsibility to free
*/
virtual void* getDataArray( void ) = 0;
/**
* Get type string
*
......@@ -200,6 +223,17 @@ class BrookStreamInternal {
const std::string getContentsString( int level = 0 ) const;
/*
* Print to file
*
* @param log log file
*
* @return DefaultReturnValue
*
* */
int printToFile( FILE* log );
protected:
std::string _name;
......@@ -229,6 +263,16 @@ class BrookStreamInternal {
std::string _getLine( const std::string& tab, const std::string& description,
const std::string& value ) const;
/*
* Print array to file
*
* @param log log file
*
* @return DefaultReturnValue
*
* */
virtual int _bodyPrintToFile( FILE* log ) = 0;
};
} // namespace OpenMM
......
......@@ -57,6 +57,9 @@ gpuCalcInvMap(
//This will hold the number of imaps actually used
*nimaps = -1;
printf( "gpuCalcInvMap: posflag=%d niatoms=%d nints=%d natoms=%d nmaps=%d\n",
posflag, niatoms, nints, natoms, nmaps );
//Now note down the positions where each atom occurs
for ( i = 0; i < nints; i++ ) {
//This is our atom
......@@ -94,6 +97,9 @@ gpuCalcInvMap(
}
counts[atom]++;
printf( "Atom %d count=%d max %d mapcomp=%d val=%d mapnum=%d\n", atom, counts[atom],
nmaps * 4, mapcomp, i, mapnum );
}
(*nimaps)++;
......
......@@ -65,6 +65,7 @@ void knbforce_CDLJ4(
const float epsfac,
const float4 params,
::brook::stream posq,
::brook::stream charge,
::brook::stream isigeps,
::brook::stream sigma,
::brook::stream epsilon,
......@@ -115,6 +116,7 @@ void knbforce_CDLJ4NoEx(
const float epsfac,
const float4 params,
::brook::stream posq,
::brook::stream charge,
::brook::stream isigeps,
::brook::stream sigma,
::brook::stream epsilon,
......@@ -286,6 +288,7 @@ void kbonded_CDLJ (const float epsfac,
const float xstrwidth,
const float4 params,
::brook::stream posq,
::brook::stream charge,
::brook::stream atoms,
::brook::stream parm0,
::brook::stream parm1,
......
This diff is collapsed.
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