diff --git a/lib/gpu/lal_coul.cpp b/lib/gpu/lal_coul.cpp new file mode 100644 index 0000000000..53fb3dae82 --- /dev/null +++ b/lib/gpu/lal_coul.cpp @@ -0,0 +1,166 @@ +/*************************************************************************** + coul.cpp + ------------------- + Trung Dac Nguyen + + Class for acceleration of the coul/cut pair style. + + __________________________________________________________________________ + This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) + __________________________________________________________________________ + + begin : + email : ndtrung@umich.edu + ***************************************************************************/ + +#if defined(USE_OPENCL) +#include "coul_cl.h" +#elif defined(USE_CUDART) +const char *coul=0; +#else +#include "coul_cubin.h" +#endif + +#include "lal_coul.h" +#include +using namespace LAMMPS_AL; +#define CoulT Coul + +extern Device device; + +template +CoulT::Coul() : BaseCharge(), + _allocated(false) { +} + +template +CoulT::~Coul() { + clear(); +} + +template +int CoulT::bytes_per_atom(const int max_nbors) const { + return this->bytes_per_atom_atomic(max_nbors); +} + +template +int CoulT::init(const int ntypes, double **host_scale, double **host_cutsq, + double *host_special_coul, const int nlocal, + const int nall, const int max_nbors, + const int maxspecial, const double cell_size, + const double gpu_split, FILE *_screen, + const double qqrd2e) { + int success; + success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split, + _screen,coul,"k_coul"); + 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 host_write(lj_types*lj_types*32,*(this->ucl_device), + UCL_WRITE_ONLY); + + for (int i=0; iucl_device),UCL_READ_ONLY); + this->atom->type_pack1(ntypes,lj_types,scale,host_write,host_scale); + + 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_cl.alloc(4,*(this->ucl_device),UCL_READ_ONLY); + for (int i=0; i<4; i++) { + host_write[i]=host_special_coul[i]; + } + ucl_copy(sp_cl,host_write,4,false); + + _qqrd2e=qqrd2e; + + _allocated=true; + this->_max_bytes=cutsq.row_bytes()+sp_cl.row_bytes(); + return 0; +} + +template +void CoulT::reinit(const int ntypes, double **host_scale) { + // Allocate a host write buffer for data initialization + UCL_H_Vec 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_pack1(ntypes,_lj_types,scale,host_write,host_scale); +} + +template +void CoulT::clear() { + if (!_allocated) + return; + _allocated=false; + + scale.clear(); + cutsq.clear(); + sp_cl.clear(); + this->clear_atomic(); +} + +template +double CoulT::host_memory_usage() const { + return this->host_memory_usage_atomic()+sizeof(Coul); +} + +// --------------------------------------------------------------------------- +// Calculate energies, forces, and torques +// --------------------------------------------------------------------------- +template +void CoulT::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(ceil(static_cast(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, &scale, &sp_cl, + &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, &scale, &_lj_types, &sp_cl, + &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(); +} + +template class Coul; diff --git a/lib/gpu/lal_coul.cu b/lib/gpu/lal_coul.cu new file mode 100644 index 0000000000..7f8b9af6a0 --- /dev/null +++ b/lib/gpu/lal_coul.cu @@ -0,0 +1,211 @@ +// ************************************************************************** +// coul.cu +// ------------------- +// Trung Dac Nguyen +// +// Device code for acceleration of the coul/cut pair style +// +// __________________________________________________________________________ +// This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) +// __________________________________________________________________________ +// +// begin : +// email : ndtrung@umich.edu +// ***************************************************************************/ + +#ifdef NV_KERNEL + +#include "lal_aux_fun1.h" +#ifndef _DOUBLE_DOUBLE +texture pos_tex; +texture q_tex; +#else +texture pos_tex; +texture q_tex; +#endif + +#else +#define pos_tex x_ +#define q_tex q_ +#endif + +__kernel void k_coul(const __global numtyp4 *restrict x_, + const __global numtyp *restrict scale, + const int lj_types, + const __global numtyp *restrict sp_cl_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_cl[8]; + sp_cl[0]=sp_cl_in[0]; + sp_cl[1]=sp_cl_in[1]; + sp_cl[2]=sp_cl_in[2]; + sp_cl[3]=sp_cl_in[3]; + + acctyp energy=(acctyp)0; + acctyp e_coul=(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 (ii0) { + e_coul += forcecoul; + } + 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_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag, + vflag,ans,engv); + } // if ii +} + +__kernel void k_coul_fast(const __global numtyp4 *restrict x_, + const __global numtyp *restrict scale, + const __global numtyp *restrict sp_cl_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 cutsq[MAX_SHARED_TYPES*MAX_SHARED_TYPES]; + __local numtyp sp_cl[4]; + if (tid<4) + sp_cl[tid]=sp_cl_in[tid]; + if (tid0) { + e_coul += forcecoul; + } + 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_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag, + vflag,ans,engv); + } // if ii +} + diff --git a/lib/gpu/lal_coul.h b/lib/gpu/lal_coul.h new file mode 100644 index 0000000000..4374abd80d --- /dev/null +++ b/lib/gpu/lal_coul.h @@ -0,0 +1,83 @@ +/*************************************************************************** + coul.h + ------------------- + Trung Dac Nguyen + + Class for acceleration of the coul/cut pair style. + + __________________________________________________________________________ + This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) + __________________________________________________________________________ + + begin : + email : ndtrung@umich.edu + ***************************************************************************/ + +#ifndef LAL_COUL_H +#define LAL_COUL_H + +#include "lal_base_charge.h" + +namespace LAMMPS_AL { + +template +class Coul : public BaseCharge { + public: + Coul(); + ~Coul(); + + /// 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_scale, + double **host_cutsq, double *host_special_coul, + const int nlocal, const int nall, const int max_nbors, + const int maxspecial, const double cell_size, + const double gpu_split, FILE *screen, const double qqrd2e); + + /// Send updated coeffs from host to device (to be compatible with fix adapt) + void reinit(const int ntypes, double **host_scale); + + /// 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 -------------------------- + + /// cutsq + UCL_D_Vec scale; + /// cutsq + UCL_D_Vec cutsq; + /// Special Coul values [0-3] + UCL_D_Vec sp_cl; + + /// 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; + void loop(const bool _eflag, const bool _vflag); +}; + +} + +#endif diff --git a/lib/gpu/lal_coul_debye.cpp b/lib/gpu/lal_coul_debye.cpp new file mode 100644 index 0000000000..990dff6db9 --- /dev/null +++ b/lib/gpu/lal_coul_debye.cpp @@ -0,0 +1,167 @@ +/*************************************************************************** + coul_debye.cpp + ------------------- + Trung Dac Nguyen + + Class for acceleration of the coul/debye pair style. + + __________________________________________________________________________ + This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) + __________________________________________________________________________ + + begin : + email : ndtrung@umich.edu + ***************************************************************************/ + +#ifdef USE_OPENCL +#include "coul_debye_cl.h" +#elif defined(USE_CUDART) +const char *coul_debye=0; +#else +#include "coul_debye_cubin.h" +#endif + +#include "lal_coul_debye.h" +#include +using namespace LAMMPS_AL; +#define CoulDebyeT CoulDebye + +extern Device device; + +template +CoulDebyeT::CoulDebye() : BaseCharge(), + _allocated(false) { +} + +template +CoulDebyeT::~CoulDebye() { + clear(); +} + +template +int CoulDebyeT::bytes_per_atom(const int max_nbors) const { + return this->bytes_per_atom_atomic(max_nbors); +} + +template +int CoulDebyeT::init(const int ntypes, double **host_scale, + double **host_cutsq, double *host_special_coul, + const int nlocal, const int nall, const int max_nbors, + const int maxspecial, const double cell_size, + const double gpu_split, FILE *_screen, + const double qqrd2e, const double kappa) { + int success; + success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split, + _screen,coul_debye,"k_coul_debye"); + 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 host_write(lj_types*lj_types*32,*(this->ucl_device), + UCL_WRITE_ONLY); + + for (int i=0; iucl_device),UCL_READ_ONLY); + this->atom->type_pack1(ntypes,lj_types,scale,host_write,host_scale); + + 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_cl.alloc(4,*(this->ucl_device),UCL_READ_ONLY); + for (int i=0; i<4; i++) { + host_write[i]=host_special_coul[i]; + } + ucl_copy(sp_cl,host_write,4,false); + + _qqrd2e=qqrd2e; + _kappa=kappa; + + _allocated=true; + this->_max_bytes=cutsq.row_bytes()+scale.row_bytes()+sp_cl.row_bytes(); + return 0; +} + +template +void CoulDebyeT::reinit(const int ntypes, double **host_scale) { + // Allocate a host write buffer for data initialization + UCL_H_Vec 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_pack1(ntypes,_lj_types,scale,host_write,host_scale); +} + +template +void CoulDebyeT::clear() { + if (!_allocated) + return; + _allocated=false; + + scale.clear(); + cutsq.clear(); + sp_cl.clear(); + this->clear_atomic(); +} + +template +double CoulDebyeT::host_memory_usage() const { + return this->host_memory_usage_atomic()+sizeof(CoulDebye); +} + +// --------------------------------------------------------------------------- +// Calculate energies, forces, and torques +// --------------------------------------------------------------------------- +template +void CoulDebyeT::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(ceil(static_cast(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, &scale, &sp_cl, + &this->nbor->dev_nbor, &this->_nbor_data->begin(), + &this->ans->force, &this->ans->engv, &eflag, &vflag, + &ainum, &nbor_pitch, &this->atom->q, &cutsq, + &_qqrd2e, &_kappa, &this->_threads_per_atom); + } else { + this->k_pair.set_size(GX,BX); + this->k_pair.run(&this->atom->x, &scale, &_lj_types, &sp_cl, + &this->nbor->dev_nbor, &this->_nbor_data->begin(), + &this->ans->force, &this->ans->engv, &eflag, &vflag, + &ainum, &nbor_pitch, &this->atom->q, &cutsq, + &_qqrd2e, &_kappa, &this->_threads_per_atom); + } + this->time_pair.stop(); +} + +template class CoulDebye; diff --git a/lib/gpu/lal_coul_debye.cu b/lib/gpu/lal_coul_debye.cu new file mode 100644 index 0000000000..a1c5da34ba --- /dev/null +++ b/lib/gpu/lal_coul_debye.cu @@ -0,0 +1,220 @@ +// ************************************************************************** +// coul_debye.cu +// ------------------- +// Trung Dac Nguyen +// +// Device code for acceleration of the coul/debye pair style +// +// __________________________________________________________________________ +// This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) +// __________________________________________________________________________ +// +// begin : +// email : ndtrung@umich.edu +// ***************************************************************************/ + +#ifdef NV_KERNEL + +#include "lal_aux_fun1.h" +#ifndef _DOUBLE_DOUBLE +texture pos_tex; +texture q_tex; +#else +texture pos_tex; +texture q_tex; +#endif + +#else +#define pos_tex x_ +#define q_tex q_ +#endif + +__kernel void k_coul_debye(const __global numtyp4 *restrict x_, + const __global numtyp *restrict scale, + const int lj_types, + const __global numtyp *restrict sp_cl_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 numtyp kappa, + const int t_per_atom) { + int tid, ii, offset; + atom_info(t_per_atom,ii,tid,offset); + + __local numtyp sp_cl[4]; + sp_cl[0]=sp_cl_in[0]; + sp_cl[1]=sp_cl_in[1]; + sp_cl[2]=sp_cl_in[2]; + sp_cl[3]=sp_cl_in[3]; + + acctyp energy=(acctyp)0; + acctyp e_coul=(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 (ii0) { + e_coul+=qqrd2e*scale[mtype]*qtmp*rinv*screening*factor_coul; + } + 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_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag, + vflag,ans,engv); + } // if ii +} + +__kernel void k_coul_debye_fast(const __global numtyp4 *restrict x_, + const __global numtyp *restrict scale_in, + const __global numtyp *restrict sp_cl_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 numtyp kappa, + const int t_per_atom) { + int tid, ii, offset; + atom_info(t_per_atom,ii,tid,offset); + + __local numtyp scale[MAX_SHARED_TYPES*MAX_SHARED_TYPES]; + __local numtyp cutsq[MAX_SHARED_TYPES*MAX_SHARED_TYPES]; + __local numtyp sp_cl[4]; + if (tid<4) + sp_cl[tid]=sp_cl_in[tid]; + if (tid0) { + e_coul+=qqrd2e*scale[mtype]*qtmp*rinv*screening*factor_coul; + } + 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_q(f,energy,e_coul,virial,ii,inum,tid,t_per_atom,offset,eflag, + vflag,ans,engv); + } // if ii +} + diff --git a/lib/gpu/lal_coul_debye.h b/lib/gpu/lal_coul_debye.h new file mode 100644 index 0000000000..885f08cd34 --- /dev/null +++ b/lib/gpu/lal_coul_debye.h @@ -0,0 +1,84 @@ +/*************************************************************************** + coul_debye.h + ------------------- + Trung Dac Nguyen + + Class for acceleration of the coul/debye pair style. + + __________________________________________________________________________ + This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) + __________________________________________________________________________ + + begin : + email : ndtrung@umich.edu + ***************************************************************************/ + +#ifndef LAL_COUL_DEBYE_H +#define LAL_COUL_DEBYE_H + +#include "lal_base_charge.h" + +namespace LAMMPS_AL { + +template +class CoulDebye : public BaseCharge { + public: + CoulDebye(); + ~CoulDebye(); + + /// 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_scale, + double **host_cutsq, double *host_special_coul, + const int nlocal, const int nall, const int max_nbors, + const int maxspecial, const double cell_size, + const double gpu_split, FILE *screen, + const double qqrd2e, const double kappa); + + /// Send updated coeffs from host to device (to be compatible with fix adapt) + void reinit(const int ntypes, double **host_scale); + + /// 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 -------------------------- + + /// scale + UCL_D_Vec scale; + /// cutsq + UCL_D_Vec cutsq; + /// Special Coul values [0-3] + UCL_D_Vec sp_cl; + + /// If atom type constants fit in shared memory, use fast kernels + bool shared_types; + + /// Number of atom types + int _lj_types; + + numtyp _qqrd2e,_kappa; + + private: + bool _allocated; + void loop(const bool _eflag, const bool _vflag); +}; + +} + +#endif diff --git a/lib/gpu/lal_coul_debye_ext.cpp b/lib/gpu/lal_coul_debye_ext.cpp new file mode 100644 index 0000000000..ced08b63e4 --- /dev/null +++ b/lib/gpu/lal_coul_debye_ext.cpp @@ -0,0 +1,143 @@ +/*************************************************************************** + coul_debye_ext.cpp + ------------------- + Trung Dac Nguyen + + Functions for LAMMPS access to coul/debye acceleration routines. + + __________________________________________________________________________ + This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) + __________________________________________________________________________ + + begin : + email : ndtrung@umich.edu + ***************************************************************************/ + +#include +#include +#include + +#include "lal_coul_debye.h" + +using namespace std; +using namespace LAMMPS_AL; + +static CoulDebye CDEMF; + +// --------------------------------------------------------------------------- +// Allocate memory on host and device and copy constants to device +// --------------------------------------------------------------------------- +int cdebye_gpu_init(const int ntypes, double **host_scale, double **cutsq, + double *host_special_coul, const int inum, + const int nall, const int max_nbors, const int maxspecial, + const double cell_size, int &gpu_mode, FILE *screen, + const double qqrd2e, const double kappa) { + CDEMF.clear(); + gpu_mode=CDEMF.device->gpu_mode(); + double gpu_split=CDEMF.device->particle_split(); + int first_gpu=CDEMF.device->first_device(); + int last_gpu=CDEMF.device->last_device(); + int world_me=CDEMF.device->world_me(); + int gpu_rank=CDEMF.device->gpu_rank(); + int procs_per_gpu=CDEMF.device->procs_per_gpu(); + + CDEMF.device->init_message(screen,"coul/debye",first_gpu,last_gpu); + + bool message=false; + if (CDEMF.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) + init_ok=CDEMF.init(ntypes, host_scale, cutsq, host_special_coul, inum, nall, 300, + maxspecial, cell_size, gpu_split, screen, qqrd2e, kappa); + + CDEMF.device->world_barrier(); + if (message) + fprintf(screen,"Done.\n"); + + for (int i=0; igpu_barrier(); + if (message) + fprintf(screen,"Done.\n"); + } + if (message) + fprintf(screen,"\n"); + + if (init_ok==0) + CDEMF.estimate_gpu_overhead(); + return init_ok; +} + +// --------------------------------------------------------------------------- +// Copy updated constants to device +// --------------------------------------------------------------------------- +void cdebye_gpu_reinit(const int ntypes, double **host_scale) { + int world_me=CDEMF.device->world_me(); + int gpu_rank=CDEMF.device->gpu_rank(); + int procs_per_gpu=CDEMF.device->procs_per_gpu(); + + if (world_me==0) + CDEMF.reinit(ntypes, host_scale); + + CDEMF.device->world_barrier(); + + for (int i=0; igpu_barrier(); + } +} + +void cdebye_gpu_clear() { + CDEMF.clear(); +} + +int** cdebye_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 CDEMF.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 cdebye_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) { + CDEMF.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 cdebye_gpu_bytes() { + return CDEMF.host_memory_usage(); +} + + diff --git a/lib/gpu/lal_coul_ext.cpp b/lib/gpu/lal_coul_ext.cpp new file mode 100644 index 0000000000..291546d5b1 --- /dev/null +++ b/lib/gpu/lal_coul_ext.cpp @@ -0,0 +1,143 @@ +/*************************************************************************** + coul_ext.cpp + ------------------- + Trung Dac Nguyen + + Functions for LAMMPS access to coul/cut acceleration routines. + + __________________________________________________________________________ + This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) + __________________________________________________________________________ + + begin : + email : ndtrung@umich.edu + ***************************************************************************/ + +#include +#include +#include + +#include "lal_coul.h" + +using namespace std; +using namespace LAMMPS_AL; + +static Coul COULMF; + +// --------------------------------------------------------------------------- +// Allocate memory on host and device and copy constants to device +// --------------------------------------------------------------------------- +int coul_gpu_init(const int ntypes, double **host_scale, + double **cutsq, double *special_coul, + const int inum, const int nall, const int max_nbors, + const int maxspecial, const double cell_size, + int &gpu_mode, FILE *screen, const double qqrd2e) { + COULMF.clear(); + gpu_mode=COULMF.device->gpu_mode(); + double gpu_split=COULMF.device->particle_split(); + int first_gpu=COULMF.device->first_device(); + int last_gpu=COULMF.device->last_device(); + int world_me=COULMF.device->world_me(); + int gpu_rank=COULMF.device->gpu_rank(); + int procs_per_gpu=COULMF.device->procs_per_gpu(); + + COULMF.device->init_message(screen,"coul/cut",first_gpu,last_gpu); + + bool message=false; + if (COULMF.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) + init_ok=COULMF.init(ntypes, host_scale, cutsq, special_coul, inum, nall, 300, + maxspecial, cell_size, gpu_split, screen, qqrd2e); + + COULMF.device->world_barrier(); + if (message) + fprintf(screen,"Done.\n"); + + for (int i=0; igpu_barrier(); + if (message) + fprintf(screen,"Done.\n"); + } + if (message) + fprintf(screen,"\n"); + + if (init_ok==0) + COULMF.estimate_gpu_overhead(); + return init_ok; +} + +// --------------------------------------------------------------------------- +// Copy updated constants to device +// --------------------------------------------------------------------------- +void coul_gpu_reinit(const int ntypes, double **host_scale) { + int world_me=COULMF.device->world_me(); + int gpu_rank=COULMF.device->gpu_rank(); + int procs_per_gpu=COULMF.device->procs_per_gpu(); + + if (world_me==0) + COULMF.reinit(ntypes, host_scale); + + COULMF.device->world_barrier(); + + for (int i=0; igpu_barrier(); + } +} + +void coul_gpu_clear() { + COULMF.clear(); +} + +int** coul_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 COULMF.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 coul_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) { + COULMF.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 coul_gpu_bytes() { + return COULMF.host_memory_usage(); +} + +