Added the GPU versions of lj/cut/coul/cut/soft and lj/cut/coul/long/soft

This commit is contained in:
Trung Nguyen
2023-12-05 13:30:26 -06:00
parent 8389e2eb80
commit 9588ddabf6
18 changed files with 2023 additions and 14 deletions

View File

@ -54,6 +54,6 @@ namespace ucl_opencl {
#include "ucl_print.h" #include "ucl_print.h"
#undef UCL_PRINT_ALLOW #undef UCL_PRINT_ALLOW
} // namespace ucl_cudart } // namespace ucl_opencl
#endif #endif

View File

@ -56,7 +56,8 @@ int BaseDPDT::init_atomic(const int nlocal, const int nall,
const int max_nbors, const int maxspecial, const int max_nbors, const int maxspecial,
const double cell_size, const double gpu_split, const double cell_size, const double gpu_split,
FILE *_screen, const void *pair_program, FILE *_screen, const void *pair_program,
const char *k_name, const int onetype) { const char *k_name, const int onetype,
const int extra_fields) {
screen=_screen; screen=_screen;
int gpu_nbor=0; int gpu_nbor=0;
@ -75,7 +76,8 @@ int BaseDPDT::init_atomic(const int nlocal, const int nall,
bool charge = false; bool charge = false;
bool rot = false; bool rot = false;
bool vel = true; bool vel = true;
int success=device->init(*ans,charge,rot,nlocal,nall,maxspecial,vel); _extra_fields = extra_fields;
int success=device->init(*ans,charge,rot,nlocal,nall,maxspecial,vel,_extra_fields/4);
if (success!=0) if (success!=0)
return success; return success;

View File

@ -53,7 +53,7 @@ class BaseDPD {
const int maxspecial, const double cell_size, const int maxspecial, const double cell_size,
const double gpu_split, FILE *screen, const double gpu_split, FILE *screen,
const void *pair_program, const char *k_name, const void *pair_program, const char *k_name,
const int onetype=0); const int onetype=0, const int extra_fields=0);
/// Estimate the overhead for GPU context changes and CPU driver /// Estimate the overhead for GPU context changes and CPU driver
void estimate_gpu_overhead(); void estimate_gpu_overhead();
@ -167,7 +167,6 @@ class BaseDPD {
/// Atom Data /// Atom Data
Atom<numtyp,acctyp> *atom; Atom<numtyp,acctyp> *atom;
// ------------------------ FORCE/ENERGY DATA ----------------------- // ------------------------ FORCE/ENERGY DATA -----------------------
Answer<numtyp,acctyp> *ans; Answer<numtyp,acctyp> *ans;
@ -197,6 +196,8 @@ class BaseDPD {
numtyp _dtinvsqrt; numtyp _dtinvsqrt;
int _seed, _timestep; int _seed, _timestep;
int _extra_fields;
protected: protected:
bool _compiled; bool _compiled;
int _block_size, _threads_per_atom, _onetype; int _block_size, _threads_per_atom, _onetype;

View File

@ -364,6 +364,12 @@ int DeviceT::init_device(MPI_Comm /*world*/, MPI_Comm replica, const int ngpu,
} else } else
_neighbor_shared.setup_auto_cell_size(false,_user_cell_size,_simd_size); _neighbor_shared.setup_auto_cell_size(false,_user_cell_size,_simd_size);
#ifndef LAL_USE_OLD_NEIGHBOR
_use_old_nbor_build = 0;
#else
_use_old_nbor_build = 1;
#endif
return flag; return flag;
} }
@ -510,9 +516,13 @@ int DeviceT::init(Answer<numtyp,acctyp> &ans, const bool charge,
gpu_nbor=1; gpu_nbor=1;
else if (_gpu_mode==Device<numtyp,acctyp>::GPU_HYB_NEIGH) else if (_gpu_mode==Device<numtyp,acctyp>::GPU_HYB_NEIGH)
gpu_nbor=2; gpu_nbor=2;
// NOTE: enforce the hybrid mode (binning on the CPU)
// when not using sorting on the device
#if !defined(USE_CUDPP) && !defined(USE_HIP_DEVICE_SORT) #if !defined(USE_CUDPP) && !defined(USE_HIP_DEVICE_SORT)
if (gpu_nbor==1) gpu_nbor=2; if (gpu_nbor==1) gpu_nbor=2;
#endif #endif
// or when the device supports subgroups
#ifndef LAL_USE_OLD_NEIGHBOR #ifndef LAL_USE_OLD_NEIGHBOR
if (gpu_nbor==1) gpu_nbor=2; if (gpu_nbor==1) gpu_nbor=2;
#endif #endif
@ -886,19 +896,31 @@ void DeviceT::output_times(UCL_Timer &time_pair, Answer<numtyp,acctyp> &ans,
} }
if (times[5] > 0.0) if (times[5] > 0.0)
fprintf(screen,"Device Overhead: %.4f s.\n",times[5]/_replica_size); fprintf(screen,"Device Overhead: %.4f s.\n",times[5]/_replica_size);
fprintf(screen,"Average split: %.4f.\n",avg_split);
fprintf(screen,"Lanes / atom: %d.\n",threads_per_atom);
fprintf(screen,"Vector width: %d.\n", simd_size());
fprintf(screen,"Prefetch mode: ");
if (_nbor_prefetch==2) fprintf(screen,"Intrinsics.\n");
else if (_nbor_prefetch==1) fprintf(screen,"API.\n");
else fprintf(screen,"None.\n");
fprintf(screen,"Max Mem / Proc: %.2f MB.\n",max_mb);
if (nbor.gpu_nbor()==2) if (nbor.gpu_nbor()==2)
fprintf(screen,"CPU Neighbor: %.4f s.\n",times[8]/_replica_size); fprintf(screen,"CPU Neighbor: %.4f s.\n",times[8]/_replica_size);
fprintf(screen,"CPU Cast/Pack: %.4f s.\n",times[4]/_replica_size); fprintf(screen,"CPU Cast/Pack: %.4f s.\n",times[4]/_replica_size);
fprintf(screen,"CPU Driver_Time: %.4f s.\n",times[6]/_replica_size); fprintf(screen,"CPU Driver_Time: %.4f s.\n",times[6]/_replica_size);
fprintf(screen,"CPU Idle_Time: %.4f s.\n",times[7]/_replica_size); fprintf(screen,"CPU Idle_Time: %.4f s.\n",times[7]/_replica_size);
fprintf(screen,"Average split: %.4f.\n",avg_split);
fprintf(screen,"Max Mem / Proc: %.2f MB.\n",max_mb);
fprintf(screen,"Prefetch mode: ");
if (_nbor_prefetch==2) fprintf(screen,"Intrinsics.\n");
else if (_nbor_prefetch==1) fprintf(screen,"API.\n");
else fprintf(screen,"None.\n");
fprintf(screen,"Vector width: %d.\n", simd_size());
fprintf(screen,"Lanes / atom: %d.\n",threads_per_atom);
fprintf(screen,"Pair block: %d.\n",_block_pair);
fprintf(screen,"Neigh block: %d.\n",_block_nbor_build);
if (nbor.gpu_nbor()==2) {
fprintf(screen,"Neigh mode: Hybrid (binning on host)");
if (_use_old_nbor_build == 1) fprintf(screen," - legacy\n");
else fprintf(screen," with subgroup support\n");
} else if (nbor.gpu_nbor()==1) {
fprintf(screen,"Neigh mode: Device");
if (_use_old_nbor_build == 1) fprintf(screen," - legacy\n");
else fprintf(screen," - with subgroup support\n");
} else if (nbor.gpu_nbor()==0)
fprintf(screen,"Neigh mode: Host\n");
fprintf(screen,"-------------------------------------"); fprintf(screen,"-------------------------------------");
fprintf(screen,"--------------------------------\n\n"); fprintf(screen,"--------------------------------\n\n");

View File

@ -347,6 +347,7 @@ class Device {
int _pppm_block, _block_nbor_build, _block_cell_2d, _block_cell_id; int _pppm_block, _block_nbor_build, _block_cell_2d, _block_cell_id;
int _max_shared_types, _max_bio_shared_types, _pppm_max_spline; int _max_shared_types, _max_bio_shared_types, _pppm_max_spline;
int _nbor_prefetch; int _nbor_prefetch;
int _use_old_nbor_build;
UCL_Program *dev_program; UCL_Program *dev_program;
UCL_Kernel k_zero, k_info; UCL_Kernel k_zero, k_info;

View File

@ -78,7 +78,7 @@ class LJCoulLong : public BaseCharge<numtyp, acctyp> {
numtyp _cut_coulsq, _qqrd2e, _g_ewald; numtyp _cut_coulsq, _qqrd2e, _g_ewald;
private: protected:
bool _allocated; bool _allocated;
int loop(const int eflag, const int vflag); int loop(const int eflag, const int vflag);
}; };

View File

@ -0,0 +1,174 @@
/***************************************************************************
lj_coul_long_soft.cpp
-------------------
Trung Nguyen (U Chicago)
Class for acceleration of the lj/cut/coul/long/soft pair style.
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : ndtrung@uchicago.edu
***************************************************************************/
#if defined(USE_OPENCL)
#include "lj_coul_long_soft_cl.h"
#elif defined(USE_CUDART)
const char *lj_coul_long_soft=0;
#else
#include "lj_coul_long_soft_cubin.h"
#endif
#include "lal_lj_coul_long_soft.h"
#include <cassert>
namespace LAMMPS_AL {
#define LJCoulLongSoftT LJCoulLongSoft<numtyp, acctyp>
extern Device<PRECISION,ACC_PRECISION> device;
template <class numtyp, class acctyp>
LJCoulLongSoftT::LJCoulLongSoft() : BaseCharge<numtyp,acctyp>(),
_allocated(false) {
}
template <class numtyp, class acctyp>
LJCoulLongSoftT::~LJCoulLongSoft() {
clear();
}
template <class numtyp, class acctyp>
int LJCoulLongSoftT::bytes_per_atom(const int max_nbors) const {
return this->bytes_per_atom_atomic(max_nbors);
}
template <class numtyp, class acctyp>
int LJCoulLongSoftT::init(const int ntypes,
double **host_cutsq, double **host_lj1,
double **host_lj2, double **host_lj3,
double **host_lj4, double **host_offset, double **host_epsilon,
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_cut_ljsq, const double host_cut_coulsq,
double *host_special_coul, const double qqrd2e,
const double g_ewald) {
int success;
success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
_screen,lj_coul_long_soft,"k_lj_coul_long_soft");
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, host_cut_ljsq);
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,
host_offset, host_epsilon);
sp_lj.alloc(8,*(this->ucl_device),UCL_READ_ONLY);
for (int i=0; i<4; i++) {
host_write[i]=host_special_lj[i];
host_write[i+4]=host_special_coul[i];
}
ucl_copy(sp_lj,host_write,8,false);
_cut_coulsq=host_cut_coulsq;
_qqrd2e=qqrd2e;
_g_ewald=g_ewald;
_allocated=true;
this->_max_bytes=lj1.row_bytes()+lj3.row_bytes()+sp_lj.row_bytes();
return 0;
}
template <class numtyp, class acctyp>
void LJCoulLongSoftT::reinit(const int ntypes, double **host_cutsq, double **host_lj1,
double **host_lj2, double **host_lj3, double **host_lj4,
double **host_offset, double **host_epsilon, double **host_cut_ljsq) {
// 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;
this->atom->type_pack4(ntypes,_lj_types,lj1,host_write,host_lj1,host_lj2,
host_cutsq, host_cut_ljsq);
this->atom->type_pack4(ntypes,_lj_types,lj3,host_write,host_lj3,host_lj4,
host_offset, host_epsilon);
}
template <class numtyp, class acctyp>
void LJCoulLongSoftT::clear() {
if (!_allocated)
return;
_allocated=false;
lj1.clear();
lj3.clear();
sp_lj.clear();
this->clear_atomic();
}
template <class numtyp, class acctyp>
double LJCoulLongSoftT::host_memory_usage() const {
return this->host_memory_usage_atomic()+sizeof(LJCoulLongSoft<numtyp,acctyp>);
}
// ---------------------------------------------------------------------------
// Calculate energies, forces, and torques
// ---------------------------------------------------------------------------
template <class numtyp, class acctyp>
int LJCoulLongSoftT::loop(const int eflag, const int vflag) {
// Compute the block size and grid size to keep all cores busy
const int BX=this->block_size();
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_sel->set_size(GX,BX);
this->k_pair_sel->run(&this->atom->x, &lj1, &lj3, &sp_lj,
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&this->ans->force, &this->ans->engv, &eflag,
&vflag, &ainum, &nbor_pitch, &this->atom->q,
&_cut_coulsq, &_qqrd2e, &_g_ewald,
&this->_threads_per_atom);
} else {
this->k_pair.set_size(GX,BX);
this->k_pair.run(&this->atom->x, &lj1, &lj3,
&_lj_types, &sp_lj, &this->nbor->dev_nbor,
&this->_nbor_data->begin(), &this->ans->force,
&this->ans->engv, &eflag, &vflag, &ainum,
&nbor_pitch, &this->atom->q, &_cut_coulsq,
&_qqrd2e, &_g_ewald, &this->_threads_per_atom);
}
this->time_pair.stop();
return GX;
}
template class LJCoulLongSoft<PRECISION,ACC_PRECISION>;
}

View File

@ -0,0 +1,288 @@
// **************************************************************************
// lj_coul_long_soft.cu
// -------------------
// Trung Nguyen (U Chicago)
//
// Device code for acceleration of the lj/cut/coul/long/soft pair style
//
// __________________________________________________________________________
// This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
// __________________________________________________________________________
//
// begin :
// email : ndtrung@uchicago.edu
// ***************************************************************************
#if defined(NV_KERNEL) || defined(USE_HIP)
#include <stdio.h>
#include "lal_aux_fun1.h"
#ifndef _DOUBLE_DOUBLE
_texture( pos_tex,float4);
_texture( q_tex,float);
#else
_texture_2d( pos_tex,int4);
_texture( q_tex,int2);
#endif
#else
#define pos_tex x_
#define q_tex q_
#endif
__kernel void k_lj_coul_long_soft(const __global numtyp4 *restrict x_,
const __global numtyp4 *restrict lj1,
const __global numtyp4 *restrict lj3,
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 __global numtyp *restrict q_,
const numtyp cut_coulsq, const numtyp qqrd2e,
const numtyp g_ewald, const int t_per_atom) {
int tid, ii, offset;
atom_info(t_per_atom,ii,tid,offset);
__local numtyp sp_lj[8];
int n_stride;
local_allocate_store_charge();
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];
sp_lj[4]=sp_lj_in[4];
sp_lj[5]=sp_lj_in[5];
sp_lj[6]=sp_lj_in[6];
sp_lj[7]=sp_lj_in[7];
acctyp4 f;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
acctyp energy, e_coul, virial[6];
if (EVFLAG) {
energy=(acctyp)0;
e_coul=(acctyp)0;
for (int i=0; i<6; i++) virial[i]=(acctyp)0;
}
if (ii<inum) {
int nbor, nbor_end;
int i, numj;
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
n_stride,nbor_end,nbor);
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
numtyp qtmp; fetch(qtmp,i,q_tex);
int itype=ix.w;
for ( ; nbor<nbor_end; nbor+=n_stride) {
int j=dev_packed[nbor];
numtyp factor_lj, factor_coul;
factor_lj = sp_lj[sbmask(j)];
factor_coul = (numtyp)1.0-sp_lj[sbmask(j)+4];
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 forcecoul, force_lj, force, prefactor, _erfc;
numtyp denc, denlj, r4sig6;
if (rsq < lj1[mtype].w) {
r4sig6 = rsq*rsq / lj1[mtype].y;
denlj = lj3[mtype].x + rsq*r4sig6;
force_lj = lj1[mtype].x * lj3[mtype].w *
((numtyp)48.0*r4sig6/(denlj*denlj*denlj) - (numtyp)24.0*r4sig6/(denlj*denlj));
} else
force_lj = (numtyp)0.0;
if (rsq < cut_coulsq) {
numtyp r = ucl_rsqrt(r2inv);
numtyp grij = g_ewald * r;
numtyp expm2 = ucl_exp(-grij*grij);
numtyp t = ucl_recip((numtyp)1.0 + EWALD_P*grij);
_erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
fetch(prefactor,j,q_tex);
denc = ucl_sqrt(lj3[mtype].y + rsq);
prefactor *= qqrd2e * lj1[mtype].x * qtmp / (denc*denc*denc);
forcecoul = prefactor * (_erfc + EWALD_F*grij*expm2-factor_coul);
} else
forcecoul = (numtyp)0.0;
force = factor_lj * force_lj + forcecoul;
f.x+=delx*force;
f.y+=dely*force;
f.z+=delz*force;
if (EVFLAG && eflag) {
if (rsq < cut_coulsq) {
prefactor *= (denc*denc);
e_coul += prefactor*(_erfc-factor_coul);
}
if (rsq < lj1[mtype].w) {
numtyp e= lj1[mtype].x * (numtyp)4.0 * lj3[mtype].w *
((numtyp)1.0/(denlj*denlj) - (numtyp)1.0/denlj);
energy+=factor_lj*(e-lj3[mtype].z);
}
}
if (EVFLAG && vflag) {
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
} // if ii
store_answers_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag,
vflag,ans,engv);
}
__kernel void k_lj_coul_long_soft_fast(const __global numtyp4 *restrict x_,
const __global numtyp4 *restrict lj1_in,
const __global numtyp4 *restrict lj3_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 __global numtyp *restrict q_,
const numtyp cut_coulsq, const numtyp qqrd2e,
const numtyp g_ewald, 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 numtyp sp_lj[8];
int n_stride;
local_allocate_store_charge();
if (tid<8)
sp_lj[tid]=sp_lj_in[tid];
if (tid<MAX_SHARED_TYPES*MAX_SHARED_TYPES) {
lj1[tid]=lj1_in[tid];
if (EVFLAG && eflag)
lj3[tid]=lj3_in[tid];
}
acctyp4 f;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
acctyp energy, e_coul, virial[6];
if (EVFLAG) {
energy=(acctyp)0;
e_coul=(acctyp)0;
for (int i=0; i<6; i++) virial[i]=(acctyp)0;
}
__syncthreads();
if (ii<inum) {
int nbor, nbor_end;
int i, numj;
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
n_stride,nbor_end,nbor);
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
numtyp qtmp; fetch(qtmp,i,q_tex);
int iw=ix.w;
int itype=fast_mul((int)MAX_SHARED_TYPES,iw);
for ( ; nbor<nbor_end; nbor+=n_stride) {
int j=dev_packed[nbor];
numtyp factor_lj, factor_coul;
factor_lj = sp_lj[sbmask(j)];
factor_coul = (numtyp)1.0-sp_lj[sbmask(j)+4];
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 forcecoul, force_lj, force, prefactor, _erfc;
numtyp denc, denlj, r4sig6;
if (rsq < lj1[mtype].w) {
r4sig6 = rsq*rsq / lj1[mtype].y;
denlj = lj3[mtype].x + rsq*r4sig6;
force_lj = lj1[mtype].x * lj3[mtype].w *
((numtyp)48.0*r4sig6/(denlj*denlj*denlj) - (numtyp)24.0*r4sig6/(denlj*denlj));
} else
force_lj = (numtyp)0.0;
if (rsq < cut_coulsq) {
numtyp r = ucl_sqrt(rsq);
numtyp grij = g_ewald * r;
numtyp expm2 = ucl_exp(-grij*grij);
numtyp t = ucl_recip((numtyp)1.0 + EWALD_P*grij);
_erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
fetch(prefactor,j,q_tex);
denc = ucl_sqrt(lj3[mtype].y + rsq);
prefactor *= qqrd2e * lj1[mtype].x * qtmp / (denc*denc*denc);
forcecoul = prefactor * (_erfc + EWALD_F*grij*expm2-factor_coul);
} else
forcecoul = (numtyp)0.0;
force = forcecoul + factor_lj*force_lj;
f.x+=delx*force;
f.y+=dely*force;
f.z+=delz*force;
if (EVFLAG && eflag) {
if (rsq < cut_coulsq) {
prefactor *= (denc*denc);
e_coul += prefactor*(_erfc-factor_coul);
}
if (rsq < lj1[mtype].w) {
numtyp e= lj1[mtype].x * (numtyp)4.0 * lj3[mtype].w *
((numtyp)1.0/(denlj*denlj) - (numtyp)1.0/denlj);
energy+=factor_lj*(e-lj3[mtype].z);
}
}
if (EVFLAG && vflag) {
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
} // if ii
store_answers_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag,
vflag,ans,engv);
}

View File

@ -0,0 +1,88 @@
/***************************************************************************
lj_coul_long_soft.h
-------------------
Trung Nguyen (U Chicago)
Class for acceleration of the lj/cut/coul/long/soft pair style.
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : ndtrung@uchicago.edu
***************************************************************************/
#ifndef LAL_LJ_COUL_LONG_SOFT_H
#define LAL_LJ_COUL_LONG_SOFT_H
#include "lal_base_charge.h"
namespace LAMMPS_AL {
template <class numtyp, class acctyp>
class LJCoulLongSoft : public BaseCharge<numtyp, acctyp> {
public:
LJCoulLongSoft();
~LJCoulLongSoft();
/// 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 successful
* - -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_offset, double **host_epsilon, 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_cut_ljsq,
const double host_cut_coulsq, double *host_special_coul,
const double qqrd2e, const double g_ewald);
/// Send updated coeffs from host to device (to be compatible with fix adapt)
void reinit(const int ntypes, double **host_cutsq,
double **host_lj1, double **host_lj2, double **host_lj3,
double **host_lj4, double **host_offset, double **host_epsilon, double **host_cut_ljsq);
/// 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 = cutsq_vdw
UCL_D_Vec<numtyp4> lj1;
/// lj3.x = lj3, lj3.y = lj4, lj3.z = offset, lj3.w = epsilon
UCL_D_Vec<numtyp4> lj3;
/// 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;
numtyp _cut_coulsq, _qqrd2e, _g_ewald;
protected:
bool _allocated;
int loop(const int eflag, const int vflag);
};
}
#endif

View File

@ -0,0 +1,151 @@
/***************************************************************************
lj_coul_long_soft_ext.cpp
-------------------
Trung Nguyen (U Chicago)
Functions for LAMMPS access to lj/cut/coul/long/soft acceleration routines.
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : ndtrung@uchicago.edu
***************************************************************************/
#include <iostream>
#include <cassert>
#include <cmath>
#include "lal_lj_coul_long_soft.h"
using namespace std;
using namespace LAMMPS_AL;
static LJCoulLongSoft<PRECISION,ACC_PRECISION> LJCLSMF;
// ---------------------------------------------------------------------------
// Allocate memory on host and device and copy constants to device
// ---------------------------------------------------------------------------
int ljcls_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
double **host_lj2, double **host_lj3, double **host_lj4,
double **offset, double **epsilon, 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_cut_ljsq, double host_cut_coulsq,
double *host_special_coul, const double qqrd2e,
const double g_ewald) {
LJCLSMF.clear();
gpu_mode=LJCLSMF.device->gpu_mode();
double gpu_split=LJCLSMF.device->particle_split();
int first_gpu=LJCLSMF.device->first_device();
int last_gpu=LJCLSMF.device->last_device();
int world_me=LJCLSMF.device->world_me();
int gpu_rank=LJCLSMF.device->gpu_rank();
int procs_per_gpu=LJCLSMF.device->procs_per_gpu();
LJCLSMF.device->init_message(screen,"lj/cut/coul/long/soft",first_gpu,last_gpu);
bool message=false;
if (LJCLSMF.device->replica_me()==0 && screen)
message=true;
if (message) {
fprintf(screen,"Initializing Device and compiling on process 0...");
fflush(screen);
}
int init_ok=0;
if (world_me==0)
init_ok=LJCLSMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
offset, epsilon, special_lj, inum, nall, max_nbors, maxspecial,
cell_size, gpu_split, screen, host_cut_ljsq,
host_cut_coulsq, host_special_coul, qqrd2e, g_ewald);
LJCLSMF.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 Device %d on core %d...",first_gpu,i);
else
fprintf(screen,"Initializing Devices %d-%d on core %d...",first_gpu,
last_gpu,i);
fflush(screen);
}
if (gpu_rank==i && world_me!=0)
init_ok=LJCLSMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
offset, epsilon, special_lj, inum, nall, max_nbors, maxspecial,
cell_size, gpu_split, screen, host_cut_ljsq,
host_cut_coulsq, host_special_coul, qqrd2e, g_ewald);
LJCLSMF.device->gpu_barrier();
if (message)
fprintf(screen,"Done.\n");
}
if (message)
fprintf(screen,"\n");
if (init_ok==0)
LJCLSMF.estimate_gpu_overhead();
return init_ok;
}
// ---------------------------------------------------------------------------
// Copy updated coeffs from host to device
// ---------------------------------------------------------------------------
void ljcls_gpu_reinit(const int ntypes, double **cutsq, double **host_lj1,
double **host_lj2, double **host_lj3, double **host_lj4,
double **offset, double **epsilon, double **host_cut_ljsq) {
int world_me=LJCLSMF.device->world_me();
int gpu_rank=LJCLSMF.device->gpu_rank();
int procs_per_gpu=LJCLSMF.device->procs_per_gpu();
if (world_me==0)
LJCLSMF.reinit(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
offset, epsilon, host_cut_ljsq);
LJCLSMF.device->world_barrier();
for (int i=0; i<procs_per_gpu; i++) {
if (gpu_rank==i && world_me!=0)
LJCLSMF.reinit(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
offset, epsilon, host_cut_ljsq);
LJCLSMF.device->gpu_barrier();
}
}
void ljcls_gpu_clear() {
LJCLSMF.clear();
}
int** ljcls_gpu_compute_n(const int ago, const int inum_full,
const int nall, double **host_x, int *host_type,
double *sublo, double *subhi, tagint *tag, int **nspecial,
tagint **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, double *host_q, double *boxlo,
double *prd) {
return LJCLSMF.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,
host_q, boxlo, prd);
}
void ljcls_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, double *host_q,
const int nlocal, double *boxlo, double *prd) {
LJCLSMF.compute(ago,inum_full,nall,host_x,host_type,ilist,numj,
firstneigh,eflag,vflag,eatom,vatom,host_start,cpu_time,success,
host_q,nlocal,boxlo,prd);
}
double ljcls_gpu_bytes() {
return LJCLSMF.host_memory_usage();
}

View File

@ -0,0 +1,157 @@
/***************************************************************************
lj_coul_soft.cpp
-------------------
Trung Nguyen (U Chicago)
Class for acceleration of the lj/cut/coul/cut/soft pair style.
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : ndtrung@uchicago.edu
***************************************************************************/
#if defined(USE_OPENCL)
#include "lj_coul_soft_cl.h"
#elif defined(USE_CUDART)
const char *lj_coul_soft=0;
#else
#include "lj_coul_soft_cubin.h"
#endif
#include "lal_lj_coul_soft.h"
#include <cassert>
namespace LAMMPS_AL {
#define LJCoulSoftT LJCoulSoft<numtyp, acctyp>
extern Device<PRECISION,ACC_PRECISION> device;
template <class numtyp, class acctyp>
LJCoulSoftT::LJCoulSoft() : BaseCharge<numtyp,acctyp>(),
_allocated(false) {
}
template <class numtyp, class acctyp>
LJCoulSoftT::~LJCoulSoft() {
clear();
}
template <class numtyp, class acctyp>
int LJCoulSoftT::bytes_per_atom(const int max_nbors) const {
return this->bytes_per_atom_atomic(max_nbors);
}
template <class numtyp, class acctyp>
int LJCoulSoftT::init(const int ntypes,
double **host_cutsq, double **host_lj1,
double **host_lj2, double **host_lj3,
double **host_lj4, double **host_offset, double **host_epsilon,
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_cut_ljsq, double **host_cut_coulsq,
double *host_special_coul, const double qqrd2e) {
int success;
success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
_screen,lj_coul_soft,"lj_coul_soft");
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_cut_ljsq, host_cut_coulsq);
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,
host_offset, host_epsilon);
cutsq.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
this->atom->type_pack1(ntypes,lj_types,cutsq,host_write,host_cutsq);
sp_lj.alloc(8,*(this->ucl_device),UCL_READ_ONLY);
for (int i=0; i<4; i++) {
host_write[i]=host_special_lj[i];
host_write[i+4]=host_special_coul[i];
}
ucl_copy(sp_lj,host_write,8,false);
_qqrd2e=qqrd2e;
_allocated=true;
this->_max_bytes=lj1.row_bytes()+lj3.row_bytes()+cutsq.row_bytes()+
sp_lj.row_bytes();
return 0;
}
template <class numtyp, class acctyp>
void LJCoulSoftT::clear() {
if (!_allocated)
return;
_allocated=false;
lj1.clear();
lj3.clear();
cutsq.clear();
sp_lj.clear();
this->clear_atomic();
}
template <class numtyp, class acctyp>
double LJCoulSoftT::host_memory_usage() const {
return this->host_memory_usage_atomic()+sizeof(LJCoulSoft<numtyp,acctyp>);
}
// ---------------------------------------------------------------------------
// Calculate energies, forces, and torques
// ---------------------------------------------------------------------------
template <class numtyp, class acctyp>
int LJCoulSoftT::loop(const int eflag, const int vflag) {
// Compute the block size and grid size to keep all cores busy
const int BX=this->block_size();
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_sel->set_size(GX,BX);
this->k_pair_sel->run(&this->atom->x, &lj1, &lj3, &sp_lj,
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&this->ans->force, &this->ans->engv, &eflag,
&vflag, &ainum, &nbor_pitch, &this->atom->q,
&cutsq, &_qqrd2e, &this->_threads_per_atom);
} else {
this->k_pair.set_size(GX,BX);
this->k_pair.run(&this->atom->x, &lj1, &lj3, &_lj_types, &sp_lj,
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&this->ans->force, &this->ans->engv,
&eflag, &vflag, &ainum, &nbor_pitch, &this->atom->q,
&cutsq, &_qqrd2e, &this->_threads_per_atom);
}
this->time_pair.stop();
return GX;
}
template class LJCoulSoft<PRECISION,ACC_PRECISION>;
}

275
lib/gpu/lal_lj_coul_soft.cu Normal file
View File

@ -0,0 +1,275 @@
// **************************************************************************
// lj_coul_soft.cu
// -------------------
// Trung Nguyen (U Chicago)
//
// Device code for acceleration of the lj/coul/cut/soft pair style
//
// __________________________________________________________________________
// This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
// __________________________________________________________________________
//
// begin :
// email : ndtrung@uchicago.edu
// ***************************************************************************
#if defined(NV_KERNEL) || defined(USE_HIP)
#include "lal_aux_fun1.h"
#ifndef _DOUBLE_DOUBLE
_texture( pos_tex,float4);
_texture( q_tex,float);
#else
_texture_2d( pos_tex,int4);
_texture( q_tex,int2);
#endif
#else
#define pos_tex x_
#define q_tex q_
#endif
__kernel void k_lj_coul_soft(const __global numtyp4 *restrict x_,
const __global numtyp4 *restrict lj1,
const __global numtyp4 *restrict lj3,
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 __global numtyp *restrict q_,
const __global numtyp *restrict cutsq,
const numtyp qqrd2e, const int t_per_atom) {
int tid, ii, offset;
atom_info(t_per_atom,ii,tid,offset);
__local numtyp sp_lj[8];
int n_stride;
local_allocate_store_charge();
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];
sp_lj[4]=sp_lj_in[4];
sp_lj[5]=sp_lj_in[5];
sp_lj[6]=sp_lj_in[6];
sp_lj[7]=sp_lj_in[7];
acctyp4 f;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
acctyp energy, e_coul, virial[6];
if (EVFLAG) {
energy=(acctyp)0;
e_coul=(acctyp)0;
for (int i=0; i<6; i++) virial[i]=(acctyp)0;
}
if (ii<inum) {
int nbor, nbor_end;
int i, numj;
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
n_stride,nbor_end,nbor);
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
numtyp qtmp; fetch(qtmp,i,q_tex);
int itype=ix.w;
for ( ; nbor<nbor_end; nbor+=n_stride) {
int j=dev_packed[nbor];
numtyp factor_lj, factor_coul;
factor_lj = sp_lj[sbmask(j)];
factor_coul = sp_lj[sbmask(j)+4];
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<cutsq[mtype]) {
numtyp forcecoul, force_lj, force;
numtyp r4sig6, denlj, denc;
if (rsq < lj1[mtype].z) {
r4sig6 = rsq*rsq / lj1[mtype].y;
denlj = lj3[mtype].x + rsq*r4sig6;
force_lj = lj1[mtype].x * lj3[mtype].w *
((numtyp)48.0*r4sig6/(denlj*denlj*denlj) - (numtyp)24.0*r4sig6/(denlj*denlj));
force_lj *= factor_lj;
} else
force_lj = (numtyp)0.0;
if (rsq < lj1[mtype].w) {
fetch(forcecoul,j,q_tex);
denc = sqrt(lj3[mtype].y + rsq);
forcecoul *= qqrd2e * lj1[mtype].x * qtmp / (denc*denc*denc);
forcecoul *= factor_coul;
} else
forcecoul = (numtyp)0.0;
force = force_lj + forcecoul;
f.x+=delx*force;
f.y+=dely*force;
f.z+=delz*force;
if (EVFLAG && eflag) {
if (rsq < lj1[mtype].w) {
e_coul += forcecoul*(denc*denc);
}
if (rsq < lj1[mtype].z) {
numtyp e = lj1[mtype].x * (numtyp)4.0 * lj3[mtype].w *
((numtyp)1.0/(denlj*denlj) - (numtyp)1.0/denlj);
energy+=factor_lj*(e-lj3[mtype].z);
}
}
if (EVFLAG && vflag) {
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
} // if ii
store_answers_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag,
vflag,ans,engv);
}
__kernel void k_lj_coul_soft_fast(const __global numtyp4 *restrict x_,
const __global numtyp4 *restrict lj1_in,
const __global numtyp4 *restrict lj3_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 __global numtyp *restrict q_,
const __global numtyp *restrict _cutsq,
const numtyp qqrd2e, 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 numtyp cutsq[MAX_SHARED_TYPES*MAX_SHARED_TYPES];
__local numtyp sp_lj[8];
int n_stride;
local_allocate_store_charge();
if (tid<8)
sp_lj[tid]=sp_lj_in[tid];
if (tid<MAX_SHARED_TYPES*MAX_SHARED_TYPES) {
lj1[tid]=lj1_in[tid];
cutsq[tid]=_cutsq[tid];
if (EVFLAG && eflag)
lj3[tid]=lj3_in[tid];
}
acctyp4 f;
f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0;
acctyp energy, e_coul, virial[6];
if (EVFLAG) {
energy=(acctyp)0;
e_coul=(acctyp)0;
for (int i=0; i<6; i++) virial[i]=(acctyp)0;
}
__syncthreads();
if (ii<inum) {
int nbor, nbor_end;
int i, numj;
nbor_info(dev_nbor,dev_packed,nbor_pitch,t_per_atom,ii,offset,i,numj,
n_stride,nbor_end,nbor);
numtyp4 ix; fetch4(ix,i,pos_tex); //x_[i];
numtyp qtmp; fetch(qtmp,i,q_tex);
int iw=ix.w;
int itype=fast_mul((int)MAX_SHARED_TYPES,iw);
for ( ; nbor<nbor_end; nbor+=n_stride) {
int j=dev_packed[nbor];
numtyp factor_lj, factor_coul;
factor_lj = sp_lj[sbmask(j)];
factor_coul = sp_lj[sbmask(j)+4];
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<cutsq[mtype]) {
numtyp forcecoul, force_lj, force;
numtyp r4sig6, denlj, denc;
if (rsq < lj1[mtype].z) {
r4sig6 = rsq*rsq / lj1[mtype].y;
denlj = lj3[mtype].x + rsq*r4sig6;
force_lj = lj1[mtype].x * lj3[mtype].w *
((numtyp)48.0*r4sig6/(denlj*denlj*denlj) - (numtyp)24.0*r4sig6/(denlj*denlj));
force_lj *= factor_lj;
} else
force_lj = (numtyp)0.0;
if (rsq < lj1[mtype].w) {
fetch(forcecoul,j,q_tex);
denc = sqrt(lj3[mtype].y + rsq);
forcecoul *= qqrd2e * lj1[mtype].x * qtmp / (denc*denc*denc);
forcecoul *= factor_coul;
} else
forcecoul = (numtyp)0.0;
force = force_lj + forcecoul;
f.x+=delx*force;
f.y+=dely*force;
f.z+=delz*force;
if (EVFLAG && eflag) {
if (rsq < lj1[mtype].w) {
e_coul += forcecoul*(denc*denc);
}
if (rsq < lj1[mtype].z) {
numtyp e = lj1[mtype].x * (numtyp)4.0 * lj3[mtype].w *
((numtyp)1.0/(denlj*denlj) - (numtyp)1.0/denlj);
energy+=factor_lj*(e-lj3[mtype].z);
}
}
if (EVFLAG && vflag) {
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
} // if ii
store_answers_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag,
vflag,ans,engv);
}

View File

@ -0,0 +1,85 @@
/***************************************************************************
lj_coul_soft.h
-------------------
Trung Nguyen (U Chicago)
Class for acceleration of the lj/cut/coul/cut/soft pair style.
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : ndtrung@uchicago.edu
***************************************************************************/
#ifndef LAL_LJ_COUL_SOFT_H
#define LAL_LJ_COUL_SOFT_H
#include "lal_base_charge.h"
namespace LAMMPS_AL {
template <class numtyp, class acctyp>
class LJCoulSoft : public BaseCharge<numtyp, acctyp> {
public:
LJCoulSoft();
~LJCoulSoft();
/// 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 successful
* - -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_offset, double **host_epsilon, 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_cut_ljsq,
double **host_cut_coulsq, double *host_special_coul,
const double qqrd2e);
/// 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_vdw, lj1.w = cutsq_coul
UCL_D_Vec<numtyp4> lj1;
/// lj3.x = lj3, lj3.y = lj4, lj3.z = offset, lj3.w = epsilon
UCL_D_Vec<numtyp4> lj3;
/// cutsq
UCL_D_Vec<numtyp> cutsq;
/// 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;
numtyp _qqrd2e;
private:
bool _allocated;
int loop(const int eflag, const int vflag);
};
}
#endif

View File

@ -0,0 +1,128 @@
/***************************************************************************
lj_coul_soft_ext.cpp
-------------------
Trung Nguyen (U Chicago)
Functions for LAMMPS access to lj/cut/coul/cut/soft acceleration routines.
__________________________________________________________________________
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
email : ndtrung@uchicago.edu
***************************************************************************/
#include <iostream>
#include <cassert>
#include <cmath>
#include "lal_lj_coul_soft.h"
using namespace std;
using namespace LAMMPS_AL;
static LJCoulSoft<PRECISION,ACC_PRECISION> LJCSMF;
// ---------------------------------------------------------------------------
// Allocate memory on host and device and copy constants to device
// ---------------------------------------------------------------------------
int ljcs_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
double **host_lj2, double **host_lj3, double **host_lj4,
double **offset, double **epsilon, 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_cut_ljsq, double **host_cut_coulsq,
double *host_special_coul, const double qqrd2e) {
LJCSMF.clear();
gpu_mode=LJCSMF.device->gpu_mode();
double gpu_split=LJCSMF.device->particle_split();
int first_gpu=LJCSMF.device->first_device();
int last_gpu=LJCSMF.device->last_device();
int world_me=LJCSMF.device->world_me();
int gpu_rank=LJCSMF.device->gpu_rank();
int procs_per_gpu=LJCSMF.device->procs_per_gpu();
LJCSMF.device->init_message(screen,"lj/cut/coul/cut",first_gpu,last_gpu);
bool message=false;
if (LJCSMF.device->replica_me()==0 && screen)
message=true;
if (message) {
fprintf(screen,"Initializing Device and compiling on process 0...");
fflush(screen);
}
int init_ok=0;
if (world_me==0)
init_ok=LJCSMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3,
host_lj4, offset, epsilon, special_lj, inum, nall, max_nbors,
maxspecial, cell_size, gpu_split, screen, host_cut_ljsq,
host_cut_coulsq, host_special_coul, qqrd2e);
LJCSMF.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 Device %d on core %d...",first_gpu,i);
else
fprintf(screen,"Initializing Devices %d-%d on core %d...",first_gpu,
last_gpu,i);
fflush(screen);
}
if (gpu_rank==i && world_me!=0)
init_ok=LJCSMF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
offset, epsilon, special_lj, inum, nall, max_nbors, maxspecial,
cell_size, gpu_split, screen, host_cut_ljsq,
host_cut_coulsq, host_special_coul, qqrd2e);
LJCSMF.device->gpu_barrier();
if (message)
fprintf(screen,"Done.\n");
}
if (message)
fprintf(screen,"\n");
if (init_ok==0)
LJCSMF.estimate_gpu_overhead();
return init_ok;
}
void ljcs_gpu_clear() {
LJCSMF.clear();
}
int** ljcs_gpu_compute_n(const int ago, const int inum_full,
const int nall, double **host_x, int *host_type,
double *sublo, double *subhi, tagint *tag, int **nspecial,
tagint **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, double *host_q, double *boxlo,
double *prd) {
return LJCSMF.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,
host_q, boxlo, prd);
}
void ljcs_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, double *host_q,
const int nlocal, double *boxlo, double *prd) {
LJCSMF.compute(ago,inum_full,nall,host_x,host_type,ilist,numj,firstneigh,eflag,
vflag,eatom,vatom,host_start,cpu_time,success,host_q,
nlocal,boxlo,prd);
}
double ljcs_gpu_bytes() {
return LJCSMF.host_memory_usage();
}

View File

@ -0,0 +1,249 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Trung Nguyen (U Chicago)
------------------------------------------------------------------------- */
#include "pair_lj_cut_coul_cut_soft_gpu.h"
#include "atom.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "gpu_extra.h"
#include "neigh_list.h"
#include "neighbor.h"
#include "suffix.h"
#include <cmath>
using namespace LAMMPS_NS;
// External functions from cuda library for atom decomposition
int ljcs_gpu_init(const int ntypes, double **cutsq, double **host_lj1, double **host_lj2,
double **host_lj3, double **host_lj4, double **offset, double **epsilon, double *special_lj,
const int nlocal, const int nall, const int max_nbors, const int maxspecial,
const double cell_size, int &gpu_mode, FILE *screen, double **host_cut_ljsq,
double **host_cut_coulsq, double *host_special_coul, const double qqrd2e);
void ljcs_gpu_clear();
int **ljcs_gpu_compute_n(const int ago, const int inum, const int nall, double **host_x,
int *host_type, double *sublo, double *subhi, tagint *tag, int **nspecial,
tagint **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, double *host_q, double *boxlo,
double *prd);
void ljcs_gpu_compute(const int ago, const int inum, 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, double *host_q, const int nlocal, double *boxlo, double *prd);
double ljcs_gpu_bytes();
/* ---------------------------------------------------------------------- */
PairLJCutCoulCutSoftGPU::PairLJCutCoulCutSoftGPU(LAMMPS *lmp) :
PairLJCutCoulCutSoft(lmp), gpu_mode(GPU_FORCE)
{
respa_enable = 0;
reinitflag = 0;
cpu_time = 0.0;
suffix_flag |= Suffix::GPU;
GPU_EXTRA::gpu_ready(lmp->modify, lmp->error);
}
/* ----------------------------------------------------------------------
free all arrays
------------------------------------------------------------------------- */
PairLJCutCoulCutSoftGPU::~PairLJCutCoulCutSoftGPU()
{
ljcs_gpu_clear();
}
/* ---------------------------------------------------------------------- */
void PairLJCutCoulCutSoftGPU::compute(int eflag, int vflag)
{
ev_init(eflag, vflag);
int nall = atom->nlocal + atom->nghost;
int inum, host_start;
bool success = true;
int *ilist, *numneigh, **firstneigh;
if (gpu_mode != GPU_FORCE) {
double sublo[3], subhi[3];
if (domain->triclinic == 0) {
sublo[0] = domain->sublo[0];
sublo[1] = domain->sublo[1];
sublo[2] = domain->sublo[2];
subhi[0] = domain->subhi[0];
subhi[1] = domain->subhi[1];
subhi[2] = domain->subhi[2];
} else {
domain->bbox(domain->sublo_lamda, domain->subhi_lamda, sublo, subhi);
}
inum = atom->nlocal;
firstneigh = ljcs_gpu_compute_n(neighbor->ago, inum, nall, atom->x, atom->type, sublo, subhi,
atom->tag, atom->nspecial, atom->special, eflag, vflag,
eflag_atom, vflag_atom, host_start, &ilist, &numneigh, cpu_time,
success, atom->q, domain->boxlo, domain->prd);
} else {
inum = list->inum;
ilist = list->ilist;
numneigh = list->numneigh;
firstneigh = list->firstneigh;
ljcs_gpu_compute(neighbor->ago, inum, nall, atom->x, atom->type, ilist, numneigh, firstneigh,
eflag, vflag, eflag_atom, vflag_atom, host_start, cpu_time, success, atom->q,
atom->nlocal, domain->boxlo, domain->prd);
}
if (!success) error->one(FLERR, "Insufficient memory on accelerator");
if (host_start < inum) {
cpu_time = platform::walltime();
cpu_compute(host_start, inum, eflag, vflag, ilist, numneigh, firstneigh);
cpu_time = platform::walltime() - cpu_time;
}
}
/* ----------------------------------------------------------------------
init specific to this pair style
------------------------------------------------------------------------- */
void PairLJCutCoulCutSoftGPU::init_style()
{
if (!atom->q_flag) error->all(FLERR, "Pair style lj/cut/coul/cut/soft/gpu requires atom attribute q");
// Repeat cutsq calculation because done after call to init_style
double maxcut = -1.0;
double cut;
for (int i = 1; i <= atom->ntypes; i++) {
for (int j = i; j <= atom->ntypes; j++) {
if (setflag[i][j] != 0 || (setflag[i][i] != 0 && setflag[j][j] != 0)) {
cut = init_one(i, j);
cut *= cut;
if (cut > maxcut) maxcut = cut;
cutsq[i][j] = cutsq[j][i] = cut;
} else
cutsq[i][j] = cutsq[j][i] = 0.0;
}
}
double cell_size = sqrt(maxcut) + neighbor->skin;
int maxspecial = 0;
if (atom->molecular != Atom::ATOMIC) maxspecial = atom->maxspecial;
int mnf = 5e-2 * neighbor->oneatom;
int success =
ljcs_gpu_init(atom->ntypes + 1, cutsq, lj1, lj2, lj3, lj4, offset, epsilon, force->special_lj,
atom->nlocal, atom->nlocal + atom->nghost, mnf, maxspecial, cell_size, gpu_mode,
screen, cut_ljsq, cut_coulsq, force->special_coul, force->qqrd2e);
GPU_EXTRA::check_flag(success, error, world);
if (gpu_mode == GPU_FORCE) neighbor->add_request(this, NeighConst::REQ_FULL);
}
/* ---------------------------------------------------------------------- */
double PairLJCutCoulCutSoftGPU::memory_usage()
{
double bytes = Pair::memory_usage();
return bytes + ljcs_gpu_bytes();
}
/* ---------------------------------------------------------------------- */
void PairLJCutCoulCutSoftGPU::cpu_compute(int start, int inum, int eflag, int /* vflag */, int *ilist,
int *numneigh, int **firstneigh)
{
int i, j, ii, jj, jnum, itype, jtype, itable;
double qtmp, xtmp, ytmp, ztmp, delx, dely, delz, evdwl, ecoul, fpair;
double r, r2inv, r6inv, forcecoul, forcelj, factor_coul, factor_lj;
double denc, denlj, r4sig6;
int *jlist;
double rsq;
evdwl = ecoul = 0.0;
double **x = atom->x;
double **f = atom->f;
double *q = atom->q;
int *type = atom->type;
double *special_coul = force->special_coul;
double *special_lj = force->special_lj;
double qqrd2e = force->qqrd2e;
// loop over neighbors of my atoms
for (ii = start; ii < inum; ii++) {
i = ilist[ii];
qtmp = q[i];
xtmp = x[i][0];
ytmp = x[i][1];
ztmp = x[i][2];
itype = type[i];
jlist = firstneigh[i];
jnum = numneigh[i];
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
factor_lj = special_lj[sbmask(j)];
factor_coul = special_coul[sbmask(j)];
j &= NEIGHMASK;
delx = xtmp - x[j][0];
dely = ytmp - x[j][1];
delz = ztmp - x[j][2];
rsq = delx * delx + dely * dely + delz * delz;
jtype = type[j];
if (rsq < cutsq[itype][jtype]) {
if (rsq < cut_coulsq[itype][jtype]) {
denc = sqrt(lj4[itype][jtype] + rsq);
forcecoul = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc);
} else forcecoul = 0.0;
if (rsq < cut_ljsq[itype][jtype]) {
r4sig6 = rsq*rsq / lj2[itype][jtype];
denlj = lj3[itype][jtype] + rsq*r4sig6;
forcelj = lj1[itype][jtype] * epsilon[itype][jtype] *
(48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj));
} else forcelj = 0.0;
fpair = factor_coul*forcecoul + factor_lj*forcelj;
f[i][0] += delx * fpair;
f[i][1] += dely * fpair;
f[i][2] += delz * fpair;
if (eflag) {
if (rsq < cut_coulsq[itype][jtype])
ecoul = factor_coul * qqrd2e * lj1[itype][jtype] * qtmp*q[j] / denc;
else
ecoul = 0.0;
if (rsq < cut_ljsq[itype][jtype]) {
evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] *
(1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype];
evdwl *= factor_lj;
} else
evdwl = 0.0;
}
if (evflag) ev_tally_full(i, evdwl, ecoul, fpair, delx, dely, delz);
}
}
}
}

View File

@ -0,0 +1,45 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef PAIR_CLASS
// clang-format off
PairStyle(lj/cut/coul/soft/soft/gpu,PairLJCutCoulCutSoftGPU);
// clang-format on
#else
#ifndef LMP_PAIR_LJ_CUT_COUL_CUT_SOFT_GPU_H
#define LMP_PAIR_LJ_CUT_COUL_CUT_SOFT_GPU_H
#include "pair_lj_cut_coul_cut_soft.h"
namespace LAMMPS_NS {
class PairLJCutCoulCutSoftGPU : public PairLJCutCoulCutSoft {
public:
PairLJCutCoulCutSoftGPU(LAMMPS *lmp);
~PairLJCutCoulCutSoftGPU() override;
void cpu_compute(int, int, int, int, int *, int *, int **);
void compute(int, int) override;
void init_style() override;
double memory_usage() override;
enum { GPU_FORCE, GPU_NEIGH, GPU_HYB_NEIGH };
private:
int gpu_mode;
double cpu_time;
};
} // namespace LAMMPS_NS
#endif
#endif

View File

@ -0,0 +1,297 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Trung Nguyen (U Chicago)
------------------------------------------------------------------------- */
#include "pair_lj_cut_coul_long_soft_gpu.h"
#include "atom.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "gpu_extra.h"
#include "kspace.h"
#include "neigh_list.h"
#include "neighbor.h"
#include "suffix.h"
#include <cmath>
#define EWALD_F 1.12837917
#define EWALD_P 0.3275911
#define A1 0.254829592
#define A2 -0.284496736
#define A3 1.421413741
#define A4 -1.453152027
#define A5 1.061405429
using namespace LAMMPS_NS;
// External functions from cuda library for atom decomposition
int ljcls_gpu_init(const int ntypes, double **cutsq, double **host_lj1, double **host_lj2,
double **host_lj3, double **host_lj4, double **offset, double **epsilon, double *special_lj,
const int nlocal, const int nall, const int max_nbors, const int maxspecial,
const double cell_size, int &gpu_mode, FILE *screen, double **host_cut_ljsq,
double host_cut_coulsq, double *host_special_coul, const double qqrd2e,
const double g_ewald);
void ljcls_gpu_reinit(const int ntypes, double **cutsq, double **host_lj1, double **host_lj2,
double **host_lj3, double **host_lj4, double **offset, double **epsilon,
double **host_lj_cutsq);
void ljcls_gpu_clear();
int **ljcls_gpu_compute_n(const int ago, const int inum, const int nall, double **host_x,
int *host_type, double *sublo, double *subhi, tagint *tag, int **nspecial,
tagint **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, double *host_q, double *boxlo,
double *prd);
void ljcls_gpu_compute(const int ago, const int inum, 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, double *host_q, const int nlocal,
double *boxlo, double *prd);
double ljcls_gpu_bytes();
/* ---------------------------------------------------------------------- */
PairLJCutCoulLongSoftGPU::PairLJCutCoulLongSoftGPU(LAMMPS *lmp) :
PairLJCutCoulLongSoft(lmp), gpu_mode(GPU_FORCE)
{
respa_enable = 0;
cpu_time = 0.0;
suffix_flag |= Suffix::GPU;
GPU_EXTRA::gpu_ready(lmp->modify, lmp->error);
}
/* ----------------------------------------------------------------------
free all arrays
------------------------------------------------------------------------- */
PairLJCutCoulLongSoftGPU::~PairLJCutCoulLongSoftGPU()
{
ljcls_gpu_clear();
}
/* ---------------------------------------------------------------------- */
void PairLJCutCoulLongSoftGPU::compute(int eflag, int vflag)
{
ev_init(eflag, vflag);
int nall = atom->nlocal + atom->nghost;
int inum, host_start;
bool success = true;
int *ilist, *numneigh, **firstneigh;
if (gpu_mode != GPU_FORCE) {
double sublo[3], subhi[3];
if (domain->triclinic == 0) {
sublo[0] = domain->sublo[0];
sublo[1] = domain->sublo[1];
sublo[2] = domain->sublo[2];
subhi[0] = domain->subhi[0];
subhi[1] = domain->subhi[1];
subhi[2] = domain->subhi[2];
} else {
domain->bbox(domain->sublo_lamda, domain->subhi_lamda, sublo, subhi);
}
inum = atom->nlocal;
firstneigh = ljcls_gpu_compute_n(neighbor->ago, inum, nall, atom->x, atom->type, sublo, subhi,
atom->tag, atom->nspecial, atom->special, eflag, vflag,
eflag_atom, vflag_atom, host_start, &ilist, &numneigh, cpu_time,
success, atom->q, domain->boxlo, domain->prd);
} else {
inum = list->inum;
ilist = list->ilist;
numneigh = list->numneigh;
firstneigh = list->firstneigh;
ljcls_gpu_compute(neighbor->ago, inum, nall, atom->x, atom->type, ilist, numneigh, firstneigh,
eflag, vflag, eflag_atom, vflag_atom, host_start, cpu_time, success, atom->q,
atom->nlocal, domain->boxlo, domain->prd);
}
if (!success) error->one(FLERR, "Insufficient memory on accelerator");
if (host_start < inum) {
cpu_time = platform::walltime();
cpu_compute(host_start, inum, eflag, vflag, ilist, numneigh, firstneigh);
cpu_time = platform::walltime() - cpu_time;
}
}
/* ----------------------------------------------------------------------
init specific to this pair style
------------------------------------------------------------------------- */
void PairLJCutCoulLongSoftGPU::init_style()
{
cut_respa = nullptr;
if (!atom->q_flag) error->all(FLERR, "Pair style lj/cut/coul/long/soft/gpu requires atom attribute q");
// Repeat cutsq calculation because done after call to init_style
double maxcut = -1.0;
double cut;
for (int i = 1; i <= atom->ntypes; i++) {
for (int j = i; j <= atom->ntypes; j++) {
if (setflag[i][j] != 0 || (setflag[i][i] != 0 && setflag[j][j] != 0)) {
cut = init_one(i, j);
cut *= cut;
if (cut > maxcut) maxcut = cut;
cutsq[i][j] = cutsq[j][i] = cut;
} else
cutsq[i][j] = cutsq[j][i] = 0.0;
}
}
double cell_size = sqrt(maxcut) + neighbor->skin;
cut_coulsq = cut_coul * cut_coul;
// insure use of KSpace long-range solver, set g_ewald
if (force->kspace == nullptr) error->all(FLERR, "Pair style requires a KSpace style");
g_ewald = force->kspace->g_ewald;
// setup force tables
if (ncoultablebits) init_tables(cut_coul, cut_respa);
int maxspecial = 0;
if (atom->molecular != Atom::ATOMIC) maxspecial = atom->maxspecial;
int mnf = 5e-2 * neighbor->oneatom;
int success =
ljcls_gpu_init(atom->ntypes + 1, cutsq, lj1, lj2, lj3, lj4, offset, epsilon, force->special_lj,
atom->nlocal, atom->nlocal + atom->nghost, mnf, maxspecial, cell_size, gpu_mode,
screen, cut_ljsq, cut_coulsq, force->special_coul, force->qqrd2e, g_ewald);
GPU_EXTRA::check_flag(success, error, world);
if (gpu_mode == GPU_FORCE) neighbor->add_request(this, NeighConst::REQ_FULL);
}
/* ---------------------------------------------------------------------- */
void PairLJCutCoulLongSoftGPU::reinit()
{
Pair::reinit();
ljcls_gpu_reinit(atom->ntypes + 1, cutsq, lj1, lj2, lj3, lj4, offset, epsilon, cut_ljsq);
}
/* ---------------------------------------------------------------------- */
double PairLJCutCoulLongSoftGPU::memory_usage()
{
double bytes = Pair::memory_usage();
return bytes + ljcls_gpu_bytes();
}
/* ---------------------------------------------------------------------- */
void PairLJCutCoulLongSoftGPU::cpu_compute(int start, int inum, int eflag, int /* vflag */, int *ilist,
int *numneigh, int **firstneigh)
{
int i, j, ii, jj, jnum, itype, jtype, itable;
double qtmp, xtmp, ytmp, ztmp, delx, dely, delz, evdwl, ecoul, fpair;
double r, r2inv, r6inv, forcecoul, forcelj, factor_coul, factor_lj;
double denc, denlj, r4sig6;
double grij, expm2, prefactor, t, erfc;
int *jlist;
double rsq;
evdwl = ecoul = 0.0;
double **x = atom->x;
double **f = atom->f;
double *q = atom->q;
int *type = atom->type;
double *special_coul = force->special_coul;
double *special_lj = force->special_lj;
double qqrd2e = force->qqrd2e;
// loop over neighbors of my atoms
for (ii = start; ii < inum; ii++) {
i = ilist[ii];
qtmp = q[i];
xtmp = x[i][0];
ytmp = x[i][1];
ztmp = x[i][2];
itype = type[i];
jlist = firstneigh[i];
jnum = numneigh[i];
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
factor_lj = special_lj[sbmask(j)];
factor_coul = special_coul[sbmask(j)];
j &= NEIGHMASK;
delx = xtmp - x[j][0];
dely = ytmp - x[j][1];
delz = ztmp - x[j][2];
rsq = delx * delx + dely * dely + delz * delz;
jtype = type[j];
if (rsq < cutsq[itype][jtype]) {
r2inv = 1.0 / rsq;
if (rsq < cut_coulsq) {
r = sqrt(rsq);
grij = g_ewald * r;
expm2 = exp(-grij * grij);
t = 1.0 / (1.0 + EWALD_P * grij);
erfc = t * (A1 + t * (A2 + t * (A3 + t * (A4 + t * A5)))) * expm2;
denc = sqrt(lj4[itype][jtype] + rsq);
prefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / (denc*denc*denc);
forcecoul = prefactor * (erfc + EWALD_F * grij * expm2);
if (factor_coul < 1.0) forcecoul -= (1.0 - factor_coul) * prefactor;
} else
forcecoul = 0.0;
if (rsq < cut_ljsq[itype][jtype]) {
r4sig6 = rsq*rsq / lj2[itype][jtype];
denlj = lj3[itype][jtype] + rsq*r4sig6;
forcelj = lj1[itype][jtype] * epsilon[itype][jtype] *
(48.0*r4sig6/(denlj*denlj*denlj) - 24.0*r4sig6/(denlj*denlj));
} else
forcelj = 0.0;
fpair = (forcecoul + factor_lj * forcelj) * r2inv;
f[i][0] += delx * fpair;
f[i][1] += dely * fpair;
f[i][2] += delz * fpair;
if (eflag) {
if (rsq < cut_coulsq) {
prefactor = qqrd2e * lj1[itype][jtype] * qtmp*q[j] / denc;
ecoul = prefactor*erfc;
} else
ecoul = 0.0;
if (rsq < cut_ljsq[itype][jtype]) {
evdwl = lj1[itype][jtype] * 4.0 * epsilon[itype][jtype] *
(1.0/(denlj*denlj) - 1.0/denlj) - offset[itype][jtype];
evdwl *= factor_lj;
} else
evdwl = 0.0;
}
if (evflag) ev_tally_full(i, evdwl, ecoul, fpair, delx, dely, delz);
}
}
}
}

View File

@ -0,0 +1,46 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef PAIR_CLASS
// clang-format off
PairStyle(lj/cut/coul/long/soft/gpu,PairLJCutCoulLongSoftGPU);
// clang-format on
#else
#ifndef LMP_PAIR_LJ_CUT_COUL_LONG_SOFT_GPU_H
#define LMP_PAIR_LJ_CUT_COUL_LONG_SOFT_GPU_H
#include "pair_lj_cut_coul_long_soft.h"
namespace LAMMPS_NS {
class PairLJCutCoulLongSoftGPU : public PairLJCutCoulLongSoft {
public:
PairLJCutCoulLongSoftGPU(LAMMPS *lmp);
~PairLJCutCoulLongSoftGPU() override;
void cpu_compute(int, int, int, int, int *, int *, int **);
void compute(int, int) override;
void init_style() override;
void reinit() override;
double memory_usage() override;
enum { GPU_FORCE, GPU_NEIGH, GPU_HYB_NEIGH };
private:
int gpu_mode;
double cpu_time;
};
} // namespace LAMMPS_NS
#endif
#endif