Add Kokkos version of pair_style soft
This commit is contained in:
@ -363,6 +363,8 @@ action pair_reaxff_kokkos.h pair_reaxff.h
|
|||||||
action pair_snap_kokkos_impl.h pair_snap.cpp
|
action pair_snap_kokkos_impl.h pair_snap.cpp
|
||||||
action pair_snap_kokkos.cpp pair_snap.cpp
|
action pair_snap_kokkos.cpp pair_snap.cpp
|
||||||
action pair_snap_kokkos.h pair_snap.h
|
action pair_snap_kokkos.h pair_snap.h
|
||||||
|
action pair_soft_kokkos.cpp
|
||||||
|
action pair_soft_kokkos.h
|
||||||
action pair_sw_kokkos.cpp pair_sw.cpp
|
action pair_sw_kokkos.cpp pair_sw.cpp
|
||||||
action pair_sw_kokkos.h pair_sw.h
|
action pair_sw_kokkos.h pair_sw.h
|
||||||
action pair_table_kokkos.cpp
|
action pair_table_kokkos.cpp
|
||||||
|
|||||||
255
src/KOKKOS/pair_soft_kokkos.cpp
Normal file
255
src/KOKKOS/pair_soft_kokkos.cpp
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
// clang-format off
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||||
|
https://www.lammps.org/, Sandia National Laboratories
|
||||||
|
LAMMPS development team: developers@lammps.org
|
||||||
|
|
||||||
|
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.
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include "pair_soft_kokkos.h"
|
||||||
|
|
||||||
|
#include "atom_kokkos.h"
|
||||||
|
#include "atom_masks.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "force.h"
|
||||||
|
#include "kokkos.h"
|
||||||
|
#include "math_const.h"
|
||||||
|
#include "memory_kokkos.h"
|
||||||
|
#include "neigh_request.h"
|
||||||
|
#include "neighbor.h"
|
||||||
|
#include "respa.h"
|
||||||
|
#include "update.h"
|
||||||
|
|
||||||
|
using namespace LAMMPS_NS;
|
||||||
|
using namespace MathConst;
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
PairSoftKokkos<DeviceType>::PairSoftKokkos(LAMMPS *lmp) : PairSoft(lmp)
|
||||||
|
{
|
||||||
|
respa_enable = 0;
|
||||||
|
|
||||||
|
kokkosable = 1;
|
||||||
|
atomKK = (AtomKokkos *) atom;
|
||||||
|
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
|
||||||
|
datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK;
|
||||||
|
datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
PairSoftKokkos<DeviceType>::~PairSoftKokkos()
|
||||||
|
{
|
||||||
|
if (copymode) return;
|
||||||
|
|
||||||
|
if (allocated) {
|
||||||
|
memoryKK->destroy_kokkos(k_eatom,eatom);
|
||||||
|
memoryKK->destroy_kokkos(k_vatom,vatom);
|
||||||
|
memoryKK->destroy_kokkos(k_cutsq,cutsq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
void PairSoftKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
|
||||||
|
{
|
||||||
|
eflag = eflag_in;
|
||||||
|
vflag = vflag_in;
|
||||||
|
|
||||||
|
if (neighflag == FULL) no_virial_fdotr_compute = 1;
|
||||||
|
|
||||||
|
ev_init(eflag,vflag,0);
|
||||||
|
|
||||||
|
// reallocate per-atom arrays if necessary
|
||||||
|
|
||||||
|
if (eflag_atom) {
|
||||||
|
memoryKK->destroy_kokkos(k_eatom,eatom);
|
||||||
|
memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom");
|
||||||
|
d_eatom = k_eatom.view<DeviceType>();
|
||||||
|
}
|
||||||
|
if (vflag_atom) {
|
||||||
|
memoryKK->destroy_kokkos(k_vatom,vatom);
|
||||||
|
memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom");
|
||||||
|
d_vatom = k_vatom.view<DeviceType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
atomKK->sync(execution_space,datamask_read);
|
||||||
|
k_cutsq.template sync<DeviceType>();
|
||||||
|
k_params.template sync<DeviceType>();
|
||||||
|
if (eflag || vflag) atomKK->modified(execution_space,datamask_modify);
|
||||||
|
else atomKK->modified(execution_space,F_MASK);
|
||||||
|
|
||||||
|
x = atomKK->k_x.view<DeviceType>();
|
||||||
|
c_x = atomKK->k_x.view<DeviceType>();
|
||||||
|
f = atomKK->k_f.view<DeviceType>();
|
||||||
|
type = atomKK->k_type.view<DeviceType>();
|
||||||
|
nlocal = atom->nlocal;
|
||||||
|
nall = atom->nlocal + atom->nghost;
|
||||||
|
newton_pair = force->newton_pair;
|
||||||
|
special_lj[0] = force->special_lj[0];
|
||||||
|
special_lj[1] = force->special_lj[1];
|
||||||
|
special_lj[2] = force->special_lj[2];
|
||||||
|
special_lj[3] = force->special_lj[3];
|
||||||
|
|
||||||
|
// loop over neighbors of my atoms
|
||||||
|
|
||||||
|
copymode = 1;
|
||||||
|
|
||||||
|
EV_FLOAT ev = pair_compute<PairSoftKokkos<DeviceType>,void >(this,(NeighListKokkos<DeviceType>*)list);
|
||||||
|
|
||||||
|
if (eflag_global) eng_vdwl += ev.evdwl;
|
||||||
|
if (vflag_global) {
|
||||||
|
virial[0] += ev.v[0];
|
||||||
|
virial[1] += ev.v[1];
|
||||||
|
virial[2] += ev.v[2];
|
||||||
|
virial[3] += ev.v[3];
|
||||||
|
virial[4] += ev.v[4];
|
||||||
|
virial[5] += ev.v[5];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eflag_atom) {
|
||||||
|
k_eatom.template modify<DeviceType>();
|
||||||
|
k_eatom.template sync<LMPHostType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vflag_atom) {
|
||||||
|
k_vatom.template modify<DeviceType>();
|
||||||
|
k_vatom.template sync<LMPHostType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vflag_fdotr) pair_virial_fdotr_compute(this);
|
||||||
|
|
||||||
|
copymode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
template<bool STACKPARAMS, class Specialisation>
|
||||||
|
KOKKOS_INLINE_FUNCTION
|
||||||
|
F_FLOAT PairSoftKokkos<DeviceType>::
|
||||||
|
compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const {
|
||||||
|
(void) i;
|
||||||
|
const F_FLOAT r = sqrt(rsq);
|
||||||
|
const F_FLOAT cut_ij = STACKPARAMS?m_params[itype][jtype].cut:params(itype,jtype).cut;
|
||||||
|
const F_FLOAT prefactor_ij = STACKPARAMS?m_params[itype][jtype].prefactor:params(itype,jtype).prefactor;
|
||||||
|
const F_FLOAT arg = MY_PI*r/cut_ij;
|
||||||
|
|
||||||
|
F_FLOAT fpair = 0.0;
|
||||||
|
if (r > 0.0) fpair = prefactor_ij *
|
||||||
|
sin(arg) * MY_PI/cut_ij/r;
|
||||||
|
|
||||||
|
return fpair;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
template<bool STACKPARAMS, class Specialisation>
|
||||||
|
KOKKOS_INLINE_FUNCTION
|
||||||
|
F_FLOAT PairSoftKokkos<DeviceType>::
|
||||||
|
compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const {
|
||||||
|
(void) i;
|
||||||
|
const F_FLOAT r = sqrt(rsq);
|
||||||
|
const F_FLOAT cut_ij = STACKPARAMS?m_params[itype][jtype].cut:params(itype,jtype).cut;
|
||||||
|
const F_FLOAT prefactor_ij = STACKPARAMS?m_params[itype][jtype].prefactor:params(itype,jtype).prefactor;
|
||||||
|
const F_FLOAT arg = MY_PI*r/cut_ij;
|
||||||
|
|
||||||
|
return prefactor_ij*(1.0+cos(arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
allocate all arrays
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
void PairSoftKokkos<DeviceType>::allocate()
|
||||||
|
{
|
||||||
|
PairSoft::allocate();
|
||||||
|
|
||||||
|
int n = atom->ntypes;
|
||||||
|
memory->destroy(cutsq);
|
||||||
|
memoryKK->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq");
|
||||||
|
d_cutsq = k_cutsq.template view<DeviceType>();
|
||||||
|
k_params = Kokkos::DualView<params_soft**,Kokkos::LayoutRight,DeviceType>("PairSoft::params",n+1,n+1);
|
||||||
|
params = k_params.template view<DeviceType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
global settings
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
void PairSoftKokkos<DeviceType>::settings(int narg, char **arg)
|
||||||
|
{
|
||||||
|
if (narg > 2) error->all(FLERR,"Illegal pair_style command");
|
||||||
|
|
||||||
|
PairSoft::settings(1,arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
init specific to this pair style
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
void PairSoftKokkos<DeviceType>::init_style()
|
||||||
|
{
|
||||||
|
PairSoft::init_style();
|
||||||
|
|
||||||
|
// error if rRESPA with inner levels
|
||||||
|
|
||||||
|
if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) {
|
||||||
|
int respa = 0;
|
||||||
|
if (((Respa *) update->integrate)->level_inner >= 0) respa = 1;
|
||||||
|
if (((Respa *) update->integrate)->level_middle >= 0) respa = 2;
|
||||||
|
if (respa)
|
||||||
|
error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle");
|
||||||
|
}
|
||||||
|
|
||||||
|
// adjust neighbor list request for KOKKOS
|
||||||
|
|
||||||
|
neighflag = lmp->kokkos->neighflag;
|
||||||
|
auto request = neighbor->find_request(this);
|
||||||
|
request->set_kokkos_host(std::is_same_v<DeviceType,LMPHostType> &&
|
||||||
|
!std::is_same_v<DeviceType,LMPDeviceType>);
|
||||||
|
request->set_kokkos_device(std::is_same_v<DeviceType,LMPDeviceType>);
|
||||||
|
if (neighflag == FULL) request->enable_full();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
init for one type pair i,j and corresponding j,i
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
double PairSoftKokkos<DeviceType>::init_one(int i, int j)
|
||||||
|
{
|
||||||
|
double cutone = PairSoft::init_one(i,j);
|
||||||
|
|
||||||
|
k_params.h_view(i,j).prefactor = prefactor[i][j];
|
||||||
|
k_params.h_view(i,j).cut = cutone;
|
||||||
|
k_params.h_view(i,j).cutsq = cutone*cutone;
|
||||||
|
k_params.h_view(j,i) = k_params.h_view(i,j);
|
||||||
|
if (i<MAX_TYPES_STACKPARAMS+1 && j<MAX_TYPES_STACKPARAMS+1) {
|
||||||
|
m_params[i][j] = m_params[j][i] = k_params.h_view(i,j);
|
||||||
|
m_cutsq[j][i] = m_cutsq[i][j] = cutone*cutone;
|
||||||
|
}
|
||||||
|
|
||||||
|
k_cutsq.h_view(i,j) = k_cutsq.h_view(j,i) = cutone*cutone;
|
||||||
|
k_cutsq.template modify<LMPHostType>();
|
||||||
|
k_params.template modify<LMPHostType>();
|
||||||
|
|
||||||
|
return cutone;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace LAMMPS_NS {
|
||||||
|
template class PairSoftKokkos<LMPDeviceType>;
|
||||||
|
#ifdef LMP_KOKKOS_GPU
|
||||||
|
template class PairSoftKokkos<LMPHostType>;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
114
src/KOKKOS/pair_soft_kokkos.h
Normal file
114
src/KOKKOS/pair_soft_kokkos.h
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/* -*- c++ -*- ----------------------------------------------------------
|
||||||
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||||
|
https://www.lammps.org/, Sandia National Laboratories
|
||||||
|
LAMMPS development team: developers@lammps.org
|
||||||
|
|
||||||
|
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(soft/kk,PairSoftKokkos<LMPDeviceType>);
|
||||||
|
PairStyle(soft/kk/device,PairSoftKokkos<LMPDeviceType>);
|
||||||
|
PairStyle(soft/kk/host,PairSoftKokkos<LMPHostType>);
|
||||||
|
// clang-format on
|
||||||
|
#else
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
#ifndef LMP_PAIR_SOFT_KOKKOS_H
|
||||||
|
#define LMP_PAIR_SOFT_KOKKOS_H
|
||||||
|
|
||||||
|
#include "pair_kokkos.h"
|
||||||
|
#include "pair_soft.h"
|
||||||
|
#include "neigh_list_kokkos.h"
|
||||||
|
|
||||||
|
namespace LAMMPS_NS {
|
||||||
|
|
||||||
|
template<class DeviceType>
|
||||||
|
class PairSoftKokkos : public PairSoft {
|
||||||
|
public:
|
||||||
|
enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF};
|
||||||
|
enum {COUL_FLAG=0};
|
||||||
|
typedef DeviceType device_type;
|
||||||
|
typedef ArrayTypes<DeviceType> AT;
|
||||||
|
PairSoftKokkos(class LAMMPS *);
|
||||||
|
~PairSoftKokkos() override;
|
||||||
|
|
||||||
|
void compute(int, int) override;
|
||||||
|
|
||||||
|
void settings(int, char **) override;
|
||||||
|
void init_style() override;
|
||||||
|
double init_one(int, int) override;
|
||||||
|
|
||||||
|
struct params_soft{
|
||||||
|
KOKKOS_INLINE_FUNCTION
|
||||||
|
params_soft() {cutsq=0,cut=0,prefactor=0;};
|
||||||
|
KOKKOS_INLINE_FUNCTION
|
||||||
|
params_soft(int /*i*/) {cutsq=0,cut=0,prefactor=0;};
|
||||||
|
F_FLOAT cutsq,cut,prefactor;
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
template<bool STACKPARAMS, class Specialisation>
|
||||||
|
KOKKOS_INLINE_FUNCTION
|
||||||
|
F_FLOAT compute_fpair(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const;
|
||||||
|
|
||||||
|
template<bool STACKPARAMS, class Specialisation>
|
||||||
|
KOKKOS_INLINE_FUNCTION
|
||||||
|
F_FLOAT compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const;
|
||||||
|
|
||||||
|
template<bool STACKPARAMS, class Specialisation>
|
||||||
|
KOKKOS_INLINE_FUNCTION
|
||||||
|
F_FLOAT compute_ecoul(const F_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/,
|
||||||
|
const int& /*itype*/, const int& /*jtype*/) const { return 0; }
|
||||||
|
|
||||||
|
Kokkos::DualView<params_soft**,Kokkos::LayoutRight,DeviceType> k_params;
|
||||||
|
typename Kokkos::DualView<params_soft**,Kokkos::LayoutRight,DeviceType>::t_dev_const_um params;
|
||||||
|
params_soft m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; // hardwired to space for 12 atom types
|
||||||
|
F_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1];
|
||||||
|
typename AT::t_x_array_randomread x;
|
||||||
|
typename AT::t_x_array c_x;
|
||||||
|
typename AT::t_f_array f;
|
||||||
|
typename AT::t_int_1d_randomread type;
|
||||||
|
|
||||||
|
DAT::tdual_efloat_1d k_eatom;
|
||||||
|
DAT::tdual_virial_array k_vatom;
|
||||||
|
typename AT::t_efloat_1d d_eatom;
|
||||||
|
typename AT::t_virial_array d_vatom;
|
||||||
|
|
||||||
|
int newton_pair;
|
||||||
|
double special_lj[4];
|
||||||
|
|
||||||
|
typename AT::tdual_ffloat_2d k_cutsq;
|
||||||
|
typename AT::t_ffloat_2d d_cutsq;
|
||||||
|
|
||||||
|
int neighflag;
|
||||||
|
int nlocal,nall,eflag,vflag;
|
||||||
|
|
||||||
|
void allocate() override;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,FULL,true,0>;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,FULL,true,1>;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,HALF,true>;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,HALFTHREAD,true>;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,FULL,false,0>;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,FULL,false,1>;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,HALF,false>;
|
||||||
|
friend struct PairComputeFunctor<PairSoftKokkos,HALFTHREAD,false>;
|
||||||
|
friend EV_FLOAT pair_compute_neighlist<PairSoftKokkos,FULL,0>(PairSoftKokkos*,NeighListKokkos<DeviceType>*);
|
||||||
|
friend EV_FLOAT pair_compute_neighlist<PairSoftKokkos,FULL,1>(PairSoftKokkos*,NeighListKokkos<DeviceType>*);
|
||||||
|
friend EV_FLOAT pair_compute_neighlist<PairSoftKokkos,HALF>(PairSoftKokkos*,NeighListKokkos<DeviceType>*);
|
||||||
|
friend EV_FLOAT pair_compute_neighlist<PairSoftKokkos,HALFTHREAD>(PairSoftKokkos*,NeighListKokkos<DeviceType>*);
|
||||||
|
friend EV_FLOAT pair_compute<PairSoftKokkos>(PairSoftKokkos*,NeighListKokkos<DeviceType>*);
|
||||||
|
friend void pair_virial_fdotr_compute<PairSoftKokkos>(PairSoftKokkos*);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
@ -39,6 +39,8 @@ PairSoft::PairSoft(LAMMPS *lmp) : Pair(lmp)
|
|||||||
|
|
||||||
PairSoft::~PairSoft()
|
PairSoft::~PairSoft()
|
||||||
{
|
{
|
||||||
|
if (copymode) return;
|
||||||
|
|
||||||
if (allocated) {
|
if (allocated) {
|
||||||
memory->destroy(setflag);
|
memory->destroy(setflag);
|
||||||
memory->destroy(cutsq);
|
memory->destroy(cutsq);
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class PairSoft : public Pair {
|
|||||||
double **prefactor;
|
double **prefactor;
|
||||||
double **cut;
|
double **cut;
|
||||||
|
|
||||||
void allocate();
|
virtual void allocate();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LAMMPS_NS
|
} // namespace LAMMPS_NS
|
||||||
|
|||||||
Reference in New Issue
Block a user