forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@11231 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
bbffbe06a2
commit
496746e338
|
@ -0,0 +1,164 @@
|
||||||
|
/***************************************************************************
|
||||||
|
lj_gromacs.cpp
|
||||||
|
-------------------
|
||||||
|
Trung Dac Nguyen (ORNL)
|
||||||
|
|
||||||
|
Class for acceleration of the lj/gromacs pair style.
|
||||||
|
|
||||||
|
__________________________________________________________________________
|
||||||
|
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
|
||||||
|
__________________________________________________________________________
|
||||||
|
|
||||||
|
begin :
|
||||||
|
email : nguyentd@ornl.gov
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#if defined(USE_OPENCL)
|
||||||
|
#include "lj_gromacs_cl.h"
|
||||||
|
#elif defined(USE_CUDART)
|
||||||
|
const char *lj_gromacs=0;
|
||||||
|
#else
|
||||||
|
#include "lj_gromacs_cubin.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "lal_lj_gromacs.h"
|
||||||
|
#include <cassert>
|
||||||
|
using namespace LAMMPS_AL;
|
||||||
|
#define LJGROMACST LJGROMACS<numtyp, acctyp>
|
||||||
|
|
||||||
|
extern Device<PRECISION,ACC_PRECISION> device;
|
||||||
|
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
LJGROMACST::LJGROMACS() : BaseAtomic<numtyp,acctyp>(),
|
||||||
|
_allocated(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
LJGROMACST::~LJGROMACS() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
int LJGROMACST::bytes_per_atom(const int max_nbors) const {
|
||||||
|
return this->bytes_per_atom_atomic(max_nbors);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
int LJGROMACST::init(const int ntypes, double **host_cutsq,
|
||||||
|
double **host_lj1, double **host_lj2, double **host_lj3,
|
||||||
|
double **host_lj4, 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,
|
||||||
|
double **host_ljsw1, double **host_ljsw2, double **host_ljsw3,
|
||||||
|
double **host_ljsw4, double **host_ljsw5,
|
||||||
|
double **cut_inner, double **cut_inner_sq) {
|
||||||
|
int success;
|
||||||
|
success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
|
||||||
|
_screen,lj_gromacs,"k_lj_gromacs");
|
||||||
|
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 data initialization
|
||||||
|
UCL_H_Vec<numtyp> host_write(lj_types*lj_types*32,*(this->ucl_device),
|
||||||
|
UCL_WRITE_ONLY);
|
||||||
|
|
||||||
|
for (int i=0; i<lj_types*lj_types; i++)
|
||||||
|
host_write[i]=0.0;
|
||||||
|
|
||||||
|
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,
|
||||||
|
host_cutsq,cut_inner_sq);
|
||||||
|
|
||||||
|
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,
|
||||||
|
cut_inner,host_ljsw5);
|
||||||
|
|
||||||
|
ljsw.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
|
||||||
|
this->atom->type_pack4(ntypes,lj_types,ljsw,host_write,host_ljsw1,host_ljsw2,
|
||||||
|
host_ljsw3,host_ljsw4);
|
||||||
|
|
||||||
|
UCL_H_Vec<double> dview;
|
||||||
|
sp_lj.alloc(4,*(this->ucl_device),UCL_READ_ONLY);
|
||||||
|
dview.view(host_special_lj,4,*(this->ucl_device));
|
||||||
|
ucl_copy(sp_lj,dview,false);
|
||||||
|
|
||||||
|
_allocated=true;
|
||||||
|
this->_max_bytes=lj1.row_bytes()+lj3.row_bytes()
|
||||||
|
+ljsw.row_bytes()+sp_lj.row_bytes();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
void LJGROMACST::clear() {
|
||||||
|
if (!_allocated)
|
||||||
|
return;
|
||||||
|
_allocated=false;
|
||||||
|
|
||||||
|
lj1.clear();
|
||||||
|
lj3.clear();
|
||||||
|
ljsw.clear();
|
||||||
|
sp_lj.clear();
|
||||||
|
this->clear_atomic();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
double LJGROMACST::host_memory_usage() const {
|
||||||
|
return this->host_memory_usage_atomic()+sizeof(LJGROMACS<numtyp,acctyp>);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Calculate energies, forces, and torques
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
void LJGROMACST::loop(const bool _eflag, const bool _vflag) {
|
||||||
|
// Compute the block size and grid size to keep all cores busy
|
||||||
|
const int BX=this->block_size();
|
||||||
|
int eflag, vflag;
|
||||||
|
if (_eflag)
|
||||||
|
eflag=1;
|
||||||
|
else
|
||||||
|
eflag=0;
|
||||||
|
|
||||||
|
if (_vflag)
|
||||||
|
vflag=1;
|
||||||
|
else
|
||||||
|
vflag=0;
|
||||||
|
|
||||||
|
int GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/
|
||||||
|
(BX/this->_threads_per_atom)));
|
||||||
|
|
||||||
|
int ainum=this->ans->inum();
|
||||||
|
int nbor_pitch=this->nbor->nbor_pitch();
|
||||||
|
this->time_pair.start();
|
||||||
|
if (shared_types) {
|
||||||
|
this->k_pair_fast.set_size(GX,BX);
|
||||||
|
this->k_pair_fast.run(&this->atom->x, &lj1, &lj3, &ljsw,
|
||||||
|
&sp_lj, &this->nbor->dev_nbor,
|
||||||
|
&this->_nbor_data->begin(),
|
||||||
|
&this->ans->force, &this->ans->engv,
|
||||||
|
&eflag, &vflag, &ainum, &nbor_pitch,
|
||||||
|
&this->_threads_per_atom);
|
||||||
|
} else {
|
||||||
|
this->k_pair.set_size(GX,BX);
|
||||||
|
this->k_pair.run(&this->atom->x, &lj1, &lj3, &ljsw, &_lj_types,
|
||||||
|
&sp_lj, &this->nbor->dev_nbor,
|
||||||
|
&this->_nbor_data->begin(),
|
||||||
|
&this->ans->force, &this->ans->engv,
|
||||||
|
&eflag, &vflag, &ainum, &nbor_pitch,
|
||||||
|
&this->_threads_per_atom);
|
||||||
|
}
|
||||||
|
this->time_pair.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
template class LJGROMACS<PRECISION,ACC_PRECISION>;
|
|
@ -0,0 +1,233 @@
|
||||||
|
// **************************************************************************
|
||||||
|
// lj_gromacs.cu
|
||||||
|
// -------------------
|
||||||
|
// Trung Dac Nguyen (ORNL)
|
||||||
|
//
|
||||||
|
// Device code for acceleration of the gromacs/coul/long pair style
|
||||||
|
//
|
||||||
|
// __________________________________________________________________________
|
||||||
|
// This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
|
||||||
|
// __________________________________________________________________________
|
||||||
|
//
|
||||||
|
// begin :
|
||||||
|
// email : nguyentd@ornl.gov
|
||||||
|
// ***************************************************************************/
|
||||||
|
|
||||||
|
#ifdef NV_KERNEL
|
||||||
|
|
||||||
|
#include "lal_aux_fun1.h"
|
||||||
|
#ifndef _DOUBLE_DOUBLE
|
||||||
|
texture<float4> pos_tex;
|
||||||
|
#else
|
||||||
|
texture<int4,1> pos_tex;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define pos_tex x_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__kernel void k_lj_gromacs(const __global numtyp4 *restrict x_,
|
||||||
|
const __global numtyp4 *restrict lj1,
|
||||||
|
const __global numtyp4 *restrict lj3,
|
||||||
|
const __global numtyp4 *restrict ljsw,
|
||||||
|
const int lj_types,
|
||||||
|
const __global numtyp *restrict sp_lj_in,
|
||||||
|
const __global int *dev_nbor,
|
||||||
|
const __global int *dev_packed,
|
||||||
|
__global acctyp4 *restrict ans,
|
||||||
|
__global acctyp *restrict engv,
|
||||||
|
const int eflag, const int vflag, const int inum,
|
||||||
|
const int nbor_pitch, const int t_per_atom) {
|
||||||
|
int tid, ii, offset;
|
||||||
|
atom_info(t_per_atom,ii,tid,offset);
|
||||||
|
|
||||||
|
__local numtyp sp_lj[4];
|
||||||
|
sp_lj[0]=sp_lj_in[0];
|
||||||
|
sp_lj[1]=sp_lj_in[1];
|
||||||
|
sp_lj[2]=sp_lj_in[2];
|
||||||
|
sp_lj[3]=sp_lj_in[3];
|
||||||
|
|
||||||
|
acctyp energy=(acctyp)0;
|
||||||
|
acctyp4 f;
|
||||||
|
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
|
||||||
|
acctyp virial[6];
|
||||||
|
for (int i=0; i<6; i++)
|
||||||
|
virial[i]=(acctyp)0;
|
||||||
|
|
||||||
|
if (ii<inum) {
|
||||||
|
const __global int *nbor, *list_end;
|
||||||
|
int i, numj;
|
||||||
|
__local int n_stride;
|
||||||
|
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
|
||||||
|
n_stride,list_end,nbor);
|
||||||
|
|
||||||
|
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
|
||||||
|
int itype=ix.w;
|
||||||
|
|
||||||
|
numtyp factor_lj;
|
||||||
|
for ( ; nbor<list_end; nbor+=n_stride) {
|
||||||
|
|
||||||
|
int j=*nbor;
|
||||||
|
factor_lj = sp_lj[sbmask(j)];
|
||||||
|
j &= NEIGHMASK;
|
||||||
|
|
||||||
|
numtyp4 jx; fetch4(jx,j,pos_tex); //x_[j];
|
||||||
|
int jtype=jx.w;
|
||||||
|
|
||||||
|
// Compute r12
|
||||||
|
numtyp delx = ix.x-jx.x;
|
||||||
|
numtyp dely = ix.y-jx.y;
|
||||||
|
numtyp delz = ix.z-jx.z;
|
||||||
|
numtyp rsq = delx*delx+dely*dely+delz*delz;
|
||||||
|
|
||||||
|
int mtype=itype*lj_types+jtype;
|
||||||
|
if (rsq<lj1[mtype].z) {
|
||||||
|
numtyp r2inv=ucl_recip(rsq);
|
||||||
|
numtyp force_lj, force, r6inv, t;
|
||||||
|
|
||||||
|
r6inv = r2inv*r2inv*r2inv;
|
||||||
|
force_lj = r6inv*(lj1[mtype].x*r6inv-lj1[mtype].y);
|
||||||
|
if (rsq > lj1[mtype].w) {
|
||||||
|
numtyp r = ucl_sqrt(rsq);
|
||||||
|
t = r - lj3[mtype].z;
|
||||||
|
numtyp fswitch = r*t*t*(ljsw[mtype].x + ljsw[mtype].y*t);
|
||||||
|
force_lj += fswitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
force = factor_lj*force_lj * r2inv;
|
||||||
|
|
||||||
|
f.x+=delx*force;
|
||||||
|
f.y+=dely*force;
|
||||||
|
f.z+=delz*force;
|
||||||
|
|
||||||
|
if (eflag>0) {
|
||||||
|
numtyp e=r6inv*(lj3[mtype].x*r6inv-lj3[mtype].y);
|
||||||
|
e += lj3[mtype].w;
|
||||||
|
if (rsq > lj1[mtype].w) {
|
||||||
|
numtyp eswitch = t*t*t*(ljsw[mtype].z + ljsw[mtype].w*t);
|
||||||
|
e += eswitch;
|
||||||
|
}
|
||||||
|
energy+=factor_lj*e;
|
||||||
|
}
|
||||||
|
if (vflag>0) {
|
||||||
|
virial[0] += delx*delx*force;
|
||||||
|
virial[1] += dely*dely*force;
|
||||||
|
virial[2] += delz*delz*force;
|
||||||
|
virial[3] += delx*dely*force;
|
||||||
|
virial[4] += delx*delz*force;
|
||||||
|
virial[5] += dely*delz*force;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // for nbor
|
||||||
|
store_answers(f,energy,virial,ii,inum,tid,t_per_atom,offset,eflag,
|
||||||
|
vflag,ans,engv);
|
||||||
|
} // if ii
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void k_lj_gromacs_fast(const __global numtyp4 *restrict x_,
|
||||||
|
const __global numtyp4 *restrict lj1_in,
|
||||||
|
const __global numtyp4 *restrict lj3_in,
|
||||||
|
const __global numtyp4 *restrict ljsw_in,
|
||||||
|
const __global numtyp *restrict sp_lj_in,
|
||||||
|
const __global int *dev_nbor,
|
||||||
|
const __global int *dev_packed,
|
||||||
|
__global acctyp4 *restrict ans,
|
||||||
|
__global acctyp *restrict engv,
|
||||||
|
const int eflag, const int vflag, const int inum,
|
||||||
|
const int nbor_pitch, const int t_per_atom) {
|
||||||
|
int tid, ii, offset;
|
||||||
|
atom_info(t_per_atom,ii,tid,offset);
|
||||||
|
|
||||||
|
__local numtyp4 lj1[MAX_SHARED_TYPES*MAX_SHARED_TYPES];
|
||||||
|
__local numtyp4 lj3[MAX_SHARED_TYPES*MAX_SHARED_TYPES];
|
||||||
|
__local numtyp4 ljsw[MAX_SHARED_TYPES*MAX_SHARED_TYPES];
|
||||||
|
__local numtyp sp_lj[4];
|
||||||
|
if (tid<4)
|
||||||
|
sp_lj[tid]=sp_lj_in[tid];
|
||||||
|
if (tid<MAX_SHARED_TYPES*MAX_SHARED_TYPES) {
|
||||||
|
lj1[tid]=lj1_in[tid];
|
||||||
|
lj3[tid]=lj3_in[tid];
|
||||||
|
ljsw[tid]=ljsw_in[tid];
|
||||||
|
}
|
||||||
|
|
||||||
|
acctyp energy=(acctyp)0;
|
||||||
|
acctyp4 f;
|
||||||
|
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
|
||||||
|
acctyp virial[6];
|
||||||
|
for (int i=0; i<6; i++)
|
||||||
|
virial[i]=(acctyp)0;
|
||||||
|
|
||||||
|
__syncthreads();
|
||||||
|
|
||||||
|
if (ii<inum) {
|
||||||
|
const __global int *nbor, *list_end;
|
||||||
|
int i, numj;
|
||||||
|
__local int n_stride;
|
||||||
|
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
|
||||||
|
n_stride,list_end,nbor);
|
||||||
|
|
||||||
|
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
|
||||||
|
int iw=ix.w;
|
||||||
|
int itype=fast_mul((int)MAX_SHARED_TYPES,iw);
|
||||||
|
|
||||||
|
numtyp factor_lj;
|
||||||
|
for ( ; nbor<list_end; nbor+=n_stride) {
|
||||||
|
|
||||||
|
int j=*nbor;
|
||||||
|
factor_lj = sp_lj[sbmask(j)];
|
||||||
|
j &= NEIGHMASK;
|
||||||
|
|
||||||
|
numtyp4 jx; fetch4(jx,j,pos_tex); //x_[j];
|
||||||
|
int mtype=itype+jx.w;
|
||||||
|
|
||||||
|
// Compute r12
|
||||||
|
numtyp delx = ix.x-jx.x;
|
||||||
|
numtyp dely = ix.y-jx.y;
|
||||||
|
numtyp delz = ix.z-jx.z;
|
||||||
|
numtyp rsq = delx*delx+dely*dely+delz*delz;
|
||||||
|
|
||||||
|
if (rsq<lj1[mtype].z) {
|
||||||
|
numtyp r2inv=ucl_recip(rsq);
|
||||||
|
numtyp force_lj, force, r6inv, t;
|
||||||
|
|
||||||
|
r6inv = r2inv*r2inv*r2inv;
|
||||||
|
force_lj = r6inv*(lj1[mtype].x*r6inv-lj1[mtype].y);
|
||||||
|
if (rsq > lj1[mtype].w) {
|
||||||
|
numtyp r = ucl_sqrt(rsq);
|
||||||
|
t = r - lj3[mtype].z;
|
||||||
|
numtyp fswitch = r*t*t*(ljsw[mtype].x + ljsw[mtype].y*t);
|
||||||
|
force_lj += fswitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
force = factor_lj*force_lj * r2inv;
|
||||||
|
|
||||||
|
f.x+=delx*force;
|
||||||
|
f.y+=dely*force;
|
||||||
|
f.z+=delz*force;
|
||||||
|
|
||||||
|
if (eflag>0) {
|
||||||
|
numtyp e=r6inv*(lj3[mtype].x*r6inv-lj3[mtype].y);
|
||||||
|
e += lj3[mtype].w;
|
||||||
|
if (rsq > lj1[mtype].w) {
|
||||||
|
numtyp eswitch = t*t*t*(ljsw[mtype].z + ljsw[mtype].w*t);
|
||||||
|
e += eswitch;
|
||||||
|
}
|
||||||
|
energy+=factor_lj*e;
|
||||||
|
}
|
||||||
|
if (vflag>0) {
|
||||||
|
virial[0] += delx*delx*force;
|
||||||
|
virial[1] += dely*dely*force;
|
||||||
|
virial[2] += delz*delz*force;
|
||||||
|
virial[3] += delx*dely*force;
|
||||||
|
virial[4] += delx*delz*force;
|
||||||
|
virial[5] += dely*delz*force;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // for nbor
|
||||||
|
store_answers(f,energy,virial,ii,inum,tid,t_per_atom,offset,eflag,
|
||||||
|
vflag,ans,engv);
|
||||||
|
} // if ii
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
/***************************************************************************
|
||||||
|
lj_gromacs.h
|
||||||
|
-------------------
|
||||||
|
Trung Dac Nguyen (ORNL)
|
||||||
|
|
||||||
|
Class for acceleration of the lj/gromacs pair style.
|
||||||
|
|
||||||
|
__________________________________________________________________________
|
||||||
|
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
|
||||||
|
__________________________________________________________________________
|
||||||
|
|
||||||
|
begin :
|
||||||
|
email : nguyentd@ornl.gov
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LAL_LJ_GROMACS_H
|
||||||
|
#define LAL_LJ_GROMACS_H
|
||||||
|
|
||||||
|
#include "lal_base_atomic.h"
|
||||||
|
|
||||||
|
namespace LAMMPS_AL {
|
||||||
|
|
||||||
|
template <class numtyp, class acctyp>
|
||||||
|
class LJGROMACS : public BaseAtomic<numtyp, acctyp> {
|
||||||
|
public:
|
||||||
|
LJGROMACS();
|
||||||
|
~LJGROMACS();
|
||||||
|
|
||||||
|
/// Clear any previous data and set up for a new LAMMPS run
|
||||||
|
/** \param max_nbors initial number of rows in the neighbor matrix
|
||||||
|
* \param cell_size cutoff + skin
|
||||||
|
* \param gpu_split fraction of particles handled by device
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* - 0 if successfull
|
||||||
|
* - -1 if fix gpu not found
|
||||||
|
* - -3 if there is an out of memory error
|
||||||
|
* - -4 if the GPU library was not compiled for GPU
|
||||||
|
* - -5 Double precision is not supported on card **/
|
||||||
|
int init(const int ntypes, double **host_cutsq,
|
||||||
|
double **host_lj1, double **host_lj2, double **host_lj3,
|
||||||
|
double **host_lj4, 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,
|
||||||
|
double **host_ljsw1, double **host_ljsw2, double **host_ljsw3,
|
||||||
|
double **host_ljsw4, double **host_ljsw5,
|
||||||
|
double **cut_inner, double **cut_inner_sq);
|
||||||
|
|
||||||
|
/// Clear all host and device data
|
||||||
|
/** \note This is called at the beginning of the init() routine **/
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/// Returns memory usage on device per atom
|
||||||
|
int bytes_per_atom(const int max_nbors) const;
|
||||||
|
|
||||||
|
/// Total host memory used by library for pair style
|
||||||
|
double host_memory_usage() const;
|
||||||
|
|
||||||
|
// --------------------------- TYPE DATA --------------------------
|
||||||
|
|
||||||
|
/// lj1.x = lj1, lj1.y = lj2, lj1.z = cutsq, lj1.w = cut_inner_sq
|
||||||
|
UCL_D_Vec<numtyp4> lj1;
|
||||||
|
/// lj3.x = lj3, lj3.y = lj4, lj3.z = cut_inner, lj3.w = ljsw5
|
||||||
|
UCL_D_Vec<numtyp4> lj3;
|
||||||
|
/// ljsw.x = ljsw1, ljsw.y = ljsw2, ljsw.z = ljsw3, ljsw.w = ljsw4
|
||||||
|
UCL_D_Vec<numtyp4> ljsw;
|
||||||
|
/// Special LJ values [0-3] and Special Coul values [4-7]
|
||||||
|
UCL_D_Vec<numtyp> sp_lj;
|
||||||
|
|
||||||
|
/// If atom type constants fit in shared memory, use fast kernels
|
||||||
|
bool shared_types;
|
||||||
|
|
||||||
|
/// Number of atom types
|
||||||
|
int _lj_types;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _allocated;
|
||||||
|
void loop(const bool _eflag, const bool _vflag);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,126 @@
|
||||||
|
/***************************************************************************
|
||||||
|
lj_gromacs_ext.cpp
|
||||||
|
-------------------
|
||||||
|
Trung Dac Nguyen (ORNL)
|
||||||
|
|
||||||
|
Functions for LAMMPS access to lj/gromacs acceleration routines.
|
||||||
|
|
||||||
|
__________________________________________________________________________
|
||||||
|
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
|
||||||
|
__________________________________________________________________________
|
||||||
|
|
||||||
|
begin :
|
||||||
|
email : nguyentd@ornl.gov
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "lal_lj_gromacs.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace LAMMPS_AL;
|
||||||
|
|
||||||
|
static LJGROMACS<PRECISION,ACC_PRECISION> LJGRMMF;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Allocate memory on host and device and copy constants to device
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
int ljgrm_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
|
||||||
|
double **host_lj2, double **host_lj3, double **host_lj4,
|
||||||
|
double *special_lj, const int inum,
|
||||||
|
const int nall, const int max_nbors, const int maxspecial,
|
||||||
|
const double cell_size, int &gpu_mode, FILE *screen,
|
||||||
|
double **host_ljsw1, double **host_ljsw2, double **host_ljsw3,
|
||||||
|
double **host_ljsw4, double **host_ljsw5,
|
||||||
|
double **cut_inner, double **cut_inner_sq) {
|
||||||
|
LJGRMMF.clear();
|
||||||
|
gpu_mode=LJGRMMF.device->gpu_mode();
|
||||||
|
double gpu_split=LJGRMMF.device->particle_split();
|
||||||
|
int first_gpu=LJGRMMF.device->first_device();
|
||||||
|
int last_gpu=LJGRMMF.device->last_device();
|
||||||
|
int world_me=LJGRMMF.device->world_me();
|
||||||
|
int gpu_rank=LJGRMMF.device->gpu_rank();
|
||||||
|
int procs_per_gpu=LJGRMMF.device->procs_per_gpu();
|
||||||
|
|
||||||
|
LJGRMMF.device->init_message(screen,"lj/gromacs",first_gpu,last_gpu);
|
||||||
|
|
||||||
|
bool message=false;
|
||||||
|
if (LJGRMMF.device->replica_me()==0 && screen)
|
||||||
|
message=true;
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
fprintf(screen,"Initializing GPU and compiling on process 0...");
|
||||||
|
fflush(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
int init_ok=0;
|
||||||
|
if (world_me==0)
|
||||||
|
LJGRMMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
|
||||||
|
special_lj, inum, nall, 300, maxspecial, cell_size,
|
||||||
|
gpu_split, screen, host_ljsw1, host_ljsw2, host_ljsw3,
|
||||||
|
host_ljsw4, host_ljsw5, cut_inner, cut_inner_sq);
|
||||||
|
|
||||||
|
LJGRMMF.device->world_barrier();
|
||||||
|
if (message)
|
||||||
|
fprintf(screen,"Done.\n");
|
||||||
|
|
||||||
|
for (int i=0; i<procs_per_gpu; i++) {
|
||||||
|
if (message) {
|
||||||
|
if (last_gpu-first_gpu==0)
|
||||||
|
fprintf(screen,"Initializing GPU %d on core %d...",first_gpu,i);
|
||||||
|
else
|
||||||
|
fprintf(screen,"Initializing GPUs %d-%d on core %d...",first_gpu,
|
||||||
|
last_gpu,i);
|
||||||
|
fflush(screen);
|
||||||
|
}
|
||||||
|
if (gpu_rank==i && world_me!=0)
|
||||||
|
init_ok=LJGRMMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
|
||||||
|
special_lj, inum, nall, 300, maxspecial, cell_size,
|
||||||
|
gpu_split, screen, host_ljsw1, host_ljsw2, host_ljsw3,
|
||||||
|
host_ljsw4, host_ljsw5, cut_inner, cut_inner_sq);
|
||||||
|
|
||||||
|
LJGRMMF.device->gpu_barrier();
|
||||||
|
if (message)
|
||||||
|
fprintf(screen,"Done.\n");
|
||||||
|
}
|
||||||
|
if (message)
|
||||||
|
fprintf(screen,"\n");
|
||||||
|
|
||||||
|
if (init_ok==0)
|
||||||
|
LJGRMMF.estimate_gpu_overhead();
|
||||||
|
return init_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ljgrm_gpu_clear() {
|
||||||
|
LJGRMMF.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ** ljgrm_gpu_compute_n(const int ago, const int inum_full,
|
||||||
|
const int nall, double **host_x, int *host_type,
|
||||||
|
double *sublo, double *subhi, int *tag, int **nspecial,
|
||||||
|
int **special, const bool eflag, const bool vflag,
|
||||||
|
const bool eatom, const bool vatom, int &host_start,
|
||||||
|
int **ilist, int **jnum, const double cpu_time,
|
||||||
|
bool &success) {
|
||||||
|
return LJGRMMF.compute(ago, inum_full, nall, host_x, host_type, sublo,
|
||||||
|
subhi, tag, nspecial, special, eflag, vflag, eatom,
|
||||||
|
vatom, host_start, ilist, jnum, cpu_time, success);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ljgrm_gpu_compute(const int ago, const int inum_full, const int nall,
|
||||||
|
double **host_x, int *host_type, int *ilist, int *numj,
|
||||||
|
int **firstneigh, const bool eflag, const bool vflag,
|
||||||
|
const bool eatom, const bool vatom, int &host_start,
|
||||||
|
const double cpu_time, bool &success) {
|
||||||
|
LJGRMMF.compute(ago,inum_full,nall,host_x,host_type,ilist,numj,
|
||||||
|
firstneigh,eflag,vflag,eatom,vatom,host_start,cpu_time,success);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double ljgrm_gpu_bytes() {
|
||||||
|
return LJGRMMF.host_memory_usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue