1
/***************************************************************************
6
Class for acceleration of the coul/cut pair style.
8
__________________________________________________________________________
9
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
10
__________________________________________________________________________
13
email : ndtrung@umich.edu
14
***************************************************************************/
16
#if defined(USE_OPENCL)
18
#elif defined(USE_CUDART)
21
#include "coul_cubin.h"
26
using namespace LAMMPS_AL;
27
#define CoulT Coul<numtyp, acctyp>
29
extern Device<PRECISION,ACC_PRECISION> device;
31
template <class numtyp, class acctyp>
32
CoulT::Coul() : BaseCharge<numtyp,acctyp>(),
36
template <class numtyp, class acctyp>
41
template <class numtyp, class acctyp>
42
int CoulT::bytes_per_atom(const int max_nbors) const {
43
return this->bytes_per_atom_atomic(max_nbors);
46
template <class numtyp, class acctyp>
47
int CoulT::init(const int ntypes, double **host_scale, double **host_cutsq,
48
double *host_special_coul, const int nlocal,
49
const int nall, const int max_nbors,
50
const int maxspecial, const double cell_size,
51
const double gpu_split, FILE *_screen,
52
const double qqrd2e) {
54
success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
55
_screen,coul,"k_coul");
59
// If atom type constants fit in shared memory use fast kernel
62
int max_shared_types=this->device->max_shared_types();
63
if (lj_types<=max_shared_types && this->_block_size>=max_shared_types) {
64
lj_types=max_shared_types;
69
// Allocate a host write buffer for data initialization
70
UCL_H_Vec<numtyp> host_write(lj_types*lj_types*32,*(this->ucl_device),
73
for (int i=0; i<lj_types*lj_types; i++)
76
scale.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
77
this->atom->type_pack1(ntypes,lj_types,scale,host_write,host_scale);
79
cutsq.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
80
this->atom->type_pack1(ntypes,lj_types,cutsq,host_write,host_cutsq);
82
sp_cl.alloc(4,*(this->ucl_device),UCL_READ_ONLY);
83
for (int i=0; i<4; i++) {
84
host_write[i]=host_special_coul[i];
86
ucl_copy(sp_cl,host_write,4,false);
91
this->_max_bytes=cutsq.row_bytes()+sp_cl.row_bytes();
95
template <class numtyp, class acctyp>
96
void CoulT::reinit(const int ntypes, double **host_scale) {
97
// Allocate a host write buffer for data initialization
98
UCL_H_Vec<numtyp> host_write(_lj_types*_lj_types*32,*(this->ucl_device),
101
for (int i=0; i<_lj_types*_lj_types; i++)
104
this->atom->type_pack1(ntypes,_lj_types,scale,host_write,host_scale);
107
template <class numtyp, class acctyp>
108
void CoulT::clear() {
116
this->clear_atomic();
119
template <class numtyp, class acctyp>
120
double CoulT::host_memory_usage() const {
121
return this->host_memory_usage_atomic()+sizeof(Coul<numtyp,acctyp>);
124
// ---------------------------------------------------------------------------
125
// Calculate energies, forces, and torques
126
// ---------------------------------------------------------------------------
127
template <class numtyp, class acctyp>
128
void CoulT::loop(const bool _eflag, const bool _vflag) {
129
// Compute the block size and grid size to keep all cores busy
130
const int BX=this->block_size();
142
int GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/
143
(BX/this->_threads_per_atom)));
145
int ainum=this->ans->inum();
146
int nbor_pitch=this->nbor->nbor_pitch();
147
this->time_pair.start();
149
this->k_pair_fast.set_size(GX,BX);
150
this->k_pair_fast.run(&this->atom->x, &scale, &sp_cl,
151
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
152
&this->ans->force, &this->ans->engv, &eflag,
153
&vflag, &ainum, &nbor_pitch, &this->atom->q,
154
&cutsq, &_qqrd2e, &this->_threads_per_atom);
156
this->k_pair.set_size(GX,BX);
157
this->k_pair.run(&this->atom->x, &scale, &_lj_types, &sp_cl,
158
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
159
&this->ans->force, &this->ans->engv,
160
&eflag, &vflag, &ainum, &nbor_pitch, &this->atom->q,
161
&cutsq, &_qqrd2e, &this->_threads_per_atom);
163
this->time_pair.stop();
166
template class Coul<PRECISION,ACC_PRECISION>;