1
/* ----------------------------------------------------------------------
2
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3
http://lammps.sandia.gov, Sandia National Laboratories
4
Steve Plimpton, sjplimp@sandia.gov
6
Copyright (2003) Sandia Corporation. Under the terms of Contract
7
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
8
certain rights in this software. This software is distributed under
9
the GNU General Public License.
11
See the README file in the top-level LAMMPS directory.
12
------------------------------------------------------------------------- */
14
/* ----------------------------------------------------------------------
15
Contributing author: Stan Moore (SNL)
16
------------------------------------------------------------------------- */
22
#include "pair_buck_kokkos.h"
24
#include "atom_kokkos.h"
28
#include "neigh_list.h"
29
#include "neigh_request.h"
31
#include "integrate.h"
33
#include "math_const.h"
36
#include "atom_masks.h"
38
using namespace LAMMPS_NS;
39
using namespace MathConst;
41
#define KOKKOS_CUDA_MAX_THREADS 256
42
#define KOKKOS_CUDA_MIN_BLOCKS 8
44
/* ---------------------------------------------------------------------- */
46
template<class DeviceType>
47
PairBuckKokkos<DeviceType>::PairBuckKokkos(LAMMPS *lmp) : PairBuck(lmp)
51
atomKK = (AtomKokkos *) atom;
52
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
53
datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK;
54
datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK;
58
/* ---------------------------------------------------------------------- */
60
template<class DeviceType>
61
PairBuckKokkos<DeviceType>::~PairBuckKokkos()
64
memory->destroy_kokkos(k_eatom,eatom);
65
memory->destroy_kokkos(k_vatom,vatom);
66
k_cutsq = DAT::tdual_ffloat_2d();
74
/* ---------------------------------------------------------------------- */
76
template<class DeviceType>
77
void PairBuckKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
82
if (neighflag == FULL || neighflag == FULLCLUSTER) no_virial_fdotr_compute = 1;
84
if (eflag || vflag) ev_setup(eflag,vflag);
85
else evflag = vflag_fdotr = 0;
87
// reallocate per-atom arrays if necessary
90
memory->destroy_kokkos(k_eatom,eatom);
91
memory->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom");
92
d_eatom = k_eatom.view<DeviceType>();
95
memory->destroy_kokkos(k_vatom,vatom);
96
memory->create_kokkos(k_vatom,vatom,maxvatom,6,"pair:vatom");
97
d_vatom = k_vatom.view<DeviceType>();
100
atomKK->sync(execution_space,datamask_read);
101
k_cutsq.template sync<DeviceType>();
102
k_params.template sync<DeviceType>();
103
if (eflag || vflag) atomKK->modified(execution_space,datamask_modify);
104
else atomKK->modified(execution_space,F_MASK);
106
x = atomKK->k_x.view<DeviceType>();
107
c_x = atomKK->k_x.view<DeviceType>();
108
f = atomKK->k_f.view<DeviceType>();
109
type = atomKK->k_type.view<DeviceType>();
110
tag = atomKK->k_tag.view<DeviceType>();
111
nlocal = atom->nlocal;
112
nall = atom->nlocal + atom->nghost;
113
newton_pair = force->newton_pair;
114
special_lj[0] = force->special_lj[0];
115
special_lj[1] = force->special_lj[1];
116
special_lj[2] = force->special_lj[2];
117
special_lj[3] = force->special_lj[3];
119
// loop over neighbors of my atoms
122
EV_FLOAT ev = pair_compute<PairBuckKokkos<DeviceType>,void >(this,(NeighListKokkos<DeviceType>*)list);
125
if (eflag_global) eng_vdwl += ev.evdwl;
127
virial[0] += ev.v[0];
128
virial[1] += ev.v[1];
129
virial[2] += ev.v[2];
130
virial[3] += ev.v[3];
131
virial[4] += ev.v[4];
132
virial[5] += ev.v[5];
135
if (vflag_fdotr) pair_virial_fdotr_compute(this);
138
k_eatom.template modify<DeviceType>();
139
k_eatom.template sync<LMPHostType>();
143
k_vatom.template modify<DeviceType>();
144
k_vatom.template sync<LMPHostType>();
150
template<class DeviceType>
151
template<bool STACKPARAMS, class Specialisation>
152
KOKKOS_INLINE_FUNCTION
153
F_FLOAT PairBuckKokkos<DeviceType>::
154
compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const {
157
const F_FLOAT r2inv = 1.0/rsq;
158
const F_FLOAT r6inv = r2inv*r2inv*r2inv;
159
const F_FLOAT r = sqrt(rsq);
160
const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv));
162
const F_FLOAT forcebuck =
163
(STACKPARAMS?m_params[itype][jtype].buck1:params(itype,jtype).buck1)*r*rexp -
164
(STACKPARAMS?m_params[itype][jtype].buck2:params(itype,jtype).buck2)*r6inv;
166
return forcebuck*r2inv;
169
template<class DeviceType>
170
template<bool STACKPARAMS, class Specialisation>
171
KOKKOS_INLINE_FUNCTION
172
F_FLOAT PairBuckKokkos<DeviceType>::
173
compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const {
176
const F_FLOAT r2inv = 1.0/rsq;
177
const F_FLOAT r6inv = r2inv*r2inv*r2inv;
178
const F_FLOAT r = sqrt(rsq);
179
const F_FLOAT rexp = exp(-r*(STACKPARAMS?m_params[itype][jtype].rhoinv:params(itype,jtype).rhoinv));
182
return (STACKPARAMS?m_params[itype][jtype].a:params(itype,jtype).a)*rexp -
183
(STACKPARAMS?m_params[itype][jtype].c:params(itype,jtype).c)*r6inv -
184
(STACKPARAMS?m_params[itype][jtype].offset:params(itype,jtype).offset);
187
/* ----------------------------------------------------------------------
189
------------------------------------------------------------------------- */
191
template<class DeviceType>
192
void PairBuckKokkos<DeviceType>::allocate()
194
PairBuck::allocate();
196
int n = atom->ntypes;
197
memory->destroy(cutsq);
198
memory->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq");
199
d_cutsq = k_cutsq.template view<DeviceType>();
200
k_params = Kokkos::DualView<params_buck**,Kokkos::LayoutRight,DeviceType>("PairBuck::params",n+1,n+1);
201
params = k_params.d_view;
204
/* ----------------------------------------------------------------------
205
init specific to this pair style
206
------------------------------------------------------------------------- */
208
template<class DeviceType>
209
void PairBuckKokkos<DeviceType>::init_style()
211
PairBuck::init_style();
213
// error if rRESPA with inner levels
215
if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) {
217
if (((Respa *) update->integrate)->level_inner >= 0) respa = 1;
218
if (((Respa *) update->integrate)->level_middle >= 0) respa = 2;
220
error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle");
223
// irequest = neigh request made by parent class
225
neighflag = lmp->kokkos->neighflag;
226
int irequest = neighbor->nrequest - 1;
228
neighbor->requests[irequest]->
229
kokkos_host = Kokkos::Impl::is_same<DeviceType,LMPHostType>::value &&
230
!Kokkos::Impl::is_same<DeviceType,LMPDeviceType>::value;
231
neighbor->requests[irequest]->
232
kokkos_device = Kokkos::Impl::is_same<DeviceType,LMPDeviceType>::value;
234
if (neighflag == FULL) {
235
neighbor->requests[irequest]->full = 1;
236
neighbor->requests[irequest]->half = 0;
237
neighbor->requests[irequest]->full_cluster = 0;
238
} else if (neighflag == HALF || neighflag == HALFTHREAD) {
239
neighbor->requests[irequest]->full = 0;
240
neighbor->requests[irequest]->half = 1;
241
neighbor->requests[irequest]->full_cluster = 0;
242
} else if (neighflag == N2) {
243
neighbor->requests[irequest]->full = 0;
244
neighbor->requests[irequest]->half = 0;
245
neighbor->requests[irequest]->full_cluster = 0;
246
} else if (neighflag == FULLCLUSTER) {
247
neighbor->requests[irequest]->full_cluster = 1;
248
neighbor->requests[irequest]->full = 1;
249
neighbor->requests[irequest]->half = 0;
251
error->all(FLERR,"Cannot use chosen neighbor list style with buck/kk");
255
/* ----------------------------------------------------------------------
256
init for one type pair i,j and corresponding j,i
257
------------------------------------------------------------------------- */
259
template<class DeviceType>
260
double PairBuckKokkos<DeviceType>::init_one(int i, int j)
262
double cutone = PairBuck::init_one(i,j);
264
k_params.h_view(i,j).a = a[i][j];
265
k_params.h_view(i,j).c = c[i][j];
266
k_params.h_view(i,j).rhoinv = rhoinv[i][j];
267
k_params.h_view(i,j).buck1 = buck1[i][j];
268
k_params.h_view(i,j).buck2 = buck2[i][j];
269
k_params.h_view(i,j).offset = offset[i][j];
270
k_params.h_view(i,j).cutsq = cutone*cutone;
271
k_params.h_view(j,i) = k_params.h_view(i,j);
272
if(i<MAX_TYPES_STACKPARAMS+1 && j<MAX_TYPES_STACKPARAMS+1) {
273
m_params[i][j] = m_params[j][i] = k_params.h_view(i,j);
274
m_cutsq[j][i] = m_cutsq[i][j] = cutone*cutone;
276
k_cutsq.h_view(i,j) = cutone*cutone;
277
k_cutsq.template modify<LMPHostType>();
278
k_params.template modify<LMPHostType>();
283
template class PairBuckKokkos<LMPDeviceType>;
284
#ifdef KOKKOS_HAVE_CUDA
285
template class PairBuckKokkos<LMPHostType>;
b'\\ No newline at end of file'