Commit 9b08b9b5 authored by Mark Friedrichs's avatar Mark Friedrichs
Browse files

Latest mods -- setup for nonbonded and bonded appears to work

parent 9cea4582
......@@ -29,221 +29,480 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include <sstream>
#include "BrookFloatStreamImpl.h"
#include "OpenMMException.h"
using namespace OpenMM;
BrookFloatStreamImpl::BrookFloatStreamImpl(std::string name, int size, Stream::DataType type, int streamWidth, const Platform& platform,
float inputDefaultDangleValue) :
StreamImpl(name, size, type, platform) {
switch (type) {
case Stream::Float:
case Stream::Float2:
case Stream::Float3:
case Stream::Float4:
baseType = Stream::Float;
break;
case Stream::Double:
case Stream::Double2:
case Stream::Double3:
case Stream::Double4:
baseType = Stream::Float;
break;
}
switch (type) {
case Stream::Float:
case Stream::Double:
width = 1;
break;
case Stream::Float2:
case Stream::Double2:
width = 2;
break;
case Stream::Float3:
case Stream::Double3:
width = 3;
break;
case Stream::Float4:
case Stream::Double4:
width = 4;
break;
/**
* BrookFloatStreamImpl constructor
*
* @param name stream name
* @param size stream size
* @param type stream type (float, float2, ...)
* @param platform platform
* @param inputStreamWidth stream width
* @param inputDefaultDangleValue default dangle value
*
*/
BrookFloatStreamImpl::BrookFloatStreamImpl( std::string name, int size, Stream::DataType type,
const Platform& platform, int inputStreamWidth,
double inputDefaultDangleValue = 0.0 ) : StreamImpl( name, size, type, platform ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookFloatStreamImpl::BrookFloatStreamImpl";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
// set base type (currently only FLOAT supported)
switch( type ){
case Stream::Float:
case Stream::Float2:
case Stream::Float3:
case Stream::Float4:
_baseType = Stream::Float;
break;
case Stream::Double:
case Stream::Double2:
case Stream::Double3:
case Stream::Double4:
_baseType = Stream::Float;
break;
default:
std::stringstream message;
message << methodName << " stream=" << name << " input type=" << type << " not recognized.";
throw OpenMMException( message.str() );
break;
}
defaultDangleValue = inputDefaultDangleValue;
// set _width (FLOAT, FLOAT2, ... )
// set stream height based on specified stream width
switch( type ){
streamWidth = inputStreamWidth;
streamHeight = size/streamWidth + ((size % streamWidth) ? 1 : 0);
streamSize = streamHeight*streamWidth;
case Stream::Float:
case Stream::Double:
// create Brook stream handle
_width = 1;
break;
case Stream::Float2:
case Stream::Double2:
_width = 2;
break;
case Stream::Float3:
case Stream::Double3:
switch( width ){
_width = 3;
break;
case 1:
aStream = brook::stream::create<float>( streamHeight, streamWidth );
break;
case Stream::Float4:
case Stream::Double4:
case 2:
aStream = brook::stream::create<float2>( streamHeight, streamWidth );
break;
_width = 4;
break;
}
_defaultDangleValue = (BrookOpenMMFloat) inputDefaultDangleValue;
// set stream height based on specified stream _width
if( inputStreamWidth < 1 ){
std::stringstream message;
message << methodName << " stream=" << name << " input stream width=" << type << " is less than 1.";
throw OpenMMException( message.str() );
}
_streamWidth = inputStreamWidth;
_streamHeight = size/_streamWidth + ((size % _streamWidth) ? 1 : 0);
int streamSize = getStreamSize();
// create Brook stream handle
case 3:
aStream = brook::stream::create<float3>( streamHeight, streamWidth );
break;
switch( _width ){
case 4:
aStream = brook::stream::create<float4>( streamHeight, streamWidth );
break;
case 1:
_aStream = brook::stream::create<float>( _streamHeight, _streamWidth );
break;
case 2:
_aStream = brook::stream::create<float2>( _streamHeight, _streamWidth );
break;
case 3:
_aStream = brook::stream::create<float3>( _streamHeight, _streamWidth );
break;
case 4:
_aStream = brook::stream::create<float4>( _streamHeight, _streamWidth );
break;
}
// allocate memory for data buffer
data = new float*[streamSize];
for (int i = 0; i < streamSize; ++i){
data[i] = new float[width];
_data = new float*[streamSize];
for( int ii = 0; ii < streamSize; ii++ ){
_data[ii] = new float[_width];
}
// check if we are using float or double
if( sizeof( float ) != sizeof( RealOpenMM ) ){
realOpenMMData = new RealOpenMM*[streamSize];
for (int i = 0; i < streamSize; ++i){
realOpenMMData[i] = new RealOpenMM[width];
_realOpenMMData = new RealOpenMM*[streamSize];
for( int ii = 0; ii < streamSize; ii++ ){
_realOpenMMData[ii] = new RealOpenMM[_width];
}
} else {
_realOpenMMData = NULL;
}
}
/**
* BrookFloatStreamImpl destructor
*
*/
BrookFloatStreamImpl::~BrookFloatStreamImpl( ){
// ---------------------------------------------------------------------------------------
//static const std::string methodName = "BrookFloatStreamImpl::~BrookFloatStreamImpl";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
//delete _aStream;
int streamSize = getStreamSize();
for( int ii = 0; ii < streamSize; ii++ ){
delete[] _data[ii];
}
delete[] _data;
if( _realOpenMMData ){
for( int ii = 0; ii < streamSize; ii++ ){
delete[] _realOpenMMData[ii];
}
delete[] _realOpenMMData;
}
}
/**
* Load _data from input array
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all
* 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.
*
*/
void BrookFloatStreamImpl::loadFromArray( const void* array ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::loadFromArray";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
if( _baseType == Stream::Float ){
loadFromArray( array, Stream::Float );
} else {
realOpenMMData = NULL;
loadFromArray( array, Stream::Double );
}
}
/**
* Get width
*
* @return width
*/
int BrookFloatStreamImpl::getWidth( void ) const {
return _width;
}
/**
* Get stream width
*
* @return stream width
*/
int BrookFloatStreamImpl::getStreamWidth( void ) const {
return _streamWidth;
}
BrookFloatStreamImpl::~BrookFloatStreamImpl() {
delete aStream;
delete data[];
delete realOpenMMData[];
/**
* Get stream height
*
* @return stream height
*/
int BrookFloatStreamImpl::getStreamHeight( void ) const {
return _streamHeight;
}
/**
* Get Brook stream
*
* @return Brook stream
*/
brook::stream& BrookFloatStreamImpl::getBrookStream( void ){
return _aStream;
}
/**
* Get stream size
*
* @return stream size
*/
int BrookFloatStreamImpl::getStreamSize( void ) const {
return _streamWidth*_streamHeight;
}
void BrookFloatStreamImpl::loadFromArray(const void* array) {
/**
* Load _data from input array
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct _data type for this stream. If the stream has a compound _data type, all
* 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.
*
* @param inputType type of input array (Stream::Float, Stream::Double, Stream::Integer)
*
* @throw if input type not recognized, an exception is thrown
*/
if( baseType == Stream::Float ){
float* arrayData = (float*) array;
for (int i = 0; i < getSize(); ++i){
for (int j = 0; j < width; ++j){
data[i][j] = arrayData[i*width+j];
void BrookFloatStreamImpl::loadFromArray( const void* array, Stream::DataType inputType ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookFloatStreamImpl::loadFromArray";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
int index = 0;
if( inputType == Stream::Float ){
float* arrayData = (float*) array;
for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){
_data[ii][jj] = (BrookOpenMMFloat) arrayData[index++];
}
}
} else {
} else if( inputType == Stream::Double ){
double* arrayData = (double*) array;
for (int i = 0; i < getSize(); ++i){
for (int j = 0; j < width; ++j){
data[i][j] = (float) arrayData[i*width+j];
for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){
_data[ii][jj] = (BrookOpenMMFloat) arrayData[index++];
}
}
} else if( inputType == Stream::Integer ){
int* arrayData = (int*) array;
for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){
_data[ii][jj] = (BrookOpenMMFloat) arrayData[index++];
}
}
} else {
std::stringstream message;
message << methodName << " stream=" << getName() << " input type=" << inputType << " not recognized.";
throw OpenMMException( message.str() );
}
// set dangling values
_loadDanglingValues();
// write to GPU
// write to GPU
aStream.read( data );
_aStream.read( _data );
}
void BrookFloatStreamImpl::saveToArray(void* array) {
void BrookFloatStreamImpl::saveToArray( void* array ){
// ---------------------------------------------------------------------------------------
// get data from GPU
//static const std::string methodName = "BrookFloatStreamImpl::saveToArray";
// static const int debug = 1;
aStream.write( data );
// ---------------------------------------------------------------------------------------
// get _data from GPU
_aStream.write( _data );
// load into array
if( baseType == Stream::Float ){
int index = 0;
if( _baseType == Stream::Float ){
float* arrayData = (float*) array;
for( int i = 0; i < getSize(); ++i ){
for( int j = 0; j < width; ++j ){
arrayData[i*width+j] = data[i][j];
for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){
arrayData[index++] = (float) _data[ii][jj];
}
}
} else {
double* arrayData = (double*) array;
for( int i = 0; i < getSize(); ++i ){
for( int j = 0; j < width; ++j ){
arrayData[i*width+j] = data[i][j];
for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < getWidth(); jj++ ){
arrayData[index++] = _data[ii][jj];
}
}
}
}
/**
* Fill stream w/ specified value
*
* @param value value to fill stream w/
*
*/
void BrookFloatStreamImpl::fillWithValue( void* value ){
if (baseType == Stream::Float) {
float valueData = *((float*) value);
for( int i = 0; i < getSize(); i++ ){
for( int j = 0; j < width; j++ ){
data[i][j] = valueData;
}
}
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::fillWithValue";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
BrookOpenMMFloat valueData;
if( _baseType == Stream::Float) {
valueData = (BrookOpenMMFloat) *((float*) value);
} else {
double valueData = *((double*) value);
for( int i = 0; i < getSize(); i++ ){
for (int j = 0; j < width; j++ ){
data[i][j] = valueData;
}
valueData = (BrookOpenMMFloat) *((double*) value);
}
for( int ii = 0; ii < getSize(); ii++ ){
for (int jj = 0; jj < getWidth(); jj++ ){
_data[ii][jj] = valueData;
}
}
_loadDanglingValues();
aStream.read( data );
_aStream.read( _data );
}
const RealOpenMM* const * BrookFloatStreamImpl::getData() const {
return NULL;
}
// problem w/ const here -- _data is modified (cast away?)
/*
const RealOpenMM* const * BrookFloatStreamImpl::getData() const {
// retreive data from GPU
// retrieve _data from GPU
aStream.write( data );
_aStream.write( _data );
// check if RealOpenMM is float; if not, then
// copy into realOpenMMData[][] array
if( realOpenMMData ){
for( int i = 0; i < getSize(); i++ ){
for( int j = 0; j < width; j++ ){
realOpenMMData[i][j] = (RealOpenMM) data[i][j];
for( int j = 0; j < _width; j++ ){
realOpenMMData[i][j] = (RealOpenMM) _data[i][j];
}
}
return realOpenMMData;
} else {
return data;
return _data;
}
}
*/
RealOpenMM** BrookFloatStreamImpl::getData() {
aStream.write( data );
if( realOpenMMData ){
for( int i = 0; i < getSize(); i++ ){
for( int j = 0; j < width; j++ ){
realOpenMMData[i][j] = (RealOpenMM) data[i][j];
/**
* Get data
*
* @return data array
*
*/
RealOpenMM** BrookFloatStreamImpl::getData( void ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::getData";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
_aStream.write( _data );
if( _realOpenMMData ){
for( int ii = 0; ii < getSize(); ii++ ){
for (int jj = 0; jj < getWidth(); jj++ ){
_realOpenMMData[ii][jj] = (RealOpenMM) _data[ii][jj];
}
}
return realOpenMMData;
return _realOpenMMData;
} else {
return data;
return _data;
}
}
/**
* Load dangling value into stream
*
* @param danglingValue dangling value to load
*
*/
void BrookFloatStreamImpl::_loadDanglingValues( float danglingValue ){
for( int ii = getSize(); ii < streamSize; ii++ ){
for( int jj = 0; jj < width; jj++ ){
data[ii][jj] = danglingValue;
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookFloatStreamImpl::_loadDanglingValues";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
int streamSize = getStreamSize();
for( int ii = getSize(); ii < streamSize; ii++ ){
for (int jj = 0; jj < getWidth(); jj++ ){
_data[ii][jj] = danglingValue;
}
}
}
/**
* Load default dangling value into stream
*
*/
void BrookFloatStreamImpl::_loadDanglingValues( void ){
_loadDanglingValues( defaultDangleValue );
_loadDanglingValues( _defaultDangleValue );
}
......@@ -9,12 +9,12 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Portions copyright ( c ) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman, Mark Friedrichs *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* 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 *
......@@ -33,37 +33,58 @@
* -------------------------------------------------------------------------- */
#include "StreamImpl.h"
#include "BrookPlatform.h"
#include <brook/brook.hpp>
#include "SimTKUtilities/SimTKOpenMMRealType.h"
namespace OpenMM {
/**
* This is the implementation of Float and Double streams in the reference Platform.
* This is the implementation of Float and Double streams in the Brook Platform.
*/
class BrookFloatStreamImpl : public StreamImpl {
public:
BrookFloatStreamImpl(std::string name, int size, Stream::DataType type, int streamWidth, const Platform& platform, float defaultDangleValue );
~BrookFloatStreamImpl();
void loadFromArray(const void* array);
void saveToArray(void* array);
void fillWithValue(void* value);
const RealOpenMM* const * getData() const;
RealOpenMM** getData();
private:
int width;
int streamWidth;
int streamHeight;
int streamSize;
float defaultDangleValue;
Stream::DataType baseType;
brook::stream aStream;
float** data;
RealOpenMM** realOpenMMData;
public:
void _loadDanglingValues(void );
BrookFloatStreamImpl( std::string name, int size, Stream::DataType type, const Platform& platform, int inputStreamWidth, double defaultDangleValue );
~BrookFloatStreamImpl( );
void loadFromArray( const void* array );
void loadFromArray( const void* array, Stream::DataType type );
void saveToArray( void* array );
void fillWithValue( void* value );
const RealOpenMM* const * getData( ) const;
RealOpenMM** getData( void );
/**
* Get width
*
* @return width
*/
int BrookFloatStreamImpl::getWidth( void ) const;
int getStreamWidth( void ) const;
int getStreamHeight( void ) const;
int getStreamSize( void ) const;
brook::stream& getBrookStream( void );
private:
int _width;
int _streamWidth;
int _streamHeight;
float _defaultDangleValue;
Stream::DataType _baseType;
brook::stream _aStream;
float** _data;
RealOpenMM** _realOpenMMData;
void _loadDanglingValues( void );
void _loadDanglingValues( float );
};
} // namespace OpenMM
......
......@@ -30,59 +30,162 @@
* -------------------------------------------------------------------------- */
#include "BrookIntStreamImpl.h"
#include "OpenMMException.h"
#include <sstream>
using namespace OpenMM;
BrookIntStreamImpl::BrookIntStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform) : StreamImpl(name, size, type, platform) {
switch (type) {
case Stream::Integer:
width = 1;
break;
case Stream::Integer2:
width = 2;
break;
case Stream::Integer3:
width = 3;
break;
case Stream::Integer4:
width = 4;
break;
}
data = new int*[size];
for (int i = 0; i < size; ++i)
data[i] = new int[width];
/**
* BrookIntStreamImpl constructor
*
* @param name stream name
* @param size stream size
* @param platform platform
*
*/
BrookIntStreamImpl::BrookIntStreamImpl( std::string name, int size, Stream::DataType type, const Platform& platform ) : StreamImpl( name, size, type, platform ){
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookIntStreamImpl::BrookIntStreamImpl";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
switch( type ){
case Stream::Integer:
width = 1;
break;
case Stream::Integer2:
width = 2;
break;
case Stream::Integer3:
width = 3;
break;
case Stream::Integer4:
width = 4;
break;
default:
std::stringstream message;
message << methodName << " type=" << type << " not recognized.";
throw OpenMMException( message.str() );
}
data = new int*[size];
for( int ii = 0; ii < size; ii++ ){
data[ii] = new int[width];
}
}
/**
* BrookIntStreamImpl destructor
*
*/
BrookIntStreamImpl::~BrookIntStreamImpl() {
delete data;
delete[] data;
}
void BrookIntStreamImpl::loadFromArray(const void* array) {
int* arrayData = (int*) array;
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i][j] = arrayData[i*width+j];
/**
* Load data from array into stream
*
* @param array array to load (length=size*width)
*
*/
void BrookIntStreamImpl::loadFromArray( const void* array ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamImpl::loadFromArray";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
int* arrayData = (int*) array;
int index = 0;
for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < width; jj++ ){
data[ii][jj] = arrayData[index++];
}
}
}
void BrookIntStreamImpl::saveToArray(void* array) {
int* arrayData = (int*) array;
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
arrayData[i*width+j] = data[i][j];
/**
* Save data from stream to array
*
* @param array array to save data to (length=size*width)
*
*/
void BrookIntStreamImpl::saveToArray( void* array ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamImpl::saveToArray";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
int* arrayData = (int*) array;
int index = 0;
for( int ii = 0; ii < getSize(); ii++ ){
for( int jj = 0; jj < width; jj++ ){
arrayData[index++] = data[ii][jj];
}
}
}
void BrookIntStreamImpl::fillWithValue(void* value) {
int valueData = *((int*) value);
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i][j] = valueData;
/**
* Set all stream entries to input value
*
* @param value value to load into stream
*
*/
void BrookIntStreamImpl::fillWithValue( void* value ){
// ---------------------------------------------------------------------------------------
// static const std::string methodName = "BrookIntStreamImpl::fillWithValue";
// static const int debug = 1;
// ---------------------------------------------------------------------------------------
int valueData = *((int*) value);
for( int ii = 0; ii < getSize(); ii++ ){
for (int jj = 0; jj < width; jj++ ){
data[ii][jj] = valueData;
}
}
}
const int* const * BrookIntStreamImpl::getData() const {
return data;
/**
* Get data
*
* @return data ptr
*
*/
const int* const * BrookIntStreamImpl::getData( void ) const {
return data;
}
int** BrookIntStreamImpl::getData() {
return data;
/**
* Get data
*
* @return data ptr
*
*/
int** BrookIntStreamImpl::getData( void ){
return data;
}
......@@ -38,22 +38,25 @@
namespace OpenMM {
/**
* This is the implementation of Float and Double streams in the reference Platform.
* Implementation of int streams for the Brook platform
*/
class BrookIntStreamImpl : public StreamImpl {
public:
BrookIntStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform);
~BrookIntStreamImpl();
BrookIntStreamImpl( std::string name, int size, Stream::DataType type, const Platform& platform );
~BrookIntStreamImpl( );
void loadFromArray(const void* array);
void saveToArray(void* array);
void fillWithValue(void* value);
const int* const * getData() const;
int** getData();
void loadFromArray( const void* array );
void saveToArray( void* array );
void fillWithValue( void* value );
const int* const * getData( void ) const;
int** getData( void );
private:
int width;
Stream::DataType baseType;
int** data;
......
......@@ -36,9 +36,13 @@ using namespace OpenMM;
KernelImpl* BrookKernelFactory::createKernelImpl(std::string name, const Platform& platform, OpenMMContextImpl& context) const {
if (name == CalcStandardMMForceFieldKernel::Name())
return new BrookCalcStandardMMForceFieldKernel(name, platform);
(void) fprintf( stderr, "CalcStandardMMForceFieldKernel not set BrookKernelFactory::createKernelImpl\n" );
(void) fflush( stderr );
//return new BrookCalcStandardMMForceFieldKernel(name, platform);
if (name == CalcGBSAOBCForceFieldKernel::Name())
return new BrookCalcGBSAOBCForceFieldKernel(name, platform);
(void) fprintf( stderr, "CalcGBSAOBCForceFieldKernel not set BrookKernelFactory::createKernelImpl\n" );
(void) fflush( stderr );
//return new BrookCalcGBSAOBCForceFieldKernel(name, platform);
if (name == IntegrateVerletStepKernel::Name())
return new BrookIntegrateVerletStepKernel(name, platform);
if (name == IntegrateLangevinStepKernel::Name())
......
......@@ -31,6 +31,7 @@
#include "BrookKernels.h"
#include "BrookFloatStreamImpl.h"
/*
#include "SimTKBrook/BrookAngleBondIxn.h"
#include "SimTKBrook/BrookBondForce.h"
#include "SimTKBrook/BrookHarmonicBondIxn.h"
......@@ -40,12 +41,14 @@
#include "SimTKBrook/BrookRbDihedralBond.h"
#include "SimTKBrook/BrookStochasticDynamics.h"
#include "SimTKBrook/BrookShakeAlgorithm.h"
*/
#include <cmath>
#include <limits>
using namespace OpenMM;
using namespace std;
/*
int** allocateIntArray(int length, int width) {
int** array = new int*[length];
for (int i = 0; i < length; ++i)
......@@ -95,8 +98,10 @@ void disposeRealArray(RealOpenMM** array, int size) {
delete[] array;
}
}
*/
BrookCalcStandardMMForceFieldKernel::~BrookCalcStandardMMForceFieldKernel() {
/*
disposeIntArray(bondIndexArray, numBonds);
disposeRealArray(bondParamArray, numBonds);
disposeIntArray(angleIndexArray, numAngles);
......@@ -109,6 +114,7 @@ BrookCalcStandardMMForceFieldKernel::~BrookCalcStandardMMForceFieldKernel() {
disposeIntArray(exclusionArray, numAtoms);
disposeIntArray(bonded14IndexArray, num14);
disposeRealArray(bonded14ParamArray, num14);
*/
}
void BrookCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters,
......@@ -117,6 +123,7 @@ void BrookCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters,
const vector<vector<int> >& bonded14Indices, double lj14Scale, double coulomb14Scale,
const vector<set<int> >& exclusions, const vector<vector<double> >& nonbondedParameters) {
/*
numAtoms = nonbondedParameters.size();
numBonds = bondIndices.size();
numAngles = angleIndices.size();
......@@ -155,9 +162,11 @@ void BrookCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
bonded14ParamArray[i][1] = lj14Scale*(atomParamArray[atom1][1]*atomParamArray[atom2][1]);
bonded14ParamArray[i][2] = coulomb14Scale*(atomParamArray[atom1][2]*atomParamArray[atom2][2]);
}
*/
}
void BrookCalcStandardMMForceFieldKernel::executeForces(const Stream& positions, Stream& forces) {
/*
RealOpenMM** posData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) positions.getImpl()).getData()); // Brook code needs to be made const correct
RealOpenMM** forceData = ((BrookFloatStreamImpl&) forces.getImpl()).getData();
BrookBondForce refBondForce;
......@@ -173,14 +182,16 @@ void BrookCalcStandardMMForceFieldKernel::executeForces(const Stream& positions,
clj.calculatePairIxn(numAtoms, posData, atomParamArray, exclusionArray, 0, forceData, 0, 0);
BrookLJCoulomb14 nonbonded14;
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, 0, 0, 0, nonbonded14);
*/
}
double BrookCalcStandardMMForceFieldKernel::executeEnergy(const Stream& positions) {
RealOpenMM energy = 0;
/*
RealOpenMM** posData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) positions.getImpl()).getData()); // Brook code needs to be made const correct
RealOpenMM** forceData = allocateRealArray(numAtoms, 3);
int arraySize = max(max(max(max(numAtoms, numBonds), numAngles), numPeriodicTorsions), numRBTorsions);
RealOpenMM* energyArray = new RealOpenMM[arraySize];
RealOpenMM energy = 0;
BrookBondForce refBondForce;
BrookHarmonicBondIxn harmonicBond;
for (int i = 0; i < arraySize; ++i)
......@@ -206,6 +217,7 @@ double BrookCalcStandardMMForceFieldKernel::executeEnergy(const Stream& position
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, energyArray, 0, &energy, nonbonded14);
disposeRealArray(forceData, numAtoms);
delete[] energyArray;
*/
return energy;
}
......@@ -232,6 +244,7 @@ void BrookIntegrateVerletStepKernel::execute(Stream& positions, Stream& velociti
}
#include <iostream>
BrookIntegrateLangevinStepKernel::~BrookIntegrateLangevinStepKernel() {
/*
if (dynamics)
delete dynamics;
if (shake)
......@@ -242,10 +255,12 @@ BrookIntegrateLangevinStepKernel::~BrookIntegrateLangevinStepKernel() {
disposeIntArray(constraintIndices, numConstraints);
if (shakeParameters)
disposeRealArray(shakeParameters, numConstraints);
*/
}
void BrookIntegrateLangevinStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices,
const vector<double>& constraintLengths) {
/*
this->masses = new RealOpenMM[masses.size()];
for (int i = 0; i < masses.size(); ++i)
this->masses[i] = masses[i];
......@@ -258,9 +273,11 @@ void BrookIntegrateLangevinStepKernel::initialize(const vector<double>& masses,
shakeParameters = allocateRealArray(constraintLengths.size(), 1);
for (int i = 0; i < constraintLengths.size(); ++i)
shakeParameters[i][0] = constraintLengths[i];
*/
}
void BrookIntegrateLangevinStepKernel::execute(Stream& positions, Stream& velocities, const Stream& forces, double temperature, double friction, double stepSize) {
/*
RealOpenMM** posData = ((BrookFloatStreamImpl&) positions.getImpl()).getData();
RealOpenMM** velData = ((BrookFloatStreamImpl&) velocities.getImpl()).getData();
RealOpenMM** forceData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) forces.getImpl()).getData()); // Brook code needs to be made const correct
......@@ -280,6 +297,7 @@ void BrookIntegrateLangevinStepKernel::execute(Stream& positions, Stream& veloci
prevStepSize = stepSize;
}
dynamics->update(positions.getSize(), posData, velData, forceData, masses);
*/
}
void BrookIntegrateBrownianStepKernel::initialize(const vector<double>& masses, const vector<vector<int> >& constraintIndices,
......@@ -304,9 +322,11 @@ void BrookCalcKineticEnergyKernel::initialize(const vector<double>& masses) {
}
double BrookCalcKineticEnergyKernel::execute(const Stream& velocities) {
RealOpenMM** velData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) velocities.getImpl()).getData()); // Brook code needs to be made const correct
double energy = 0.0;
/*
RealOpenMM** velData = const_cast<RealOpenMM**>(((BrookFloatStreamImpl&) velocities.getImpl()).getData()); // Brook code needs to be made const correct
for (int i = 0; i < masses.size(); ++i)
energy += masses[i]*(velData[i][0]*velData[i][0]+velData[i][1]*velData[i][1]+velData[i][2]*velData[i][2]);
*/
return 0.5*energy;
}
......@@ -31,33 +31,65 @@
#include "BrookPlatform.h"
#include "BrookKernelFactory.h"
#include "BrookKernels.h"
//#include "BrookKernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
using namespace OpenMM;
BrookPlatform* registerBrookPlatform() {
BrookPlatform* platform = new BrookPlatform();
Platform::registerPlatform(platform);
BrookPlatform* registerBrookPlatform( void ){
BrookPlatform* platform = new BrookPlatform();
Platform::registerPlatform(platform);
return platform;
}
BrookPlatform* staticPlatform = registerBrookPlatform();
BrookPlatform* staticPlatform = registerBrookPlatform( );
BrookPlatform::BrookPlatform() {
BrookKernelFactory* factory = new BrookKernelFactory();
registerKernelFactory(CalcStandardMMForceFieldKernel::Name(), factory);
registerKernelFactory(CalcGBSAOBCForceFieldKernel::Name(), factory);
registerKernelFactory(IntegrateVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
registerKernelFactory(ApplyAndersenThermostatKernel::Name(), factory);
registerKernelFactory(CalcKineticEnergyKernel::Name(), factory);
BrookPlatform::BrookPlatform( ){
_defaultAtomStreamWidth = DefaultAtomStreamWidth;
_initializeFactory();
}
bool BrookPlatform::supportsDoublePrecision() const {
BrookPlatform::BrookPlatform( int defaultAtomStreamWidth ){
_defaultAtomStreamWidth = defaultAtomStreamWidth;
_initializeFactory();
}
BrookPlatform::~BrookPlatform( ){
}
void BrookPlatform::_initializeFactory( void ){
//BrookKernelFactory* factory = new BrookKernelFactory();
/*
registerKernelFactory( CalcStandardMMForceFieldKernel::Name(), factory);
registerKernelFactory( CalcGBSAOBCForceFieldKernel::Name(), factory);
registerKernelFactory( IntegrateVerletStepKernel::Name(), factory);
registerKernelFactory( IntegrateLangevinStepKernel::Name(), factory);
registerKernelFactory( IntegrateBrownianStepKernel::Name(), factory);
registerKernelFactory( ApplyAndersenThermostatKernel::Name(), factory);
registerKernelFactory( CalcKineticEnergyKernel::Name(), factory);
*/
}
bool BrookPlatform::supportsDoublePrecision( void ) const {
return (sizeof(RealOpenMM) >= sizeof(double));
}
const StreamFactory& BrookPlatform::getDefaultStreamFactory() const {
const StreamFactory& BrookPlatform::getDefaultStreamFactory( void ) const {
return defaultStreamFactory;
}
int BrookPlatform::getStreamSize( int size, int streamWidth, int* outputHeight ) const {
if( streamWidth < 1 ){
return -1;
}
int height = size/streamWidth;
if( streamWidth*height < size ){
height++;
}
if( outputHeight ){
*outputHeight = height;
}
return height*streamWidth;
}
......@@ -29,6 +29,7 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include <sstream>
#include "OpenMMException.h"
#include "BrookStreamFactory.h"
#include "BrookFloatStreamImpl.h"
......@@ -36,22 +37,167 @@
using namespace OpenMM;
StreamImpl* BrookStreamFactory::createStreamImpl(std::string name, int size, Stream::DataType type, int streamWidth, const Platform& platform, OpenMMContextImpl& context) const {
switch (type) {
case Stream::Float:
case Stream::Float2:
case Stream::Float3:
case Stream::Float4:
case Stream::Double:
case Stream::Double2:
case Stream::Double3:
case Stream::Double4:
return new BrookFloatStreamImpl(name, size, type, streamWidth, platform);
case Stream::Integer:
case Stream::Integer2:
case Stream::Integer3:
case Stream::Integer4:
return new BrookIntStreamImpl(name, size, type, streamWidth, platform);
}
throw OpenMMException("Tried to create a Stream with an illegal DataType.");
const std::string BrookStreamFactory::AtomPositions = "atomPositions";
const std::string BrookStreamFactory::AtomVelocities = "atomVelocities";
const std::string BrookStreamFactory::AtomForces = "atomForces";
// bonded streams
const std::string BrookStreamFactory::BondedAtomIndicesStream = "BondedAtomIndicesStream";
const std::string BrookStreamFactory::BondedParametersStream = "BondedParametersStream";
const std::string BrookStreamFactory::UnrolledForceStream = "UnrolledForceStream";
const std::string BrookStreamFactory::BondedChargeStream = "BondedChargeStream";
const std::string BrookStreamFactory::BondedInverseMapStreams = "BondedInverseMapStreams";
// non-bonded streams
const std::string BrookStreamFactory::NonBondedExclusionStream = "NonBondedExclusionStream";
const std::string BrookStreamFactory::NonBondedVdwStream = "NonBondedVdwStream";
/**
* BrookStreamFactory constructor
*
* @return BrookStreamFactory
*/
BrookStreamFactory::BrookStreamFactory( void ){
double defaultDangleValue = 1.0e+38;
int defaultStreamWidth = 32;
_streamInfoMap[AtomPositions] = new BrookStreamInfo( AtomPositions, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[AtomVelocities] = new BrookStreamInfo( AtomVelocities, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[AtomForces] = new BrookStreamInfo( AtomForces, defaultStreamWidth, defaultDangleValue );
// bonded streams
_streamInfoMap[BondedAtomIndicesStream] = new BrookStreamInfo( BondedAtomIndicesStream, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[BondedParametersStream] = new BrookStreamInfo( BondedParametersStream, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[UnrolledForceStream] = new BrookStreamInfo( UnrolledForceStream, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[BondedChargeStream] = new BrookStreamInfo( BondedChargeStream, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[BondedInverseMapStreams] = new BrookStreamInfo( BondedInverseMapStreams, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[NonBondedExclusionStream] = new BrookStreamInfo( NonBondedExclusionStream, defaultStreamWidth, defaultDangleValue );
_streamInfoMap[NonBondedVdwStream] = new BrookStreamInfo( NonBondedVdwStream, defaultStreamWidth, defaultDangleValue );
}
/**
* BrookStreamFactory destructor
*
*/
BrookStreamFactory::~BrookStreamFactory( void ){
//_streamInfoMap[UnrolledForceStream] = new BrookStreamInfo( UnrolledForceStream, 32, defaultDangleValue );
}
/**
* Get BrookStreamInfo reference given stream name
*
* @param name stream name
*
* @return BrookStreamInfo -- look up streamInfo object given name; return NULL if name not recognized
*/
BrookStreamInfo* BrookStreamFactory::getBrookStreamInfo( std::string name ) const {
if( _streamInfoMap.find( name ) == _streamInfoMap.end() ){
return NULL;
}
return _streamInfoMap.find( name )->second;
}
/**
* Create StreamImpl
*
* @param name stream name
* @param size stream size
* @param type data type (float, float2, ...)
* @param platform platform reference
* @param context context (currently ignored)
*
* @return StreamImpl
*/
StreamImpl* BrookStreamFactory::createStreamImpl( std::string name, int size, Stream::DataType type,
const Platform& platform, OpenMMContextImpl& context ) const {
return BrookStreamFactory::createStreamImplCommon( name, size, type, platform );
}
/**
* Create StreamImpl
*
* @param name stream name
* @param size stream size
* @param type data type (float, float2, ...)
* @param platform platform reference
*
* @return StreamImpl
*/
StreamImpl* BrookStreamFactory::createStreamImpl( std::string name, int size, Stream::DataType type,
const Platform& platform ) const {
return BrookStreamFactory::createStreamImplCommon( name, size, type, platform );
}
/**
* Create StreamImpl
*
* @param name stream name
* @param size stream size
* @param type data type (float, float2, ...)
* @param platform platform reference
*
* @return StreamImpl
*/
StreamImpl* BrookStreamFactory::createStreamImplCommon( std::string name, int size, Stream::DataType type,
const Platform& platform ) const {
// ---------------------------------------------------------------------------------------
static const std::string methodName = "BrookStreamFactory::createStreamImplCommon";
//static const int debug = 0;
// ---------------------------------------------------------------------------------------
// get stream width & dangle value
BrookStreamInfo* streamInfo = getBrookStreamInfo( name );
if( streamInfo == NULL ){
std::stringstream message;
message << methodName << " stream=" << name << " not registered.";
throw OpenMMException( message.str() );
}
int streamWidth = streamInfo->getStreamWidth();
double dangleValue = streamInfo->getDangleValue();
switch ( type ){
case Stream::Float:
case Stream::Float2:
case Stream::Float3:
case Stream::Float4:
case Stream::Double:
case Stream::Double2:
case Stream::Double3:
case Stream::Double4:
return new BrookFloatStreamImpl( name, size, type, platform, streamWidth, dangleValue );
break;
case Stream::Integer:
case Stream::Integer2:
case Stream::Integer3:
case Stream::Integer4:
return new BrookIntStreamImpl( name, size, type, platform );
break;
}
std::stringstream message;
message << methodName << " type=" << type << " for stream=" << name << " is invalid.";
throw OpenMMException( message.str() );
}
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