2011-12-03 00:02:36 +08:00
|
|
|
/***************************************************************************
|
|
|
|
re_squared.cpp
|
|
|
|
-------------------
|
|
|
|
W. Michael Brown
|
|
|
|
|
|
|
|
Host code for RE-Squared potential acceleration
|
|
|
|
|
|
|
|
__________________________________________________________________________
|
|
|
|
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
|
|
|
|
__________________________________________________________________________
|
|
|
|
|
|
|
|
begin : Fri May 06 2011
|
|
|
|
email : brownw@ornl.gov
|
|
|
|
***************************************************************************/
|
|
|
|
|
2012-08-21 21:57:32 +08:00
|
|
|
#if defined(USE_OPENCL)
|
2011-12-03 00:02:36 +08:00
|
|
|
#include "re_squared_cl.h"
|
|
|
|
#include "re_squared_lj_cl.h"
|
2012-08-21 21:57:32 +08:00
|
|
|
#elif defined(USE_CUDART)
|
|
|
|
const char *re_squared=0;
|
|
|
|
const char *re_squared_lj=0;
|
2011-12-03 00:02:36 +08:00
|
|
|
#else
|
2012-08-21 21:57:32 +08:00
|
|
|
#include "re_squared_cubin.h"
|
|
|
|
#include "re_squared_lj_cubin.h"
|
2011-12-03 00:02:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lal_re_squared.h"
|
|
|
|
#include <cassert>
|
2019-07-13 03:42:16 +08:00
|
|
|
namespace LAMMPS_AL {
|
2011-12-03 00:02:36 +08:00
|
|
|
|
|
|
|
#define RESquaredT RESquared<numtyp, acctyp>
|
|
|
|
extern Device<PRECISION,ACC_PRECISION> device;
|
|
|
|
|
|
|
|
template <class numtyp, class acctyp>
|
|
|
|
RESquaredT::RESquared() : BaseEllipsoid<numtyp,acctyp>(),
|
|
|
|
_allocated(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class numtyp, class acctyp>
|
2016-07-02 07:27:26 +08:00
|
|
|
RESquaredT::~RESquared() {
|
2011-12-03 00:02:36 +08:00
|
|
|
clear();
|
|
|
|
}
|
2016-07-02 07:27:26 +08:00
|
|
|
|
2011-12-03 00:02:36 +08:00
|
|
|
template <class numtyp, class acctyp>
|
|
|
|
int RESquaredT::bytes_per_atom(const int max_nbors) const {
|
|
|
|
return this->bytes_per_atom(max_nbors);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class numtyp, class acctyp>
|
2016-07-02 07:27:26 +08:00
|
|
|
int RESquaredT::init(const int ntypes, double **host_shape, double **host_well,
|
|
|
|
double **host_cutsq, double **host_sigma,
|
2011-12-03 00:02:36 +08:00
|
|
|
double **host_epsilon, int **h_form, double **host_lj1,
|
|
|
|
double **host_lj2, double **host_lj3, double **host_lj4,
|
|
|
|
double **host_offset, const double *host_special_lj,
|
|
|
|
const int nlocal, const int nall, const int max_nbors,
|
|
|
|
const int maxspecial, const double cell_size,
|
|
|
|
const double gpu_split, FILE *_screen) {
|
|
|
|
int success;
|
|
|
|
success=this->init_base(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
|
2012-08-21 21:57:32 +08:00
|
|
|
_screen,ntypes,h_form,re_squared,re_squared_lj,
|
|
|
|
"k_resquared",true);
|
2011-12-03 00:02:36 +08:00
|
|
|
if (success!=0)
|
|
|
|
return success;
|
|
|
|
|
|
|
|
// If atom type constants fit in shared memory use fast kernel
|
|
|
|
int lj_types=ntypes;
|
|
|
|
_shared_types=false;
|
|
|
|
int max_shared_types=this->device->max_shared_types();
|
|
|
|
if (lj_types<=max_shared_types && this->block_size()>=max_shared_types) {
|
|
|
|
lj_types=max_shared_types;
|
|
|
|
_shared_types=true;
|
|
|
|
}
|
|
|
|
_lj_types=lj_types;
|
|
|
|
|
|
|
|
// Allocate a host write buffer for copying type data
|
|
|
|
UCL_H_Vec<numtyp> host_write(lj_types*lj_types*32,*(this->ucl_device),
|
2013-08-23 22:41:20 +08:00
|
|
|
UCL_WRITE_ONLY);
|
2011-12-03 00:02:36 +08:00
|
|
|
|
|
|
|
for (int i=0; i<lj_types*lj_types; i++)
|
|
|
|
host_write[i]=0.0;
|
|
|
|
|
|
|
|
sigma_epsilon.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
|
|
|
|
this->atom->type_pack2(ntypes,lj_types,sigma_epsilon,host_write,
|
2016-07-02 07:27:26 +08:00
|
|
|
host_sigma,host_epsilon);
|
2011-12-03 00:02:36 +08:00
|
|
|
|
|
|
|
this->cut_form.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
|
|
|
|
this->atom->type_pack2(ntypes,lj_types,this->cut_form,host_write,
|
2016-07-02 07:27:26 +08:00
|
|
|
host_cutsq,h_form);
|
2011-12-03 00:02:36 +08:00
|
|
|
|
|
|
|
lj1.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
|
|
|
|
this->atom->type_pack4(ntypes,lj_types,lj1,host_write,host_lj1,host_lj2,
|
2016-07-02 07:27:26 +08:00
|
|
|
host_cutsq,h_form);
|
2011-12-03 00:02:36 +08:00
|
|
|
|
|
|
|
lj3.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
|
|
|
|
this->atom->type_pack4(ntypes,lj_types,lj3,host_write,host_lj3,host_lj4,
|
2016-07-02 07:27:26 +08:00
|
|
|
host_offset);
|
2011-12-03 00:02:36 +08:00
|
|
|
|
2013-08-23 22:41:20 +08:00
|
|
|
dev_error.alloc(1,*(this->ucl_device),UCL_WRITE_ONLY);
|
2011-12-03 00:02:36 +08:00
|
|
|
dev_error.zero();
|
2016-07-02 07:27:26 +08:00
|
|
|
|
2011-12-03 00:02:36 +08:00
|
|
|
// Allocate, cast and asynchronous memcpy of constant data
|
|
|
|
// Copy data for bonded interactions
|
|
|
|
special_lj.alloc(4,*(this->ucl_device),UCL_READ_ONLY);
|
|
|
|
host_write[0]=static_cast<numtyp>(host_special_lj[0]);
|
|
|
|
host_write[1]=static_cast<numtyp>(host_special_lj[1]);
|
|
|
|
host_write[2]=static_cast<numtyp>(host_special_lj[2]);
|
|
|
|
host_write[3]=static_cast<numtyp>(host_special_lj[3]);
|
|
|
|
ucl_copy(special_lj,host_write,4,false);
|
|
|
|
|
|
|
|
// Copy shape, well, sigma, epsilon, and cutsq onto GPU
|
|
|
|
// - cast if necessary
|
|
|
|
shape.alloc(ntypes,*(this->ucl_device),UCL_READ_ONLY);
|
|
|
|
for (int i=0; i<ntypes; i++) {
|
|
|
|
host_write[i*4]=host_shape[i][0];
|
|
|
|
host_write[i*4+1]=host_shape[i][1];
|
|
|
|
host_write[i*4+2]=host_shape[i][2];
|
|
|
|
}
|
|
|
|
UCL_H_Vec<numtyp4> view4;
|
|
|
|
view4.view((numtyp4*)host_write.begin(),shape.numel(),*(this->ucl_device));
|
|
|
|
ucl_copy(shape,view4,false);
|
|
|
|
|
|
|
|
well.alloc(ntypes,*(this->ucl_device),UCL_READ_ONLY);
|
|
|
|
for (int i=0; i<ntypes; i++) {
|
|
|
|
host_write[i*4]=host_well[i][0];
|
|
|
|
host_write[i*4+1]=host_well[i][1];
|
|
|
|
host_write[i*4+2]=host_well[i][2];
|
|
|
|
}
|
|
|
|
view4.view((numtyp4*)host_write.begin(),well.numel(),*(this->ucl_device));
|
|
|
|
ucl_copy(well,view4,false);
|
2016-07-02 07:27:26 +08:00
|
|
|
|
2011-12-03 00:02:36 +08:00
|
|
|
_allocated=true;
|
|
|
|
this->_max_bytes=sigma_epsilon.row_bytes()+this->cut_form.row_bytes()+
|
|
|
|
lj1.row_bytes()+lj3.row_bytes()+special_lj.row_bytes()+
|
|
|
|
shape.row_bytes()+well.row_bytes();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class numtyp, class acctyp>
|
|
|
|
void RESquaredT::clear() {
|
|
|
|
if (!_allocated)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UCL_H_Vec<int> err_flag(1,*(this->ucl_device));
|
|
|
|
ucl_copy(err_flag,dev_error,false);
|
|
|
|
if (err_flag[0] == 2)
|
2016-07-02 07:27:26 +08:00
|
|
|
std::cerr << "BAD MATRIX INVERSION IN FORCE COMPUTATION.\n";
|
2011-12-03 00:02:36 +08:00
|
|
|
err_flag.clear();
|
|
|
|
|
|
|
|
_allocated=false;
|
|
|
|
|
|
|
|
dev_error.clear();
|
|
|
|
lj1.clear();
|
|
|
|
lj3.clear();
|
|
|
|
sigma_epsilon.clear();
|
|
|
|
this->cut_form.clear();
|
|
|
|
|
|
|
|
shape.clear();
|
|
|
|
well.clear();
|
|
|
|
special_lj.clear();
|
2016-07-02 07:27:26 +08:00
|
|
|
|
2011-12-03 00:02:36 +08:00
|
|
|
this->clear_base();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class numtyp, class acctyp>
|
|
|
|
double RESquaredT::host_memory_usage() const {
|
|
|
|
return this->host_memory_usage_base()+sizeof(RESquaredT)+
|
|
|
|
4*sizeof(numtyp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Calculate energies, forces, and torques
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
template <class numtyp, class acctyp>
|
|
|
|
void RESquaredT::loop(const bool _eflag, const bool _vflag) {
|
|
|
|
const int BX=this->block_size();
|
|
|
|
int eflag, vflag;
|
|
|
|
if (_eflag)
|
|
|
|
eflag=1;
|
|
|
|
else
|
|
|
|
eflag=0;
|
|
|
|
|
|
|
|
if (_vflag)
|
|
|
|
vflag=1;
|
|
|
|
else
|
|
|
|
vflag=0;
|
2016-07-02 07:27:26 +08:00
|
|
|
|
2011-12-03 00:02:36 +08:00
|
|
|
int GX=0, NGX;
|
|
|
|
int stride=this->nbor->nbor_pitch();
|
|
|
|
int ainum=this->ans->inum();
|
|
|
|
|
|
|
|
if (this->_multiple_forms) {
|
|
|
|
if (this->_last_ellipse>0) {
|
|
|
|
// ------------ ELLIPSE_ELLIPSE ---------------
|
|
|
|
this->time_nbor1.start();
|
|
|
|
GX=static_cast<int>(ceil(static_cast<double>(this->_last_ellipse)/
|
|
|
|
(BX/this->_threads_per_atom)));
|
|
|
|
NGX=static_cast<int>(ceil(static_cast<double>(this->_last_ellipse)/BX));
|
|
|
|
this->pack_nbors(NGX,BX, 0, this->_last_ellipse,ELLIPSE_ELLIPSE,
|
2016-07-02 07:27:26 +08:00
|
|
|
ELLIPSE_ELLIPSE,_shared_types,_lj_types);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_nbor1.stop();
|
|
|
|
|
|
|
|
this->time_ellipsoid.start();
|
|
|
|
this->k_ellipsoid.set_size(GX,BX);
|
2012-08-21 21:57:32 +08:00
|
|
|
this->k_ellipsoid.run(&this->atom->x, &this->atom->quat,
|
|
|
|
&this->shape, &this->well, &this->special_lj,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->sigma_epsilon, &this->_lj_types,
|
|
|
|
&this->nbor->dev_nbor, &stride,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->ans->force,&ainum, &this->ans->engv,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->dev_error, &eflag, &vflag,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->_last_ellipse, &this->_threads_per_atom);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_ellipsoid.stop();
|
|
|
|
|
|
|
|
// ------------ ELLIPSE_SPHERE ---------------
|
|
|
|
this->time_nbor2.start();
|
|
|
|
this->pack_nbors(NGX,BX, 0, this->_last_ellipse,ELLIPSE_SPHERE,
|
2016-07-02 07:27:26 +08:00
|
|
|
ELLIPSE_SPHERE,_shared_types,_lj_types);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_nbor2.stop();
|
|
|
|
|
|
|
|
this->time_ellipsoid2.start();
|
|
|
|
this->k_ellipsoid_sphere.set_size(GX,BX);
|
2016-07-02 07:27:26 +08:00
|
|
|
this->k_ellipsoid_sphere.run(&this->atom->x, &this->atom->quat,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->shape, &this->well, &this->special_lj,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->sigma_epsilon, &this->_lj_types,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->nbor->dev_nbor, &stride,
|
|
|
|
&this->ans->force,&ainum,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->ans->engv, &this->dev_error,
|
2012-08-21 21:57:32 +08:00
|
|
|
&eflag, &vflag, &this->_last_ellipse,
|
|
|
|
&this->_threads_per_atom);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_ellipsoid2.stop();
|
|
|
|
|
|
|
|
if (this->_last_ellipse==this->ans->inum()) {
|
|
|
|
this->time_nbor3.zero();
|
|
|
|
this->time_ellipsoid3.zero();
|
|
|
|
this->time_lj.zero();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------ SPHERE_ELLIPSE ---------------
|
|
|
|
|
|
|
|
this->time_nbor3.start();
|
|
|
|
GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum()-
|
|
|
|
this->_last_ellipse)/
|
|
|
|
(BX/this->_threads_per_atom)));
|
|
|
|
NGX=static_cast<int>(ceil(static_cast<double>(this->ans->inum()-
|
|
|
|
this->_last_ellipse)/BX));
|
|
|
|
this->pack_nbors(NGX,BX,this->_last_ellipse,this->ans->inum(),
|
2016-07-02 07:27:26 +08:00
|
|
|
SPHERE_ELLIPSE,SPHERE_ELLIPSE,_shared_types,_lj_types);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_nbor3.stop();
|
|
|
|
|
|
|
|
this->time_ellipsoid3.start();
|
|
|
|
this->k_sphere_ellipsoid.set_size(GX,BX);
|
2012-08-21 21:57:32 +08:00
|
|
|
this->k_sphere_ellipsoid.run(&this->atom->x, &this->atom->quat,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->shape, &this->well, &this->special_lj,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->sigma_epsilon, &this->_lj_types,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->nbor->dev_nbor, &stride,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->ans->force, &this->ans->engv,
|
|
|
|
&this->dev_error, &eflag, &vflag,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->_last_ellipse, &ainum,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->_threads_per_atom);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_ellipsoid3.stop();
|
|
|
|
} else {
|
2013-08-23 22:41:20 +08:00
|
|
|
GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum()-
|
|
|
|
this->_last_ellipse)/
|
|
|
|
(BX/this->_threads_per_atom)));
|
2012-08-21 21:57:32 +08:00
|
|
|
this->ans->force.zero();
|
|
|
|
this->ans->engv.zero();
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_nbor1.zero();
|
2016-07-02 07:27:26 +08:00
|
|
|
this->time_ellipsoid.zero();
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_nbor2.zero();
|
|
|
|
this->time_ellipsoid2.zero();
|
|
|
|
this->time_nbor3.zero();
|
|
|
|
this->time_ellipsoid3.zero();
|
|
|
|
}
|
2016-07-02 07:27:26 +08:00
|
|
|
|
2011-12-03 00:02:36 +08:00
|
|
|
// ------------ LJ ---------------
|
|
|
|
this->time_lj.start();
|
|
|
|
if (this->_last_ellipse<this->ans->inum()) {
|
|
|
|
if (this->_shared_types) {
|
|
|
|
this->k_lj_fast.set_size(GX,BX);
|
2012-08-21 21:57:32 +08:00
|
|
|
this->k_lj_fast.run(&this->atom->x, &this->lj1, &this->lj3,
|
|
|
|
&this->special_lj, &stride,
|
|
|
|
&this->nbor->dev_packed, &this->ans->force,
|
|
|
|
&this->ans->engv, &this->dev_error,
|
|
|
|
&eflag, &vflag, &this->_last_ellipse, &ainum,
|
|
|
|
&this->_threads_per_atom);
|
2011-12-03 00:02:36 +08:00
|
|
|
} else {
|
|
|
|
this->k_lj.set_size(GX,BX);
|
2012-08-21 21:57:32 +08:00
|
|
|
this->k_lj.run(&this->atom->x, &this->lj1, &this->lj3,
|
2016-07-02 07:27:26 +08:00
|
|
|
&this->_lj_types, &this->special_lj, &stride,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->nbor->dev_packed, &this->ans->force,
|
|
|
|
&this->ans->engv, &this->dev_error, &eflag, &vflag,
|
|
|
|
&this->_last_ellipse, &ainum, &this->_threads_per_atom);
|
2011-12-03 00:02:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this->time_lj.stop();
|
|
|
|
} else {
|
|
|
|
GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/
|
|
|
|
(BX/this->_threads_per_atom)));
|
|
|
|
NGX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/BX));
|
|
|
|
this->time_nbor1.start();
|
|
|
|
this->pack_nbors(NGX, BX, 0, this->ans->inum(),SPHERE_SPHERE,
|
2016-07-02 07:27:26 +08:00
|
|
|
ELLIPSE_ELLIPSE,_shared_types,_lj_types);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_nbor1.stop();
|
2016-07-02 07:27:26 +08:00
|
|
|
this->time_ellipsoid.start();
|
2011-12-03 00:02:36 +08:00
|
|
|
this->k_ellipsoid.set_size(GX,BX);
|
2016-07-02 07:27:26 +08:00
|
|
|
this->k_ellipsoid.run(&this->atom->x, &this->atom->quat,
|
|
|
|
&this->shape, &this->well, &this->special_lj,
|
|
|
|
&this->sigma_epsilon, &this->_lj_types,
|
2012-08-21 21:57:32 +08:00
|
|
|
&this->nbor->dev_nbor, &stride, &this->ans->force,
|
2016-07-02 07:27:26 +08:00
|
|
|
&ainum, &this->ans->engv, &this->dev_error,
|
2012-08-21 21:57:32 +08:00
|
|
|
&eflag, &vflag, &ainum, &this->_threads_per_atom);
|
2011-12-03 00:02:36 +08:00
|
|
|
this->time_ellipsoid.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template class RESquared<PRECISION,ACC_PRECISION>;
|
2019-07-13 03:42:16 +08:00
|
|
|
}
|