From 254b71ab2277fcbb68414192915542113a9d493c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 May 2026 15:07:33 +0000 Subject: [PATCH 1/4] Add Kokkos port of pair_born, pair_beck, pair_gauss, pair_colloid Agent-Logs-Url: https://github.com/stanmoore1/lammps/sessions/18516148-605e-4c0d-9fa6-81963550a688 Co-authored-by: stanmoore1 <18146301+stanmoore1@users.noreply.github.com> --- src/COLLOID/pair_colloid.h | 2 +- src/EXTRA-PAIR/pair_beck.h | 2 +- src/EXTRA-PAIR/pair_gauss.h | 2 +- src/KOKKOS/Install.sh | 8 + src/KOKKOS/pair_beck_kokkos.cpp | 266 +++++++++++++++++++++ src/KOKKOS/pair_beck_kokkos.h | 118 ++++++++++ src/KOKKOS/pair_born_kokkos.cpp | 257 +++++++++++++++++++++ src/KOKKOS/pair_born_kokkos.h | 118 ++++++++++ src/KOKKOS/pair_colloid_kokkos.cpp | 358 +++++++++++++++++++++++++++++ src/KOKKOS/pair_colloid_kokkos.h | 121 ++++++++++ src/KOKKOS/pair_gauss_kokkos.cpp | 241 +++++++++++++++++++ src/KOKKOS/pair_gauss_kokkos.h | 118 ++++++++++ src/pair_born.h | 2 +- 13 files changed, 1609 insertions(+), 4 deletions(-) create mode 100644 src/KOKKOS/pair_beck_kokkos.cpp create mode 100644 src/KOKKOS/pair_beck_kokkos.h create mode 100644 src/KOKKOS/pair_born_kokkos.cpp create mode 100644 src/KOKKOS/pair_born_kokkos.h create mode 100644 src/KOKKOS/pair_colloid_kokkos.cpp create mode 100644 src/KOKKOS/pair_colloid_kokkos.h create mode 100644 src/KOKKOS/pair_gauss_kokkos.cpp create mode 100644 src/KOKKOS/pair_gauss_kokkos.h diff --git a/src/COLLOID/pair_colloid.h b/src/COLLOID/pair_colloid.h index bf8c6cac0d1..d1aef9060b6 100644 --- a/src/COLLOID/pair_colloid.h +++ b/src/COLLOID/pair_colloid.h @@ -50,7 +50,7 @@ class PairColloid : public Pair { double **lj1, **lj2, **lj3, **lj4; int **form; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/EXTRA-PAIR/pair_beck.h b/src/EXTRA-PAIR/pair_beck.h index 46d83978219..130ac0e8238 100644 --- a/src/EXTRA-PAIR/pair_beck.h +++ b/src/EXTRA-PAIR/pair_beck.h @@ -44,7 +44,7 @@ class PairBeck : public Pair { double **AA, **BB; double **aa, **alpha, **beta; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/EXTRA-PAIR/pair_gauss.h b/src/EXTRA-PAIR/pair_gauss.h index 9bb69f14e27..34c2973aa6c 100644 --- a/src/EXTRA-PAIR/pair_gauss.h +++ b/src/EXTRA-PAIR/pair_gauss.h @@ -47,7 +47,7 @@ class PairGauss : public Pair { double **a, **b; double **offset; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index c1888d4307c..3786bdce164 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -312,8 +312,14 @@ action pair_buck_coul_cut_kokkos.cpp action pair_buck_coul_cut_kokkos.h action pair_buck_coul_long_kokkos.cpp pair_buck_coul_long.cpp action pair_buck_coul_long_kokkos.h pair_buck_coul_long.h +action pair_beck_kokkos.cpp pair_beck.cpp +action pair_beck_kokkos.h pair_beck.h +action pair_born_kokkos.cpp +action pair_born_kokkos.h action pair_buck_kokkos.cpp action pair_buck_kokkos.h +action pair_colloid_kokkos.cpp pair_colloid.cpp +action pair_colloid_kokkos.h pair_colloid.h action pair_coul_cut_kokkos.cpp action pair_coul_cut_kokkos.h action pair_coul_debye_kokkos.cpp @@ -342,6 +348,8 @@ action pair_eam_kokkos.cpp pair_eam.cpp action pair_eam_kokkos.h pair_eam.h action pair_exp6_rx_kokkos.cpp pair_exp6_rx.cpp action pair_exp6_rx_kokkos.h pair_exp6_rx.h +action pair_gauss_kokkos.cpp pair_gauss.cpp +action pair_gauss_kokkos.h pair_gauss.h action pair_gran_hooke_history_kokkos.cpp pair_gran_hooke_history.cpp action pair_gran_hooke_history_kokkos.h pair_gran_hooke_history.h action pair_hybrid_kokkos.cpp diff --git a/src/KOKKOS/pair_beck_kokkos.cpp b/src/KOKKOS/pair_beck_kokkos.cpp new file mode 100644 index 00000000000..86feb783284 --- /dev/null +++ b/src/KOKKOS/pair_beck_kokkos.cpp @@ -0,0 +1,266 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_beck_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "force.h" +#include "kokkos.h" +#include "math_special_kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; +using namespace MathSpecialKokkos; + +/* ---------------------------------------------------------------------- */ + +template +PairBeckKokkos::PairBeckKokkos(LAMMPS *lmp) : PairBeck(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairBeckKokkos::~PairBeckKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairBeckKokkos::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(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + 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,void >(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBeckKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT AA = STACKPARAMS ? m_params[itype][jtype].AA : params(itype,jtype).AA; + const KK_FLOAT BB = STACKPARAMS ? m_params[itype][jtype].BB : params(itype,jtype).BB; + const KK_FLOAT aaij = STACKPARAMS ? m_params[itype][jtype].aa : params(itype,jtype).aa; + const KK_FLOAT alpha = STACKPARAMS ? m_params[itype][jtype].alpha : params(itype,jtype).alpha; + const KK_FLOAT beta = STACKPARAMS ? m_params[itype][jtype].beta : params(itype,jtype).beta; + + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT r5 = rsq*rsq*r; + const KK_FLOAT rinv = static_cast(1.0) / r; + const KK_FLOAT term1 = aaij*aaij + rsq; + const KK_FLOAT term2 = powint(term1,-5); + const KK_FLOAT term3 = static_cast(21.672) + static_cast(30.0)*aaij*aaij + + static_cast(6.0)*rsq; + const KK_FLOAT term4 = alpha + r5*beta; + const KK_FLOAT term5 = alpha + static_cast(6.0)*r5*beta; + const KK_FLOAT force_beck = AA*exp(static_cast(-1.0)*r*term4)*term5 + - BB*r*term2*term3; + return force_beck * rinv; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBeckKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT AA = STACKPARAMS ? m_params[itype][jtype].AA : params(itype,jtype).AA; + const KK_FLOAT BB = STACKPARAMS ? m_params[itype][jtype].BB : params(itype,jtype).BB; + const KK_FLOAT aaij = STACKPARAMS ? m_params[itype][jtype].aa : params(itype,jtype).aa; + const KK_FLOAT alpha = STACKPARAMS ? m_params[itype][jtype].alpha : params(itype,jtype).alpha; + const KK_FLOAT beta = STACKPARAMS ? m_params[itype][jtype].beta : params(itype,jtype).beta; + + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT r5 = rsq*rsq*r; + const KK_FLOAT term1 = aaij*aaij + rsq; + const KK_FLOAT term1inv = static_cast(1.0) / term1; + const KK_FLOAT term4 = alpha + r5*beta; + const KK_FLOAT term6 = powint(term1,-3); + return AA*exp(static_cast(-1.0)*r*term4) + - BB*term6*(static_cast(1.0) + + (static_cast(2.709) + static_cast(3.0)*aaij*aaij)*term1inv); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairBeckKokkos::allocate() +{ + PairBeck::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(); + k_params = Kokkos::DualView("PairBeck::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairBeckKokkos::init_style() +{ + PairBeck::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 && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairBeckKokkos::init_one(int i, int j) +{ + double cutone = PairBeck::init_one(i,j); + + k_params.view_host()(i,j).AA = static_cast(AA[i][j]); + k_params.view_host()(i,j).BB = static_cast(BB[i][j]); + k_params.view_host()(i,j).aa = static_cast(aa[i][j]); + k_params.view_host()(i,j).alpha = static_cast(alpha[i][j]); + k_params.view_host()(i,j).beta = static_cast(beta[i][j]); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairBeckKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairBeckKokkos; +#endif +} diff --git a/src/KOKKOS/pair_beck_kokkos.h b/src/KOKKOS/pair_beck_kokkos.h new file mode 100644 index 00000000000..96c9917d53e --- /dev/null +++ b/src/KOKKOS/pair_beck_kokkos.h @@ -0,0 +1,118 @@ +/* -*- 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(beck/kk,PairBeckKokkos); +PairStyle(beck/kk/device,PairBeckKokkos); +PairStyle(beck/kk/host,PairBeckKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_BECK_KOKKOS_H +#define LMP_PAIR_BECK_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_beck.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairBeckKokkos : public PairBeck { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairBeckKokkos(class LAMMPS *); + ~PairBeckKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_beck{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_beck() {cutsq=0;AA=0;BB=0;aa=0;alpha=0;beta=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_beck(int /*i*/) {cutsq=0;AA=0;BB=0;aa=0;alpha=0;beta=0;}; + KK_FLOAT cutsq,AA,BB,aa,alpha,beta; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_beck m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; // hardwired to space for 12 atom types + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + KK_FLOAT special_lj[4]; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + + + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate() override; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairBeckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBeckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBeckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBeckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairBeckKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairBeckKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KOKKOS/pair_born_kokkos.cpp b/src/KOKKOS/pair_born_kokkos.cpp new file mode 100644 index 00000000000..08b8c7be199 --- /dev/null +++ b/src/KOKKOS/pair_born_kokkos.cpp @@ -0,0 +1,257 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_born_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +template +PairBornKokkos::PairBornKokkos(LAMMPS *lmp) : PairBorn(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairBornKokkos::~PairBornKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairBornKokkos::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(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + 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,void >(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBornKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT rhoinv = STACKPARAMS ? m_params[itype][jtype].rhoinv : params(itype,jtype).rhoinv; + const KK_FLOAT sigma = STACKPARAMS ? m_params[itype][jtype].sigma : params(itype,jtype).sigma; + const KK_FLOAT born1 = STACKPARAMS ? m_params[itype][jtype].born1 : params(itype,jtype).born1; + const KK_FLOAT born2 = STACKPARAMS ? m_params[itype][jtype].born2 : params(itype,jtype).born2; + const KK_FLOAT born3 = STACKPARAMS ? m_params[itype][jtype].born3 : params(itype,jtype).born3; + const KK_FLOAT rexp = exp((sigma - r) * rhoinv); + const KK_FLOAT forceborn = born1*r*rexp - born2*r6inv + born3*r2inv*r6inv; + return forceborn*r2inv; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBornKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT rhoinv = STACKPARAMS ? m_params[itype][jtype].rhoinv : params(itype,jtype).rhoinv; + const KK_FLOAT sigma = STACKPARAMS ? m_params[itype][jtype].sigma : params(itype,jtype).sigma; + const KK_FLOAT a = STACKPARAMS ? m_params[itype][jtype].a : params(itype,jtype).a; + const KK_FLOAT born2 = STACKPARAMS ? m_params[itype][jtype].born2 : params(itype,jtype).born2; + const KK_FLOAT born3 = STACKPARAMS ? m_params[itype][jtype].born3 : params(itype,jtype).born3; + const KK_FLOAT offset = STACKPARAMS ? m_params[itype][jtype].offset : params(itype,jtype).offset; + const KK_FLOAT rexp = exp((sigma - r) * rhoinv); + // born2 = 6*c, born3 = 8*d + return a*rexp - (born2/static_cast(6.0))*r6inv + + (born3/static_cast(8.0))*r6inv*r2inv - offset; +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairBornKokkos::allocate() +{ + PairBorn::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(); + k_params = Kokkos::DualView("PairBorn::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairBornKokkos::init_style() +{ + PairBorn::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 && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairBornKokkos::init_one(int i, int j) +{ + double cutone = PairBorn::init_one(i,j); + + k_params.view_host()(i,j).a = static_cast(a[i][j]); + k_params.view_host()(i,j).rhoinv = static_cast(rhoinv[i][j]); + k_params.view_host()(i,j).sigma = static_cast(sigma[i][j]); + k_params.view_host()(i,j).born1 = static_cast(born1[i][j]); + k_params.view_host()(i,j).born2 = static_cast(born2[i][j]); + k_params.view_host()(i,j).born3 = static_cast(born3[i][j]); + k_params.view_host()(i,j).offset = static_cast(offset[i][j]); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairBornKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairBornKokkos; +#endif +} diff --git a/src/KOKKOS/pair_born_kokkos.h b/src/KOKKOS/pair_born_kokkos.h new file mode 100644 index 00000000000..b4a5884ea67 --- /dev/null +++ b/src/KOKKOS/pair_born_kokkos.h @@ -0,0 +1,118 @@ +/* -*- 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(born/kk,PairBornKokkos); +PairStyle(born/kk/device,PairBornKokkos); +PairStyle(born/kk/host,PairBornKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_BORN_KOKKOS_H +#define LMP_PAIR_BORN_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_born.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairBornKokkos : public PairBorn { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairBornKokkos(class LAMMPS *); + ~PairBornKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_born{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_born() {cutsq=0;a=0;rhoinv=0;sigma=0;born1=0;born2=0;born3=0;offset=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_born(int /*i*/) {cutsq=0;a=0;rhoinv=0;sigma=0;born1=0;born2=0;born3=0;offset=0;}; + KK_FLOAT cutsq,a,rhoinv,sigma,born1,born2,born3,offset; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_born m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; // hardwired to space for 12 atom types + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + KK_FLOAT special_lj[4]; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + + + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate() override; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairBornKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBornKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBornKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBornKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairBornKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairBornKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KOKKOS/pair_colloid_kokkos.cpp b/src/KOKKOS/pair_colloid_kokkos.cpp new file mode 100644 index 00000000000..a4e998d8b7f --- /dev/null +++ b/src/KOKKOS/pair_colloid_kokkos.cpp @@ -0,0 +1,358 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_colloid_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "force.h" +#include "kokkos.h" +#include "math_special_kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; +using namespace MathSpecialKokkos; + +/* ---------------------------------------------------------------------- */ + +template +PairColloidKokkos::PairColloidKokkos(LAMMPS *lmp) : PairColloid(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairColloidKokkos::~PairColloidKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairColloidKokkos::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(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + 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,void >(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairColloidKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const int iForm = STACKPARAMS ? m_params[itype][jtype].form : params(itype,jtype).form; + const KK_FLOAT a12 = STACKPARAMS ? m_params[itype][jtype].a12 : params(itype,jtype).a12; + const KK_FLOAT sigma3 = STACKPARAMS ? m_params[itype][jtype].sigma3 : params(itype,jtype).sigma3; + const KK_FLOAT sigma6 = STACKPARAMS ? m_params[itype][jtype].sigma6 : params(itype,jtype).sigma6; + const KK_FLOAT lj1 = STACKPARAMS ? m_params[itype][jtype].lj1 : params(itype,jtype).lj1; + const KK_FLOAT lj2 = STACKPARAMS ? m_params[itype][jtype].lj2 : params(itype,jtype).lj2; + const KK_FLOAT ppA1 = STACKPARAMS ? m_params[itype][jtype].a1 : params(itype,jtype).a1; + const KK_FLOAT ppA2 = STACKPARAMS ? m_params[itype][jtype].a2 : params(itype,jtype).a2; + + if (iForm == SMALL_SMALL) { + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + return r6inv*(lj1*r6inv - lj2)*r2inv; + + } else if (iForm == SMALL_LARGE) { + const KK_FLOAT c2 = ppA2; + const KK_FLOAT K1 = c2*c2; + const KK_FLOAT K2 = rsq; + const KK_FLOAT K0 = K1 - rsq; + const KK_FLOAT K4 = rsq*rsq; + KK_FLOAT K3 = K1 - K2; + K3 *= K3*K3; + const KK_FLOAT K6 = K3*K3; + const KK_FLOAT fR = sigma3*a12*c2*K1/K3; + return static_cast(4.0/15.0)*fR + * (static_cast(2.0)*(K1+K2) + * (K1*(static_cast(5.0)*K1+static_cast(22.0)*K2) + +static_cast(5.0)*K4) + * sigma6/K6 - static_cast(5.0)) / K0; + + } else { // LARGE_LARGE + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT c1 = ppA1; + const KK_FLOAT c2 = ppA2; + const KK_FLOAT K0 = c1*c2; + const KK_FLOAT K1 = c1+c2; + const KK_FLOAT K2 = c1-c2; + const KK_FLOAT K3 = K1+r; + const KK_FLOAT K4 = K1-r; + const KK_FLOAT K5 = K2+r; + const KK_FLOAT K6 = K2-r; + const KK_FLOAT K7 = static_cast(1.0)/(K3*K4); + const KK_FLOAT K8 = static_cast(1.0)/(K5*K6); + const KK_FLOAT g0 = powint(K3,-7); + const KK_FLOAT g1 = powint(K4,-7); + const KK_FLOAT g2 = powint(K5,-7); + const KK_FLOAT g3 = powint(K6,-7); + const KK_FLOAT h0 = ((K3+static_cast(5.0)*K1)*K3+static_cast(30.0)*K0)*g0; + const KK_FLOAT h1 = ((K4+static_cast(5.0)*K1)*K4+static_cast(30.0)*K0)*g1; + const KK_FLOAT h2 = ((K5+static_cast(5.0)*K2)*K5-static_cast(30.0)*K0)*g2; + const KK_FLOAT h3 = ((K6+static_cast(5.0)*K2)*K6-static_cast(30.0)*K0)*g3; + const KK_FLOAT g0m = g0*(static_cast(42.0)*K0/K3+static_cast(6.0)*K1+K3); + const KK_FLOAT g1m = g1*(static_cast(42.0)*K0/K4+static_cast(6.0)*K1+K4); + const KK_FLOAT g2m = g2*(-static_cast(42.0)*K0/K5+static_cast(6.0)*K2+K5); + const KK_FLOAT g3m = g3*(-static_cast(42.0)*K0/K6+static_cast(6.0)*K2+K6); + const KK_FLOAT fR = a12*sigma6/r/static_cast(37800.0); + const KK_FLOAT evdwl_partial = fR*(h0-h1-h2+h3); + const KK_FLOAT dUR = evdwl_partial/r + static_cast(5.0)*fR*(g0m+g1m-g2m-g3m); + const KK_FLOAT dUA = -a12/static_cast(3.0)*r + *((static_cast(2.0)*K0*K7+static_cast(1.0))*K7 + +(static_cast(2.0)*K0*K8-static_cast(1.0))*K8); + return (dUR+dUA)/r; + } +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairColloidKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const int iForm = STACKPARAMS ? m_params[itype][jtype].form : params(itype,jtype).form; + const KK_FLOAT a12 = STACKPARAMS ? m_params[itype][jtype].a12 : params(itype,jtype).a12; + const KK_FLOAT sigma3 = STACKPARAMS ? m_params[itype][jtype].sigma3 : params(itype,jtype).sigma3; + const KK_FLOAT sigma6 = STACKPARAMS ? m_params[itype][jtype].sigma6 : params(itype,jtype).sigma6; + const KK_FLOAT lj3 = STACKPARAMS ? m_params[itype][jtype].lj3 : params(itype,jtype).lj3; + const KK_FLOAT lj4 = STACKPARAMS ? m_params[itype][jtype].lj4 : params(itype,jtype).lj4; + const KK_FLOAT ppA1 = STACKPARAMS ? m_params[itype][jtype].a1 : params(itype,jtype).a1; + const KK_FLOAT ppA2 = STACKPARAMS ? m_params[itype][jtype].a2 : params(itype,jtype).a2; + const KK_FLOAT offset = STACKPARAMS ? m_params[itype][jtype].offset : params(itype,jtype).offset; + + if (iForm == SMALL_SMALL) { + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + return r6inv*(r6inv*lj3 - lj4) - offset; + + } else if (iForm == SMALL_LARGE) { + const KK_FLOAT c2 = ppA2; + const KK_FLOAT K1 = c2*c2; + const KK_FLOAT K2 = rsq; + const KK_FLOAT K4 = rsq*rsq; + KK_FLOAT K3 = K1 - K2; + K3 *= K3*K3; + const KK_FLOAT K6 = K3*K3; + const KK_FLOAT fR = sigma3*a12*c2*K1/K3; + return static_cast(2.0/9.0)*fR + * (static_cast(1.0) + - (K1*(K1*(K1/static_cast(3.0)+static_cast(3.0)*K2) + +static_cast(4.2)*K4)+K2*K4) + * sigma6/K6) - offset; + + } else { // LARGE_LARGE + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT c1 = ppA1; + const KK_FLOAT c2 = ppA2; + const KK_FLOAT K0 = c1*c2; + const KK_FLOAT K1 = c1+c2; + const KK_FLOAT K2 = c1-c2; + const KK_FLOAT K3 = K1+r; + const KK_FLOAT K4 = K1-r; + const KK_FLOAT K5 = K2+r; + const KK_FLOAT K6 = K2-r; + const KK_FLOAT K7 = static_cast(1.0)/(K3*K4); + const KK_FLOAT K8 = static_cast(1.0)/(K5*K6); + const KK_FLOAT g0 = powint(K3,-7); + const KK_FLOAT g1 = powint(K4,-7); + const KK_FLOAT g2 = powint(K5,-7); + const KK_FLOAT g3 = powint(K6,-7); + const KK_FLOAT h0 = ((K3+static_cast(5.0)*K1)*K3+static_cast(30.0)*K0)*g0; + const KK_FLOAT h1 = ((K4+static_cast(5.0)*K1)*K4+static_cast(30.0)*K0)*g1; + const KK_FLOAT h2 = ((K5+static_cast(5.0)*K2)*K5-static_cast(30.0)*K0)*g2; + const KK_FLOAT h3 = ((K6+static_cast(5.0)*K2)*K6-static_cast(30.0)*K0)*g3; + const KK_FLOAT fR = a12*sigma6/r/static_cast(37800.0); + return fR*(h0-h1-h2+h3) + + a12/static_cast(6.0) + *(static_cast(2.0)*K0*(K7+K8)-log(K8/K7)) - offset; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairColloidKokkos::allocate() +{ + PairColloid::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(); + k_params = Kokkos::DualView("PairColloid::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairColloidKokkos::init_style() +{ + PairColloid::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 && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairColloidKokkos::init_one(int i, int j) +{ + double cutone = PairColloid::init_one(i,j); + + k_params.view_host()(i,j).form = form[i][j]; + k_params.view_host()(i,j).a12 = static_cast(a12[i][j]); + k_params.view_host()(i,j).sigma3 = static_cast(sigma3[i][j]); + k_params.view_host()(i,j).sigma6 = static_cast(sigma6[i][j]); + k_params.view_host()(i,j).lj1 = static_cast(lj1[i][j]); + k_params.view_host()(i,j).lj2 = static_cast(lj2[i][j]); + k_params.view_host()(i,j).lj3 = static_cast(lj3[i][j]); + k_params.view_host()(i,j).lj4 = static_cast(lj4[i][j]); + k_params.view_host()(i,j).a1 = static_cast(a1[i][j]); + k_params.view_host()(i,j).a2 = static_cast(a2[i][j]); + k_params.view_host()(i,j).offset = static_cast(offset[i][j]); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairColloidKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairColloidKokkos; +#endif +} diff --git a/src/KOKKOS/pair_colloid_kokkos.h b/src/KOKKOS/pair_colloid_kokkos.h new file mode 100644 index 00000000000..7b4bdd76988 --- /dev/null +++ b/src/KOKKOS/pair_colloid_kokkos.h @@ -0,0 +1,121 @@ +/* -*- 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(colloid/kk,PairColloidKokkos); +PairStyle(colloid/kk/device,PairColloidKokkos); +PairStyle(colloid/kk/host,PairColloidKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_COLLOID_KOKKOS_H +#define LMP_PAIR_COLLOID_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_colloid.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairColloidKokkos : public PairColloid { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairColloidKokkos(class LAMMPS *); + ~PairColloidKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_colloid{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_colloid() {cutsq=0;form=0;a12=0;sigma3=0;sigma6=0; + lj1=0;lj2=0;lj3=0;lj4=0;a1=0;a2=0;offset=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_colloid(int /*i*/) {cutsq=0;form=0;a12=0;sigma3=0;sigma6=0; + lj1=0;lj2=0;lj3=0;lj4=0;a1=0;a2=0;offset=0;}; + KK_FLOAT cutsq,a12,sigma3,sigma6,lj1,lj2,lj3,lj4,a1,a2,offset; + int form; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_colloid m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; // hardwired to space for 12 atom types + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + KK_FLOAT special_lj[4]; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + + + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate() override; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairColloidKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairColloidKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairColloidKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairColloidKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairColloidKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairColloidKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KOKKOS/pair_gauss_kokkos.cpp b/src/KOKKOS/pair_gauss_kokkos.cpp new file mode 100644 index 00000000000..81fa0747999 --- /dev/null +++ b/src/KOKKOS/pair_gauss_kokkos.cpp @@ -0,0 +1,241 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_gauss_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +template +PairGaussKokkos::PairGaussKokkos(LAMMPS *lmp) : PairGauss(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + + // pvector counting (nextra) is not supported in the Kokkos version + nextra = 0; + delete[] pvector; + pvector = nullptr; +} + +/* ---------------------------------------------------------------------- */ + +template +PairGaussKokkos::~PairGaussKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairGaussKokkos::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(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + 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,void >(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairGaussKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT a = STACKPARAMS ? m_params[itype][jtype].a : params(itype,jtype).a; + const KK_FLOAT b = STACKPARAMS ? m_params[itype][jtype].b : params(itype,jtype).b; + return static_cast(-2.0) * a * b * exp(-b * rsq); +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairGaussKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT a = STACKPARAMS ? m_params[itype][jtype].a : params(itype,jtype).a; + const KK_FLOAT b = STACKPARAMS ? m_params[itype][jtype].b : params(itype,jtype).b; + const KK_FLOAT offset = STACKPARAMS ? m_params[itype][jtype].offset : params(itype,jtype).offset; + return -(a * exp(-b * rsq) - offset); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairGaussKokkos::allocate() +{ + PairGauss::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(); + k_params = Kokkos::DualView("PairGauss::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairGaussKokkos::init_style() +{ + PairGauss::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 && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairGaussKokkos::init_one(int i, int j) +{ + double cutone = PairGauss::init_one(i,j); + + k_params.view_host()(i,j).a = static_cast(a[i][j]); + k_params.view_host()(i,j).b = static_cast(b[i][j]); + k_params.view_host()(i,j).offset = static_cast(offset[i][j]); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairGaussKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairGaussKokkos; +#endif +} diff --git a/src/KOKKOS/pair_gauss_kokkos.h b/src/KOKKOS/pair_gauss_kokkos.h new file mode 100644 index 00000000000..854b7d743a6 --- /dev/null +++ b/src/KOKKOS/pair_gauss_kokkos.h @@ -0,0 +1,118 @@ +/* -*- 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(gauss/kk,PairGaussKokkos); +PairStyle(gauss/kk/device,PairGaussKokkos); +PairStyle(gauss/kk/host,PairGaussKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_GAUSS_KOKKOS_H +#define LMP_PAIR_GAUSS_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_gauss.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairGaussKokkos : public PairGauss { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairGaussKokkos(class LAMMPS *); + ~PairGaussKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_gauss{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_gauss() {cutsq=0;a=0;b=0;offset=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_gauss(int /*i*/) {cutsq=0;a=0;b=0;offset=0;}; + KK_FLOAT cutsq,a,b,offset; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_gauss m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; // hardwired to space for 12 atom types + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + KK_FLOAT special_lj[4]; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + + + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate() override; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairGaussKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairGaussKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairGaussKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairGaussKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairGaussKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairGaussKokkos*); +}; + +} + +#endif +#endif diff --git a/src/pair_born.h b/src/pair_born.h index eaae688c387..7ce38d3a3f4 100644 --- a/src/pair_born.h +++ b/src/pair_born.h @@ -49,7 +49,7 @@ class PairBorn : public Pair { double **a, **rho, **sigma, **c, **d; double **rhoinv, **born1, **born2, **born3, **offset; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS From 1259122f88cab3a6674199536be50ff7283c169e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 May 2026 16:11:54 +0000 Subject: [PATCH 2/4] Add copymode fix, docs, and Purge.list entries for new Kokkos pair styles Agent-Logs-Url: https://github.com/stanmoore1/lammps/sessions/238771c0-bf6a-4235-8608-8269132c2834 Co-authored-by: stanmoore1 <18146301+stanmoore1@users.noreply.github.com> --- doc/src/Commands_pair.rst | 8 ++++---- doc/src/pair_beck.rst | 3 ++- doc/src/pair_born.rst | 5 +++-- doc/src/pair_colloid.rst | 3 ++- doc/src/pair_gauss.rst | 3 ++- src/COLLOID/pair_colloid.cpp | 2 ++ src/EXTRA-PAIR/pair_beck.cpp | 2 ++ src/EXTRA-PAIR/pair_gauss.cpp | 2 ++ src/Purge.list | 8 ++++++++ src/pair_born.cpp | 2 ++ 10 files changed, 29 insertions(+), 9 deletions(-) diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index 90f2110dfd8..6eea1b66efd 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -28,12 +28,12 @@ OPT. * :doc:`airebo/morse (io) ` * :doc:`amoeba (g) ` * :doc:`atm ` - * :doc:`beck (go) ` + * :doc:`beck (gko) ` * :doc:`body/nparticle ` * :doc:`body/rounded/polygon ` * :doc:`body/rounded/polyhedron ` * :doc:`bop ` - * :doc:`born (go) ` + * :doc:`born (gko) ` * :doc:`born/coul/dsf ` * :doc:`born/coul/dsf/cs ` * :doc:`born/coul/long (go) ` @@ -54,7 +54,7 @@ OPT. * :doc:`buck/mdf ` * :doc:`buck6d/coul/gauss/dsf ` * :doc:`buck6d/coul/gauss/long ` - * :doc:`colloid (go) ` + * :doc:`colloid (gko) ` * :doc:`comb (o) ` * :doc:`comb3 ` * :doc:`cosine/squared ` @@ -105,7 +105,7 @@ OPT. * :doc:`eim (o) ` * :doc:`exp6/rx (k) ` * :doc:`extep ` - * :doc:`gauss (go) ` + * :doc:`gauss (gko) ` * :doc:`gauss/cut (o) ` * :doc:`gayberne (gio) ` * :doc:`gran/hertz/history (o) ` diff --git a/doc/src/pair_beck.rst b/doc/src/pair_beck.rst index 6bb4afdc80a..8886f5f32c9 100644 --- a/doc/src/pair_beck.rst +++ b/doc/src/pair_beck.rst @@ -1,11 +1,12 @@ .. index:: pair_style beck .. index:: pair_style beck/gpu +.. index:: pair_style beck/kk .. index:: pair_style beck/omp pair_style beck command ======================= -Accelerator Variants: *beck/gpu*, *beck/omp* +Accelerator Variants: *beck/gpu*, *beck/kk*, *beck/omp* Syntax """""" diff --git a/doc/src/pair_born.rst b/doc/src/pair_born.rst index 555e78eecd3..427840ab622 100644 --- a/doc/src/pair_born.rst +++ b/doc/src/pair_born.rst @@ -1,6 +1,7 @@ .. index:: pair_style born -.. index:: pair_style born/omp .. index:: pair_style born/gpu +.. index:: pair_style born/kk +.. index:: pair_style born/omp .. index:: pair_style born/coul/long .. index:: pair_style born/coul/long/gpu .. index:: pair_style born/coul/long/omp @@ -14,7 +15,7 @@ pair_style born command ======================= -Accelerator Variants: *born/omp*, *born/gpu* +Accelerator Variants: *born/gpu*, *born/kk*, *born/omp* pair_style born/coul/long command ================================= diff --git a/doc/src/pair_colloid.rst b/doc/src/pair_colloid.rst index 26e7fa7da46..ebef467035f 100644 --- a/doc/src/pair_colloid.rst +++ b/doc/src/pair_colloid.rst @@ -1,11 +1,12 @@ .. index:: pair_style colloid .. index:: pair_style colloid/gpu +.. index:: pair_style colloid/kk .. index:: pair_style colloid/omp pair_style colloid command ========================== -Accelerator Variants: *colloid/gpu*, *colloid/omp* +Accelerator Variants: *colloid/gpu*, *colloid/kk*, *colloid/omp* Syntax """""" diff --git a/doc/src/pair_gauss.rst b/doc/src/pair_gauss.rst index dbbe39d4cf0..0a53d225344 100644 --- a/doc/src/pair_gauss.rst +++ b/doc/src/pair_gauss.rst @@ -1,5 +1,6 @@ .. index:: pair_style gauss .. index:: pair_style gauss/gpu +.. index:: pair_style gauss/kk .. index:: pair_style gauss/omp .. index:: pair_style gauss/cut .. index:: pair_style gauss/cut/omp @@ -7,7 +8,7 @@ pair_style gauss command ======================== -Accelerator Variants: *gauss/gpu*, *gauss/omp* +Accelerator Variants: *gauss/gpu*, *gauss/kk*, *gauss/omp* pair_style gauss/cut command ============================ diff --git a/src/COLLOID/pair_colloid.cpp b/src/COLLOID/pair_colloid.cpp index ce4228fa3f0..2afc919a4c0 100644 --- a/src/COLLOID/pair_colloid.cpp +++ b/src/COLLOID/pair_colloid.cpp @@ -42,6 +42,8 @@ PairColloid::PairColloid(LAMMPS *lmp) : Pair(lmp) PairColloid::~PairColloid() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/EXTRA-PAIR/pair_beck.cpp b/src/EXTRA-PAIR/pair_beck.cpp index 7cfa4810f09..4046bb21f15 100644 --- a/src/EXTRA-PAIR/pair_beck.cpp +++ b/src/EXTRA-PAIR/pair_beck.cpp @@ -39,6 +39,8 @@ PairBeck::PairBeck(LAMMPS *lmp) : Pair(lmp) {} PairBeck::~PairBeck() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/EXTRA-PAIR/pair_gauss.cpp b/src/EXTRA-PAIR/pair_gauss.cpp index d21e1018f99..d8f4d4d94e4 100644 --- a/src/EXTRA-PAIR/pair_gauss.cpp +++ b/src/EXTRA-PAIR/pair_gauss.cpp @@ -42,6 +42,8 @@ PairGauss::PairGauss(LAMMPS *lmp) : Pair(lmp) PairGauss::~PairGauss() { + if (copymode) return; + delete[] pvector; if (allocated) { diff --git a/src/Purge.list b/src/Purge.list index b4ce98673e4..ff79d18ed19 100644 --- a/src/Purge.list +++ b/src/Purge.list @@ -1174,10 +1174,13 @@ npair_ssa_kokkos.h npair_trim_kokkos.h pack_kokkos.h pair_adp_kokkos.h +pair_beck_kokkos.h +pair_born_kokkos.h pair_brownian_kokkos.h pair_buck_coul_cut_kokkos.h pair_buck_coul_long_kokkos.h pair_buck_kokkos.h +pair_colloid_kokkos.h pair_coul_cut_kokkos.h pair_coul_debye_kokkos.h pair_coul_dsf_kokkos.h @@ -1192,6 +1195,7 @@ pair_eam_alloy_kokkos.h pair_eam_fs_kokkos.h pair_eam_kokkos.h pair_exp6_rx_kokkos.h +pair_gauss_kokkos.h pair_gran_hooke_history_kokkos.h pair_hybrid_kokkos.h pair_hybrid_overlay_kokkos.h @@ -1373,10 +1377,13 @@ npair_skip_kokkos.cpp npair_ssa_kokkos.cpp npair_trim_kokkos.cpp pair_adp_kokkos.cpp +pair_beck_kokkos.cpp +pair_born_kokkos.cpp pair_brownian_kokkos.cpp pair_buck_coul_cut_kokkos.cpp pair_buck_coul_long_kokkos.cpp pair_buck_kokkos.cpp +pair_colloid_kokkos.cpp pair_coul_cut_kokkos.cpp pair_coul_debye_kokkos.cpp pair_coul_dsf_kokkos.cpp @@ -1391,6 +1398,7 @@ pair_eam_alloy_kokkos.cpp pair_eam_fs_kokkos.cpp pair_eam_kokkos.cpp pair_exp6_rx_kokkos.cpp +pair_gauss_kokkos.cpp pair_gran_hooke_history_kokkos.cpp pair_hybrid_kokkos.cpp pair_hybrid_overlay_kokkos.cpp diff --git a/src/pair_born.cpp b/src/pair_born.cpp index a881bc18db3..5d54e6535af 100644 --- a/src/pair_born.cpp +++ b/src/pair_born.cpp @@ -45,6 +45,8 @@ PairBorn::PairBorn(LAMMPS *lmp) : Pair(lmp) PairBorn::~PairBorn() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); From ec0c1caae55b6b6e12ebb0ff85500f917cb3fa45 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 6 May 2026 01:04:27 +0000 Subject: [PATCH 3/4] Port pair_lj_smooth, pair_lj_smooth_linear, pair_ufm, pair_coul_slater_long, pair_born_coul_long to Kokkos Agent-Logs-Url: https://github.com/stanmoore1/lammps/sessions/7be1a528-e647-4b8e-9e03-6c45f0fd5d91 Co-authored-by: stanmoore1 <18146301+stanmoore1@users.noreply.github.com> --- doc/src/Commands_pair.rst | 10 +- doc/src/pair_born.rst | 3 +- doc/src/pair_coul_slater.rst | 3 +- doc/src/pair_lj_smooth.rst | 3 +- doc/src/pair_lj_smooth_linear.rst | 3 +- doc/src/pair_ufm.rst | 3 +- src/EXTRA-PAIR/pair_lj_smooth.cpp | 2 + src/EXTRA-PAIR/pair_lj_smooth.h | 2 +- src/EXTRA-PAIR/pair_lj_smooth_linear.cpp | 2 + src/EXTRA-PAIR/pair_lj_smooth_linear.h | 2 +- src/EXTRA-PAIR/pair_ufm.cpp | 2 + src/KOKKOS/Install.sh | 10 + src/KOKKOS/pair_born_coul_long_kokkos.cpp | 446 ++++++++++++++++++++ src/KOKKOS/pair_born_coul_long_kokkos.h | 162 +++++++ src/KOKKOS/pair_coul_slater_long_kokkos.cpp | 281 ++++++++++++ src/KOKKOS/pair_coul_slater_long_kokkos.h | 138 ++++++ src/KOKKOS/pair_lj_smooth_kokkos.cpp | 273 ++++++++++++ src/KOKKOS/pair_lj_smooth_kokkos.h | 123 ++++++ src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp | 242 +++++++++++ src/KOKKOS/pair_lj_smooth_linear_kokkos.h | 117 +++++ src/KOKKOS/pair_ufm_kokkos.cpp | 233 ++++++++++ src/KOKKOS/pair_ufm_kokkos.h | 117 +++++ src/KSPACE/pair_born_coul_long.cpp | 2 + src/KSPACE/pair_born_coul_long.h | 2 +- src/Purge.list | 10 + 25 files changed, 2178 insertions(+), 13 deletions(-) create mode 100644 src/KOKKOS/pair_born_coul_long_kokkos.cpp create mode 100644 src/KOKKOS/pair_born_coul_long_kokkos.h create mode 100644 src/KOKKOS/pair_coul_slater_long_kokkos.cpp create mode 100644 src/KOKKOS/pair_coul_slater_long_kokkos.h create mode 100644 src/KOKKOS/pair_lj_smooth_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_smooth_kokkos.h create mode 100644 src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp create mode 100644 src/KOKKOS/pair_lj_smooth_linear_kokkos.h create mode 100644 src/KOKKOS/pair_ufm_kokkos.cpp create mode 100644 src/KOKKOS/pair_ufm_kokkos.h diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index 6eea1b66efd..4ff5ca936d6 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -36,7 +36,7 @@ OPT. * :doc:`born (gko) ` * :doc:`born/coul/dsf ` * :doc:`born/coul/dsf/cs ` - * :doc:`born/coul/long (go) ` + * :doc:`born/coul/long (gko) ` * :doc:`born/coul/long/cs (g) ` * :doc:`born/coul/msm (o) ` * :doc:`born/coul/wolf (go) ` @@ -73,7 +73,7 @@ OPT. * :doc:`coul/long/soft (o) ` * :doc:`coul/msm (o) ` * :doc:`coul/slater/cut ` - * :doc:`coul/slater/long (g) ` + * :doc:`coul/slater/long (gk) ` * :doc:`coul/shield ` * :doc:`coul/streitz ` * :doc:`coul/tt ` @@ -190,8 +190,8 @@ OPT. * :doc:`lj/spica/coul/long (gko) ` * :doc:`lj/spica/coul/msm (o) ` * :doc:`lj/sf/dipole/sf (go) ` - * :doc:`lj/smooth (go) ` - * :doc:`lj/smooth/linear (o) ` + * :doc:`lj/smooth (gko) ` + * :doc:`lj/smooth/linear (ko) ` * :doc:`lj/switch3/coulgauss/long ` * :doc:`lj96/cut (gko) ` * :doc:`local/density ` @@ -306,7 +306,7 @@ OPT. * :doc:`tip4p/long (o) ` * :doc:`tip4p/long/soft (o) ` * :doc:`tri/lj ` - * :doc:`ufm (got) ` + * :doc:`ufm (gkot) ` * :doc:`uf3 (k) ` * :doc:`vashishta (gko) ` * :doc:`vashishta/table (o) ` diff --git a/doc/src/pair_born.rst b/doc/src/pair_born.rst index 427840ab622..c0871b5242e 100644 --- a/doc/src/pair_born.rst +++ b/doc/src/pair_born.rst @@ -4,6 +4,7 @@ .. index:: pair_style born/omp .. index:: pair_style born/coul/long .. index:: pair_style born/coul/long/gpu +.. index:: pair_style born/coul/long/kk .. index:: pair_style born/coul/long/omp .. index:: pair_style born/coul/msm .. index:: pair_style born/coul/msm/omp @@ -20,7 +21,7 @@ Accelerator Variants: *born/gpu*, *born/kk*, *born/omp* pair_style born/coul/long command ================================= -Accelerator Variants: *born/coul/long/gpu*, *born/coul/long/omp* +Accelerator Variants: *born/coul/long/gpu*, *born/coul/long/kk*, *born/coul/long/omp* pair_style born/coul/msm command ================================ diff --git a/doc/src/pair_coul_slater.rst b/doc/src/pair_coul_slater.rst index 7af1ec42c64..06021b6665a 100644 --- a/doc/src/pair_coul_slater.rst +++ b/doc/src/pair_coul_slater.rst @@ -2,6 +2,7 @@ .. index:: pair_style coul/slater/cut .. index:: pair_style coul/slater/long .. index:: pair_style coul/slater/long/gpu +.. index:: pair_style coul/slater/long/kk pair_style coul/slater command ============================== @@ -12,7 +13,7 @@ pair_style coul/slater/cut command pair_style coul/slater/long command =================================== -Accelerator Variants: *coul/slater/long/gpu* +Accelerator Variants: *coul/slater/long/gpu*, *coul/slater/long/kk* Syntax """""" diff --git a/doc/src/pair_lj_smooth.rst b/doc/src/pair_lj_smooth.rst index d6b266d9326..41e4368f4b8 100644 --- a/doc/src/pair_lj_smooth.rst +++ b/doc/src/pair_lj_smooth.rst @@ -1,11 +1,12 @@ .. index:: pair_style lj/smooth .. index:: pair_style lj/smooth/gpu +.. index:: pair_style lj/smooth/kk .. index:: pair_style lj/smooth/omp pair_style lj/smooth command ============================ -Accelerator Variants: *lj/smooth/gpu*, *lj/smooth/omp* +Accelerator Variants: *lj/smooth/gpu*, *lj/smooth/kk*, *lj/smooth/omp* Syntax """""" diff --git a/doc/src/pair_lj_smooth_linear.rst b/doc/src/pair_lj_smooth_linear.rst index 20b5e6cbda3..5cdcbb14405 100644 --- a/doc/src/pair_lj_smooth_linear.rst +++ b/doc/src/pair_lj_smooth_linear.rst @@ -1,10 +1,11 @@ .. index:: pair_style lj/smooth/linear +.. index:: pair_style lj/smooth/linear/kk .. index:: pair_style lj/smooth/linear/omp pair_style lj/smooth/linear command =================================== -Accelerator Variants: *lj/smooth/linear/omp* +Accelerator Variants: *lj/smooth/linear/kk*, *lj/smooth/linear/omp* Syntax """""" diff --git a/doc/src/pair_ufm.rst b/doc/src/pair_ufm.rst index 5de0b91ee76..080824c3b88 100644 --- a/doc/src/pair_ufm.rst +++ b/doc/src/pair_ufm.rst @@ -1,12 +1,13 @@ .. index:: pair_style ufm .. index:: pair_style ufm/gpu +.. index:: pair_style ufm/kk .. index:: pair_style ufm/omp .. index:: pair_style ufm/opt pair_style ufm command ====================== -Accelerator Variants: *ufm/gpu*, *ufm/omp*, *ufm/opt* +Accelerator Variants: *ufm/gpu*, *ufm/kk*, *ufm/omp*, *ufm/opt* Syntax """""" diff --git a/src/EXTRA-PAIR/pair_lj_smooth.cpp b/src/EXTRA-PAIR/pair_lj_smooth.cpp index 309ca02b308..ac489035faa 100644 --- a/src/EXTRA-PAIR/pair_lj_smooth.cpp +++ b/src/EXTRA-PAIR/pair_lj_smooth.cpp @@ -40,6 +40,8 @@ PairLJSmooth::PairLJSmooth(LAMMPS *lmp) : Pair(lmp) PairLJSmooth::~PairLJSmooth() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/EXTRA-PAIR/pair_lj_smooth.h b/src/EXTRA-PAIR/pair_lj_smooth.h index fde28a41796..5728e6f5bdd 100644 --- a/src/EXTRA-PAIR/pair_lj_smooth.h +++ b/src/EXTRA-PAIR/pair_lj_smooth.h @@ -48,7 +48,7 @@ class PairLJSmooth : public Pair { double **ljsw0, **ljsw1, **ljsw2, **ljsw3, **ljsw4; double **offset; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp b/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp index cde36291a28..61b1df80977 100644 --- a/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp +++ b/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp @@ -38,6 +38,8 @@ PairLJSmoothLinear::PairLJSmoothLinear(LAMMPS *lmp) : Pair(lmp) { PairLJSmoothLinear::~PairLJSmoothLinear() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/EXTRA-PAIR/pair_lj_smooth_linear.h b/src/EXTRA-PAIR/pair_lj_smooth_linear.h index b1e039e7b61..c42aae3c237 100644 --- a/src/EXTRA-PAIR/pair_lj_smooth_linear.h +++ b/src/EXTRA-PAIR/pair_lj_smooth_linear.h @@ -48,7 +48,7 @@ class PairLJSmoothLinear : public Pair { double **ljcut, **dljcut; double **lj1, **lj2, **lj3, **lj4; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/EXTRA-PAIR/pair_ufm.cpp b/src/EXTRA-PAIR/pair_ufm.cpp index 157e597227e..3b4a12fb413 100644 --- a/src/EXTRA-PAIR/pair_ufm.cpp +++ b/src/EXTRA-PAIR/pair_ufm.cpp @@ -42,6 +42,8 @@ PairUFM::PairUFM(LAMMPS *lmp) : Pair(lmp) PairUFM::~PairUFM() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 3786bdce164..0a9dc5c69d1 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -314,6 +314,8 @@ action pair_buck_coul_long_kokkos.cpp pair_buck_coul_long.cpp action pair_buck_coul_long_kokkos.h pair_buck_coul_long.h action pair_beck_kokkos.cpp pair_beck.cpp action pair_beck_kokkos.h pair_beck.h +action pair_born_coul_long_kokkos.cpp pair_born_coul_long.cpp +action pair_born_coul_long_kokkos.h pair_born_coul_long.h action pair_born_kokkos.cpp action pair_born_kokkos.h action pair_buck_kokkos.cpp @@ -328,6 +330,8 @@ action pair_coul_dsf_kokkos.cpp action pair_coul_dsf_kokkos.h action pair_coul_long_kokkos.cpp pair_coul_long.cpp action pair_coul_long_kokkos.h pair_coul_long.h +action pair_coul_slater_long_kokkos.cpp pair_coul_slater_long.cpp +action pair_coul_slater_long_kokkos.h pair_coul_slater_long.h action pair_coul_wolf_kokkos.cpp action pair_coul_wolf_kokkos.h action pair_dpd_ext_kokkos.cpp pair_dpd_ext.cpp @@ -393,6 +397,10 @@ action pair_lj_gromacs_coul_gromacs_kokkos.cpp pair_lj_gromacs_coul_gromacs.cpp action pair_lj_gromacs_coul_gromacs_kokkos.h pair_lj_gromacs_coul_gromacs.h action pair_lj_gromacs_kokkos.cpp pair_lj_gromacs.cpp action pair_lj_gromacs_kokkos.h pair_lj_gromacs.h +action pair_lj_smooth_kokkos.cpp pair_lj_smooth.cpp +action pair_lj_smooth_kokkos.h pair_lj_smooth.h +action pair_lj_smooth_linear_kokkos.cpp pair_lj_smooth_linear.cpp +action pair_lj_smooth_linear_kokkos.h pair_lj_smooth_linear.h action pair_lj_spica_coul_long_kokkos.cpp pair_lj_spica_coul_long.cpp action pair_lj_spica_coul_long_kokkos.h pair_lj_spica_coul_long.h action pair_lj_spica_kokkos.cpp pair_lj_spica.cpp @@ -428,6 +436,8 @@ action pair_table_rx_kokkos.cpp pair_table_rx.cpp action pair_table_rx_kokkos.h pair_table_rx.h action pair_tersoff_kokkos.cpp pair_tersoff.cpp action pair_tersoff_kokkos.h pair_tersoff.h +action pair_ufm_kokkos.cpp pair_ufm.cpp +action pair_ufm_kokkos.h pair_ufm.h action pair_tersoff_mod_kokkos.cpp pair_tersoff_mod.cpp action pair_tersoff_mod_kokkos.h pair_tersoff_mod.h action pair_tersoff_zbl_kokkos.cpp pair_tersoff_zbl.cpp diff --git a/src/KOKKOS/pair_born_coul_long_kokkos.cpp b/src/KOKKOS/pair_born_coul_long_kokkos.cpp new file mode 100644 index 00000000000..94d979e32e6 --- /dev/null +++ b/src/KOKKOS/pair_born_coul_long_kokkos.cpp @@ -0,0 +1,446 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_born_coul_long_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "ewald_const.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace EwaldConst; + +/* ---------------------------------------------------------------------- */ + +template +PairBornCoulLongKokkos::PairBornCoulLongKokkos(LAMMPS *lmp) : PairBornCoulLong(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairBornCoulLongKokkos::~PairBornCoulLongKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + memoryKK->destroy_kokkos(k_cut_ljsq,cut_ljsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairBornCoulLongKokkos::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); + + if (eflag_atom) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); + d_eatom = k_eatom.view(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_cut_ljsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + special_lj[0] = static_cast(force->special_lj[0]); + special_lj[1] = static_cast(force->special_lj[1]); + special_lj[2] = static_cast(force->special_lj[2]); + special_lj[3] = static_cast(force->special_lj[3]); + special_coul[0] = static_cast(force->special_coul[0]); + special_coul[1] = static_cast(force->special_coul[1]); + special_coul[2] = static_cast(force->special_coul[2]); + special_coul[3] = static_cast(force->special_coul[3]); + qqrd2e = static_cast(force->qqrd2e); + newton_pair = force->newton_pair; + + g_ewald_kk = static_cast(g_ewald); + + copymode = 1; + EV_FLOAT ev; + if (ncoultablebits) + ev = pair_compute,CoulLongTable<1>> + (this,(NeighListKokkos*)list); + else + ev = pair_compute,CoulLongTable<0>> + (this,(NeighListKokkos*)list); + + if (eflag) { + eng_vdwl += static_cast(ev.evdwl); + eng_coul += static_cast(ev.ecoul); + } + + if (vflag_global) { + virial[0] += static_cast(ev.v[0]); + virial[1] += static_cast(ev.v[1]); + virial[2] += static_cast(ev.v[2]); + virial[3] += static_cast(ev.v[3]); + virial[4] += static_cast(ev.v[4]); + virial[5] += static_cast(ev.v[5]); + } + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute Born pair force between atoms i and j +------------------------------------------------------------------------- */ +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBornCoulLongKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int & /*i*/, const int & /*j*/, + const int &itype, const int &jtype) const { + const KK_FLOAT cut_ljsq = STACKPARAMS ? m_params[itype][jtype].cut_ljsq : params(itype,jtype).cut_ljsq; + if (rsq >= cut_ljsq) return static_cast(0.0); + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT rhoinv = STACKPARAMS ? m_params[itype][jtype].rhoinv : params(itype,jtype).rhoinv; + const KK_FLOAT sigma = STACKPARAMS ? m_params[itype][jtype].sigma : params(itype,jtype).sigma; + const KK_FLOAT born1 = STACKPARAMS ? m_params[itype][jtype].born1 : params(itype,jtype).born1; + const KK_FLOAT born2 = STACKPARAMS ? m_params[itype][jtype].born2 : params(itype,jtype).born2; + const KK_FLOAT born3 = STACKPARAMS ? m_params[itype][jtype].born3 : params(itype,jtype).born3; + const KK_FLOAT rexp = exp((sigma - r) * rhoinv); + const KK_FLOAT forceborn = born1*r*rexp - born2*r6inv + born3*r2inv*r6inv; + return forceborn*r2inv; +} + +/* ---------------------------------------------------------------------- + compute Coulomb pair force between atoms i and j +------------------------------------------------------------------------- */ +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBornCoulLongKokkos:: +compute_fcoul(const KK_FLOAT &rsq, const int & /*i*/, const int &j, + const int & /*itype*/, const int & /*jtype*/, + const KK_FLOAT &factor_coul, const KK_FLOAT &qtmp) const { + if (Specialisation::DoTable && rsq > tabinnersq_kk) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const KK_FLOAT fraction = ((KK_FLOAT)rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const KK_FLOAT table = d_ftable[itable] + fraction*d_dftable[itable]; + KK_FLOAT forcecoul = qtmp*q[j] * table; + if (factor_coul < static_cast(1.0)) { + const KK_FLOAT table2 = d_ctable[itable] + fraction*d_dctable[itable]; + const KK_FLOAT prefactor = qtmp*q[j] * table2; + forcecoul -= (static_cast(1.0)-factor_coul)*prefactor; + } + return forcecoul/rsq; + } else { + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT grij = g_ewald_kk * r; + const KK_FLOAT expm2 = exp(-grij*grij); + const KK_FLOAT t = static_cast(1.0) / (static_cast(1.0) + static_cast(EWALD_P)*grij); + const KK_FLOAT erfc = t * (static_cast(A1)+t*(static_cast(A2)+t*(static_cast(A3)+t*(static_cast(A4)+t*static_cast(A5))))) * expm2; + const KK_FLOAT prefactor = qqrd2e * qtmp*q[j]/r; + KK_FLOAT forcecoul = prefactor * (erfc + static_cast(EWALD_F)*grij*expm2); + if (factor_coul < static_cast(1.0)) forcecoul -= (static_cast(1.0)-factor_coul)*prefactor; + return forcecoul/rsq; + } +} + +/* ---------------------------------------------------------------------- + compute Born pair energy between atoms i and j +------------------------------------------------------------------------- */ +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBornCoulLongKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int & /*i*/, const int & /*j*/, + const int &itype, const int &jtype) const { + const KK_FLOAT cut_ljsq = STACKPARAMS ? m_params[itype][jtype].cut_ljsq : params(itype,jtype).cut_ljsq; + if (rsq >= cut_ljsq) return static_cast(0.0); + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT rhoinv = STACKPARAMS ? m_params[itype][jtype].rhoinv : params(itype,jtype).rhoinv; + const KK_FLOAT sigma = STACKPARAMS ? m_params[itype][jtype].sigma : params(itype,jtype).sigma; + const KK_FLOAT a = STACKPARAMS ? m_params[itype][jtype].a : params(itype,jtype).a; + const KK_FLOAT born2 = STACKPARAMS ? m_params[itype][jtype].born2 : params(itype,jtype).born2; + const KK_FLOAT born3 = STACKPARAMS ? m_params[itype][jtype].born3 : params(itype,jtype).born3; + const KK_FLOAT offset = STACKPARAMS ? m_params[itype][jtype].offset : params(itype,jtype).offset; + const KK_FLOAT rexp = exp((sigma - r) * rhoinv); + // born2 = 6*c, born3 = 8*d + return a*rexp - (born2/static_cast(6.0))*r6inv + + (born3/static_cast(8.0))*r6inv*r2inv - offset; +} + +/* ---------------------------------------------------------------------- + compute Coulomb pair energy between atoms i and j +------------------------------------------------------------------------- */ +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairBornCoulLongKokkos:: +compute_ecoul(const KK_FLOAT &rsq, const int & /*i*/, const int &j, + const int & /*itype*/, const int & /*jtype*/, + const KK_FLOAT &factor_coul, const KK_FLOAT &qtmp) const { + if (Specialisation::DoTable && rsq > tabinnersq_kk) { + union_int_float_t rsq_lookup; + rsq_lookup.f = rsq; + const int itable = (rsq_lookup.i & ncoulmask) >> ncoulshiftbits; + const KK_FLOAT fraction = ((KK_FLOAT)rsq_lookup.f - d_rtable[itable]) * d_drtable[itable]; + const KK_FLOAT table = d_etable[itable] + fraction*d_detable[itable]; + KK_FLOAT ecoul = qtmp*q[j] * table; + if (factor_coul < static_cast(1.0)) { + const KK_FLOAT table2 = d_ctable[itable] + fraction*d_dctable[itable]; + const KK_FLOAT prefactor = qtmp*q[j] * table2; + ecoul -= (static_cast(1.0)-factor_coul)*prefactor; + } + return ecoul; + } else { + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT grij = g_ewald_kk * r; + const KK_FLOAT expm2 = exp(-grij*grij); + const KK_FLOAT t = static_cast(1.0) / (static_cast(1.0) + static_cast(EWALD_P)*grij); + const KK_FLOAT erfc = t * (static_cast(A1)+t*(static_cast(A2)+t*(static_cast(A3)+t*(static_cast(A4)+t*static_cast(A5))))) * expm2; + const KK_FLOAT prefactor = qqrd2e * qtmp*q[j]/r; + KK_FLOAT ecoul = prefactor*erfc; + if (factor_coul < static_cast(1.0)) ecoul -= (static_cast(1.0)-factor_coul)*prefactor; + return ecoul; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairBornCoulLongKokkos::allocate() +{ + PairBornCoulLong::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(); + + memory->destroy(cut_ljsq); + memoryKK->create_kokkos(k_cut_ljsq,cut_ljsq,n+1,n+1,"pair:cut_ljsq"); + d_cut_ljsq = k_cut_ljsq.template view(); + + d_cut_coulsq = typename AT::t_kkfloat_2d("pair:cut_coulsq",n+1,n+1); + + k_params = Kokkos::DualView("PairBornCoulLong::params",n+1,n+1); + params = k_params.template view(); +} + +template +void PairBornCoulLongKokkos::init_tables(double cut_coul, double *cut_respa) +{ + Pair::init_tables(cut_coul,cut_respa); + + typedef typename AT::t_kkfloat_1d table_type; + typedef HAT::t_kkfloat_1d host_table_type; + + int ntable = 1; + for (int i = 0; i < ncoultablebits; i++) ntable *= 2; + + tabinnersq_kk = static_cast(tabinnersq); + + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(rtable[i]); + Kokkos::deep_copy(d_table,h_table); + d_rtable = d_table; + } + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(drtable[i]); + Kokkos::deep_copy(d_table,h_table); + d_drtable = d_table; + } + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(ftable[i]); + Kokkos::deep_copy(d_table,h_table); + d_ftable = d_table; + } + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(dftable[i]); + Kokkos::deep_copy(d_table,h_table); + d_dftable = d_table; + } + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(ctable[i]); + Kokkos::deep_copy(d_table,h_table); + d_ctable = d_table; + } + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(dctable[i]); + Kokkos::deep_copy(d_table,h_table); + d_dctable = d_table; + } + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(etable[i]); + Kokkos::deep_copy(d_table,h_table); + d_etable = d_table; + } + { + host_table_type h_table("HostTable",ntable); + table_type d_table("DeviceTable",ntable); + for (int i = 0; i < ntable; i++) h_table(i) = static_cast(detable[i]); + Kokkos::deep_copy(d_table,h_table); + d_detable = d_table; + } +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairBornCoulLongKokkos::init_style() +{ + PairBornCoulLong::init_style(); + + Kokkos::deep_copy(d_cut_coulsq,static_cast(cut_coulsq)); + + 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"); + } + + neighflag = lmp->kokkos->neighflag; + auto request = neighbor->find_request(this); + request->set_kokkos_host(std::is_same_v && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairBornCoulLongKokkos::init_one(int i, int j) +{ + double cutone = PairBornCoulLong::init_one(i,j); + double cut_ljsqm = cut_ljsq[i][j]; + + k_params.view_host()(i,j).a = static_cast(a[i][j]); + k_params.view_host()(i,j).rhoinv = static_cast(rhoinv[i][j]); + k_params.view_host()(i,j).sigma = static_cast(sigma[i][j]); + k_params.view_host()(i,j).born1 = static_cast(born1[i][j]); + k_params.view_host()(i,j).born2 = static_cast(born2[i][j]); + k_params.view_host()(i,j).born3 = static_cast(born3[i][j]); + k_params.view_host()(i,j).offset = static_cast(offset[i][j]); + k_params.view_host()(i,j).cut_ljsq = static_cast(cut_ljsqm); + k_params.view_host()(i,j).cut_coulsq = static_cast(cut_coulsq); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + m_cut_ljsq[j][i] = m_cut_ljsq[i][j] = static_cast(cut_ljsqm); + m_cut_coulsq[j][i] = m_cut_coulsq[i][j] = static_cast(cut_coulsq); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_cut_ljsq.view_host()(i,j) = k_cut_ljsq.view_host()(j,i) = cut_ljsqm; + k_cut_ljsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairBornCoulLongKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairBornCoulLongKokkos; +#endif +} diff --git a/src/KOKKOS/pair_born_coul_long_kokkos.h b/src/KOKKOS/pair_born_coul_long_kokkos.h new file mode 100644 index 00000000000..c4584b2f666 --- /dev/null +++ b/src/KOKKOS/pair_born_coul_long_kokkos.h @@ -0,0 +1,162 @@ +/* -*- 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(born/coul/long/kk,PairBornCoulLongKokkos); +PairStyle(born/coul/long/kk/device,PairBornCoulLongKokkos); +PairStyle(born/coul/long/kk/host,PairBornCoulLongKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_BORN_COUL_LONG_KOKKOS_H +#define LMP_PAIR_BORN_COUL_LONG_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_born_coul_long.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairBornCoulLongKokkos : public PairBornCoulLong { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairBornCoulLongKokkos(class LAMMPS *); + ~PairBornCoulLongKokkos() override; + + void compute(int, int) override; + + void init_tables(double cut_coul, double *cut_respa) override; + void init_style() override; + double init_one(int, int) override; + + struct params_born_coul_long{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_born_coul_long() {cutsq=0;cut_ljsq=0;cut_coulsq=0; + a=0;rhoinv=0;sigma=0;born1=0;born2=0;born3=0;offset=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_born_coul_long(int /*i*/) {cutsq=0;cut_ljsq=0;cut_coulsq=0; + a=0;rhoinv=0;sigma=0;born1=0;born2=0;born3=0;offset=0;}; + KK_FLOAT cutsq,cut_ljsq,cut_coulsq; + KK_FLOAT a,rhoinv,sigma,born1,born2,born3,offset; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fcoul(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const KK_FLOAT& factor_coul, const KK_FLOAT& qtmp) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, + const KK_FLOAT& factor_coul, const KK_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_born_coul_long m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + KK_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + KK_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + typename AT::t_kkfloat_1d_randomread q; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + DAT::ttransform_kkfloat_2d k_cut_ljsq; + typename AT::t_kkfloat_2d d_cut_ljsq; + typename AT::t_kkfloat_2d d_cut_coulsq; + + typename AT::t_kkfloat_1d_randomread + d_rtable, d_drtable, d_ftable, d_dftable, + d_ctable, d_dctable, d_etable, d_detable; + + int neighflag; + int nlocal,nall,eflag,vflag; + + KK_FLOAT special_coul[4]; + KK_FLOAT special_lj[4]; + KK_FLOAT qqrd2e; + KK_FLOAT g_ewald_kk; + KK_FLOAT tabinnersq_kk; + + void allocate() override; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairBornCoulLongKokkos*, + NeighListKokkos*); + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBornCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairBornCoulLongKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairBornCoulLongKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KOKKOS/pair_coul_slater_long_kokkos.cpp b/src/KOKKOS/pair_coul_slater_long_kokkos.cpp new file mode 100644 index 00000000000..54b1bb0c4ce --- /dev/null +++ b/src/KOKKOS/pair_coul_slater_long_kokkos.cpp @@ -0,0 +1,281 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_coul_slater_long_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "ewald_const.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; +using namespace EwaldConst; + +/* ---------------------------------------------------------------------- */ + +template +PairCoulSlaterLongKokkos::PairCoulSlaterLongKokkos(LAMMPS *lmp) : PairCoulSlaterLong(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairCoulSlaterLongKokkos::~PairCoulSlaterLongKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairCoulSlaterLongKokkos::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); + + if (eflag_atom) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); + d_eatom = k_eatom.view(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + q = atomKK->k_q.view(); + type = atomKK->k_type.view(); + nlocal = atom->nlocal; + nall = atom->nlocal + atom->nghost; + qqrd2e = static_cast(force->qqrd2e); + newton_pair = force->newton_pair; + special_lj[0] = static_cast(force->special_lj[0]); + special_lj[1] = static_cast(force->special_lj[1]); + special_lj[2] = static_cast(force->special_lj[2]); + special_lj[3] = static_cast(force->special_lj[3]); + special_coul[0] = static_cast(force->special_coul[0]); + special_coul[1] = static_cast(force->special_coul[1]); + special_coul[2] = static_cast(force->special_coul[2]); + special_coul[3] = static_cast(force->special_coul[3]); + + g_ewald_kk = static_cast(g_ewald); + lamda_kk = static_cast(lamda); + + copymode = 1; + // coul/slater/long does not use force tables + EV_FLOAT ev = pair_compute,CoulLongTable<0>> + (this,(NeighListKokkos*)list); + + if (eflag) { + eng_vdwl += static_cast(ev.evdwl); + eng_coul += static_cast(ev.ecoul); + } + + if (vflag_global) { + virial[0] += static_cast(ev.v[0]); + virial[1] += static_cast(ev.v[1]); + virial[2] += static_cast(ev.v[2]); + virial[3] += static_cast(ev.v[3]); + virial[4] += static_cast(ev.v[4]); + virial[5] += static_cast(ev.v[5]); + } + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + if (vflag_fdotr) pair_virial_fdotr_compute(this); + + copymode = 0; +} + +/* ---------------------------------------------------------------------- + compute Coulomb force with Slater correction between atoms i and j +------------------------------------------------------------------------- */ +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairCoulSlaterLongKokkos:: +compute_fcoul(const KK_FLOAT &rsq, const int & /*i*/, const int &j, + const int &itype, const int &jtype, + const KK_FLOAT &factor_coul, const KK_FLOAT &qtmp) const { + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT grij = g_ewald_kk * r; + const KK_FLOAT expm2 = exp(-grij*grij); + const KK_FLOAT t = static_cast(1.0) / (static_cast(1.0) + static_cast(EWALD_P)*grij); + const KK_FLOAT erfc = t * (static_cast(A1)+t*(static_cast(A2)+t*(static_cast(A3)+t*(static_cast(A4)+t*static_cast(A5))))) * expm2; + const KK_FLOAT slater_term = exp(-static_cast(2.0)*r/lamda_kk) + * (static_cast(1.0) + (static_cast(2.0)*r/lamda_kk*(static_cast(1.0)+r/lamda_kk))); + const KK_FLOAT scale = STACKPARAMS ? m_params[itype][jtype].scale : params(itype,jtype).scale; + const KK_FLOAT prefactor = qqrd2e * scale * qtmp * q[j] / r; + KK_FLOAT forcecoul = prefactor * (erfc + static_cast(EWALD_F)*grij*expm2 - slater_term); + if (factor_coul < static_cast(1.0)) + forcecoul -= (static_cast(1.0) - factor_coul) * prefactor * (static_cast(1.0) - slater_term); + return forcecoul * r2inv; +} + +/* ---------------------------------------------------------------------- + compute Coulomb energy with Slater correction between atoms i and j +------------------------------------------------------------------------- */ +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairCoulSlaterLongKokkos:: +compute_ecoul(const KK_FLOAT &rsq, const int & /*i*/, const int &j, + const int &itype, const int &jtype, + const KK_FLOAT &factor_coul, const KK_FLOAT &qtmp) const { + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT grij = g_ewald_kk * r; + const KK_FLOAT expm2 = exp(-grij*grij); + const KK_FLOAT t = static_cast(1.0) / (static_cast(1.0) + static_cast(EWALD_P)*grij); + const KK_FLOAT erfc = t * (static_cast(A1)+t*(static_cast(A2)+t*(static_cast(A3)+t*(static_cast(A4)+t*static_cast(A5))))) * expm2; + const KK_FLOAT scale = STACKPARAMS ? m_params[itype][jtype].scale : params(itype,jtype).scale; + const KK_FLOAT prefactor = qqrd2e * scale * qtmp * q[j] / r; + KK_FLOAT ecoul = prefactor * (erfc - (static_cast(1.0) + r/lamda_kk) * exp(-static_cast(2.0)*r/lamda_kk)); + if (factor_coul < static_cast(1.0)) + ecoul -= (static_cast(1.0) - factor_coul) * prefactor + * (static_cast(1.0) - (static_cast(1.0) + r/lamda_kk) * exp(-static_cast(2.0)*r/lamda_kk)); + return ecoul; +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairCoulSlaterLongKokkos::allocate() +{ + PairCoulSlaterLong::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(); + + d_cut_ljsq = typename AT::t_kkfloat_2d("pair:cut_ljsq",n+1,n+1); + d_cut_coulsq = typename AT::t_kkfloat_2d("pair:cut_coulsq",n+1,n+1); + + k_params = Kokkos::DualView("PairCoulSlaterLong::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairCoulSlaterLongKokkos::init_style() +{ + PairCoulSlaterLong::init_style(); + + Kokkos::deep_copy(d_cut_coulsq,static_cast(cut_coulsq)); + Kokkos::deep_copy(d_cut_ljsq,static_cast(cut_coulsq)); + + 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"); + } + + neighflag = lmp->kokkos->neighflag; + auto request = neighbor->find_request(this); + request->set_kokkos_host(std::is_same_v && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairCoulSlaterLongKokkos::init_one(int i, int j) +{ + double cutone = PairCoulSlaterLong::init_one(i,j); + + k_params.view_host()(i,j).cut_coulsq = static_cast(cut_coulsq); + k_params.view_host()(i,j).scale = static_cast(scale[i][j]); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + m_cut_coulsq[j][i] = m_cut_coulsq[i][j] = static_cast(cut_coulsq); + m_cut_ljsq[j][i] = m_cut_ljsq[i][j] = static_cast(cut_coulsq); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairCoulSlaterLongKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairCoulSlaterLongKokkos; +#endif +} diff --git a/src/KOKKOS/pair_coul_slater_long_kokkos.h b/src/KOKKOS/pair_coul_slater_long_kokkos.h new file mode 100644 index 00000000000..e9a7932d5bb --- /dev/null +++ b/src/KOKKOS/pair_coul_slater_long_kokkos.h @@ -0,0 +1,138 @@ +/* -*- 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(coul/slater/long/kk,PairCoulSlaterLongKokkos); +PairStyle(coul/slater/long/kk/device,PairCoulSlaterLongKokkos); +PairStyle(coul/slater/long/kk/host,PairCoulSlaterLongKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_COUL_SLATER_LONG_KOKKOS_H +#define LMP_PAIR_COUL_SLATER_LONG_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_coul_slater_long.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairCoulSlaterLongKokkos : public PairCoulSlaterLong { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=1}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairCoulSlaterLongKokkos(class LAMMPS *); + ~PairCoulSlaterLongKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_coul_slater{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_coul_slater() {cut_coulsq=0;scale=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_coul_slater(int /*i*/) {cut_coulsq=0;scale=0;}; + KK_FLOAT cut_coulsq,scale; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0.0; } + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fcoul(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, + const int& jtype, const KK_FLOAT& factor_coul, const KK_FLOAT& qtmp) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& rsq, const int& i, const int&j, + const int& itype, const int& jtype, + const KK_FLOAT& factor_coul, const KK_FLOAT& qtmp) const; + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_coul_slater m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + KK_FLOAT m_cut_ljsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + KK_FLOAT m_cut_coulsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + typename AT::t_kkfloat_1d_randomread q; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + typename AT::t_kkfloat_2d d_cut_ljsq; + typename AT::t_kkfloat_2d d_cut_coulsq; + + int neighflag; + int nlocal,nall,eflag,vflag; + + KK_FLOAT special_coul[4]; + KK_FLOAT special_lj[4]; + KK_FLOAT qqrd2e; + KK_FLOAT g_ewald_kk; + KK_FLOAT lamda_kk; + + void allocate() override; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairCoulSlaterLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulSlaterLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulSlaterLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulSlaterLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairCoulSlaterLongKokkos*, + NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairCoulSlaterLongKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KOKKOS/pair_lj_smooth_kokkos.cpp b/src/KOKKOS/pair_lj_smooth_kokkos.cpp new file mode 100644 index 00000000000..363a0f62775 --- /dev/null +++ b/src/KOKKOS/pair_lj_smooth_kokkos.cpp @@ -0,0 +1,273 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_lj_smooth_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +template +PairLJSmoothKokkos::PairLJSmoothKokkos(LAMMPS *lmp) : PairLJSmooth(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJSmoothKokkos::~PairLJSmoothKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJSmoothKokkos::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); + + if (eflag_atom) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); + d_eatom = k_eatom.view(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + 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]; + + copymode = 1; + EV_FLOAT ev = pair_compute,void>(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairLJSmoothKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT cut_inner_sq = STACKPARAMS ? m_params[itype][jtype].cut_inner_sq : params(itype,jtype).cut_inner_sq; + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + KK_FLOAT forcelj; + if (rsq < cut_inner_sq) { + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT lj1 = STACKPARAMS ? m_params[itype][jtype].lj1 : params(itype,jtype).lj1; + const KK_FLOAT lj2 = STACKPARAMS ? m_params[itype][jtype].lj2 : params(itype,jtype).lj2; + forcelj = r6inv * (lj1*r6inv - lj2); + } else { + const KK_FLOAT cut_inner = STACKPARAMS ? m_params[itype][jtype].cut_inner : params(itype,jtype).cut_inner; + const KK_FLOAT ljsw1 = STACKPARAMS ? m_params[itype][jtype].ljsw1 : params(itype,jtype).ljsw1; + const KK_FLOAT ljsw2 = STACKPARAMS ? m_params[itype][jtype].ljsw2 : params(itype,jtype).ljsw2; + const KK_FLOAT ljsw3 = STACKPARAMS ? m_params[itype][jtype].ljsw3 : params(itype,jtype).ljsw3; + const KK_FLOAT ljsw4 = STACKPARAMS ? m_params[itype][jtype].ljsw4 : params(itype,jtype).ljsw4; + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT t = r - cut_inner; + const KK_FLOAT tsq = t*t; + const KK_FLOAT fskin = ljsw1 + ljsw2*t + ljsw3*tsq + ljsw4*tsq*t; + forcelj = fskin*r; + } + return forcelj*r2inv; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairLJSmoothKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT cut_inner_sq = STACKPARAMS ? m_params[itype][jtype].cut_inner_sq : params(itype,jtype).cut_inner_sq; + const KK_FLOAT offset = STACKPARAMS ? m_params[itype][jtype].offset : params(itype,jtype).offset; + if (rsq < cut_inner_sq) { + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT lj3 = STACKPARAMS ? m_params[itype][jtype].lj3 : params(itype,jtype).lj3; + const KK_FLOAT lj4 = STACKPARAMS ? m_params[itype][jtype].lj4 : params(itype,jtype).lj4; + return r6inv * (lj3*r6inv - lj4) - offset; + } else { + const KK_FLOAT cut_inner = STACKPARAMS ? m_params[itype][jtype].cut_inner : params(itype,jtype).cut_inner; + const KK_FLOAT ljsw0 = STACKPARAMS ? m_params[itype][jtype].ljsw0 : params(itype,jtype).ljsw0; + const KK_FLOAT ljsw1 = STACKPARAMS ? m_params[itype][jtype].ljsw1 : params(itype,jtype).ljsw1; + const KK_FLOAT ljsw2 = STACKPARAMS ? m_params[itype][jtype].ljsw2 : params(itype,jtype).ljsw2; + const KK_FLOAT ljsw3 = STACKPARAMS ? m_params[itype][jtype].ljsw3 : params(itype,jtype).ljsw3; + const KK_FLOAT ljsw4 = STACKPARAMS ? m_params[itype][jtype].ljsw4 : params(itype,jtype).ljsw4; + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT t = r - cut_inner; + const KK_FLOAT tsq = t*t; + return ljsw0 - ljsw1*t - ljsw2*tsq/static_cast(2.0) + - ljsw3*tsq*t/static_cast(3.0) + - ljsw4*tsq*tsq/static_cast(4.0) - offset; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJSmoothKokkos::allocate() +{ + PairLJSmooth::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(); + k_params = Kokkos::DualView("PairLJSmooth::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJSmoothKokkos::init_style() +{ + PairLJSmooth::init_style(); + + 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"); + } + + neighflag = lmp->kokkos->neighflag; + auto request = neighbor->find_request(this); + request->set_kokkos_host(std::is_same_v && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJSmoothKokkos::init_one(int i, int j) +{ + double cutone = PairLJSmooth::init_one(i,j); + + k_params.view_host()(i,j).cut_inner_sq = static_cast(cut_inner_sq[i][j]); + k_params.view_host()(i,j).lj1 = static_cast(lj1[i][j]); + k_params.view_host()(i,j).lj2 = static_cast(lj2[i][j]); + k_params.view_host()(i,j).lj3 = static_cast(lj3[i][j]); + k_params.view_host()(i,j).lj4 = static_cast(lj4[i][j]); + k_params.view_host()(i,j).ljsw0 = static_cast(ljsw0[i][j]); + k_params.view_host()(i,j).ljsw1 = static_cast(ljsw1[i][j]); + k_params.view_host()(i,j).ljsw2 = static_cast(ljsw2[i][j]); + k_params.view_host()(i,j).ljsw3 = static_cast(ljsw3[i][j]); + k_params.view_host()(i,j).ljsw4 = static_cast(ljsw4[i][j]); + k_params.view_host()(i,j).cut_inner = static_cast(cut_inner[i][j]); + k_params.view_host()(i,j).offset = static_cast(offset[i][j]); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairLJSmoothKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairLJSmoothKokkos; +#endif +} diff --git a/src/KOKKOS/pair_lj_smooth_kokkos.h b/src/KOKKOS/pair_lj_smooth_kokkos.h new file mode 100644 index 00000000000..b8d04cb2b09 --- /dev/null +++ b/src/KOKKOS/pair_lj_smooth_kokkos.h @@ -0,0 +1,123 @@ +/* -*- 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(lj/smooth/kk,PairLJSmoothKokkos); +PairStyle(lj/smooth/kk/device,PairLJSmoothKokkos); +PairStyle(lj/smooth/kk/host,PairLJSmoothKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_LJ_SMOOTH_KOKKOS_H +#define LMP_PAIR_LJ_SMOOTH_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_smooth.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJSmoothKokkos : public PairLJSmooth { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairLJSmoothKokkos(class LAMMPS *); + ~PairLJSmoothKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_lj_smooth{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_lj_smooth() {cutsq=0;cut_inner_sq=0;lj1=0;lj2=0;lj3=0;lj4=0; + ljsw0=0;ljsw1=0;ljsw2=0;ljsw3=0;ljsw4=0; + cut_inner=0;offset=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_lj_smooth(int /*i*/) {cutsq=0;cut_inner_sq=0;lj1=0;lj2=0;lj3=0;lj4=0; + ljsw0=0;ljsw1=0;ljsw2=0;ljsw3=0;ljsw4=0; + cut_inner=0;offset=0;}; + KK_FLOAT cutsq,cut_inner_sq,lj1,lj2,lj3,lj4; + KK_FLOAT ljsw0,ljsw1,ljsw2,ljsw3,ljsw4; + KK_FLOAT cut_inner,offset; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_lj_smooth m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + KK_FLOAT special_lj[4]; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate() override; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJSmoothKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJSmoothKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp b/src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp new file mode 100644 index 00000000000..f390de4b2f7 --- /dev/null +++ b/src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp @@ -0,0 +1,242 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_lj_smooth_linear_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +template +PairLJSmoothLinearKokkos::PairLJSmoothLinearKokkos(LAMMPS *lmp) : PairLJSmoothLinear(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairLJSmoothLinearKokkos::~PairLJSmoothLinearKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairLJSmoothLinearKokkos::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); + + if (eflag_atom) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); + d_eatom = k_eatom.view(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + 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]; + + copymode = 1; + EV_FLOAT ev = pair_compute,void>(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairLJSmoothLinearKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT rinv = sqrt(r2inv); + const KK_FLOAT lj1 = STACKPARAMS ? m_params[itype][jtype].lj1 : params(itype,jtype).lj1; + const KK_FLOAT lj2 = STACKPARAMS ? m_params[itype][jtype].lj2 : params(itype,jtype).lj2; + const KK_FLOAT dljcut = STACKPARAMS ? m_params[itype][jtype].dljcut : params(itype,jtype).dljcut; + const KK_FLOAT forcelj = rinv*r6inv*(lj1*r6inv - lj2) - dljcut; + return forcelj*rinv; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairLJSmoothLinearKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT r2inv = static_cast(1.0) / rsq; + const KK_FLOAT r6inv = r2inv*r2inv*r2inv; + const KK_FLOAT r = sqrt(rsq); + const KK_FLOAT lj3 = STACKPARAMS ? m_params[itype][jtype].lj3 : params(itype,jtype).lj3; + const KK_FLOAT lj4 = STACKPARAMS ? m_params[itype][jtype].lj4 : params(itype,jtype).lj4; + const KK_FLOAT ljcut = STACKPARAMS ? m_params[itype][jtype].ljcut : params(itype,jtype).ljcut; + const KK_FLOAT dljcut = STACKPARAMS ? m_params[itype][jtype].dljcut : params(itype,jtype).dljcut; + const KK_FLOAT cut = STACKPARAMS ? m_params[itype][jtype].cut : params(itype,jtype).cut; + return r6inv*(lj3*r6inv - lj4) - ljcut + (r - cut)*dljcut; +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairLJSmoothLinearKokkos::allocate() +{ + PairLJSmoothLinear::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(); + k_params = Kokkos::DualView("PairLJSmoothLinear::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairLJSmoothLinearKokkos::init_style() +{ + PairLJSmoothLinear::init_style(); + + 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"); + } + + neighflag = lmp->kokkos->neighflag; + auto request = neighbor->find_request(this); + request->set_kokkos_host(std::is_same_v && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairLJSmoothLinearKokkos::init_one(int i, int j) +{ + double cutone = PairLJSmoothLinear::init_one(i,j); + + k_params.view_host()(i,j).lj1 = static_cast(lj1[i][j]); + k_params.view_host()(i,j).lj2 = static_cast(lj2[i][j]); + k_params.view_host()(i,j).lj3 = static_cast(lj3[i][j]); + k_params.view_host()(i,j).lj4 = static_cast(lj4[i][j]); + k_params.view_host()(i,j).ljcut = static_cast(ljcut[i][j]); + k_params.view_host()(i,j).dljcut = static_cast(dljcut[i][j]); + k_params.view_host()(i,j).cut = static_cast(cut[i][j]); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairLJSmoothLinearKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairLJSmoothLinearKokkos; +#endif +} diff --git a/src/KOKKOS/pair_lj_smooth_linear_kokkos.h b/src/KOKKOS/pair_lj_smooth_linear_kokkos.h new file mode 100644 index 00000000000..bb872b29067 --- /dev/null +++ b/src/KOKKOS/pair_lj_smooth_linear_kokkos.h @@ -0,0 +1,117 @@ +/* -*- 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(lj/smooth/linear/kk,PairLJSmoothLinearKokkos); +PairStyle(lj/smooth/linear/kk/device,PairLJSmoothLinearKokkos); +PairStyle(lj/smooth/linear/kk/host,PairLJSmoothLinearKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_LJ_SMOOTH_LINEAR_KOKKOS_H +#define LMP_PAIR_LJ_SMOOTH_LINEAR_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_lj_smooth_linear.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairLJSmoothLinearKokkos : public PairLJSmoothLinear { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairLJSmoothLinearKokkos(class LAMMPS *); + ~PairLJSmoothLinearKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_lj_smooth_linear{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_lj_smooth_linear() {cutsq=0;lj1=0;lj2=0;lj3=0;lj4=0;ljcut=0;dljcut=0;cut=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_lj_smooth_linear(int /*i*/) {cutsq=0;lj1=0;lj2=0;lj3=0;lj4=0;ljcut=0;dljcut=0;cut=0;}; + KK_FLOAT cutsq,lj1,lj2,lj3,lj4,ljcut,dljcut,cut; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_lj_smooth_linear m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + KK_FLOAT special_lj[4]; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate() override; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJSmoothLinearKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairLJSmoothLinearKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KOKKOS/pair_ufm_kokkos.cpp b/src/KOKKOS/pair_ufm_kokkos.cpp new file mode 100644 index 00000000000..3f76147b6eb --- /dev/null +++ b/src/KOKKOS/pair_ufm_kokkos.cpp @@ -0,0 +1,233 @@ +// 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "pair_ufm_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "error.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +template +PairUFMKokkos::PairUFMKokkos(LAMMPS *lmp) : PairUFM(lmp) +{ + respa_enable = 0; + + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +PairUFMKokkos::~PairUFMKokkos() +{ + if (copymode) return; + + if (allocated) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->destroy_kokkos(k_cutsq,cutsq); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void PairUFMKokkos::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); + + if (eflag_atom) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); + d_eatom = k_eatom.view(); + } + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); + d_vatom = k_vatom.view(); + } + + atomKK->sync(execution_space,datamask_read); + k_cutsq.template sync(); + k_params.template sync(); + if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); + else atomKK->modified(execution_space,F_MASK); + + x = atomKK->k_x.view(); + c_x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + type = atomKK->k_type.view(); + 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]; + + copymode = 1; + EV_FLOAT ev = pair_compute,void>(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairUFMKokkos:: +compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT uf1 = STACKPARAMS ? m_params[itype][jtype].uf1 : params(itype,jtype).uf1; + const KK_FLOAT uf2 = STACKPARAMS ? m_params[itype][jtype].uf2 : params(itype,jtype).uf2; + const KK_FLOAT scale = STACKPARAMS ? m_params[itype][jtype].scale : params(itype,jtype).scale; + const KK_FLOAT expuf = exp(-rsq * uf2); + return scale * uf1 * expuf / (static_cast(1.0) - expuf); +} + +template +template +// NOLINTNEXTLINE +KOKKOS_INLINE_FUNCTION +KK_FLOAT PairUFMKokkos:: +compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { + const KK_FLOAT uf2 = STACKPARAMS ? m_params[itype][jtype].uf2 : params(itype,jtype).uf2; + const KK_FLOAT uf3 = STACKPARAMS ? m_params[itype][jtype].uf3 : params(itype,jtype).uf3; + const KK_FLOAT offset = STACKPARAMS ? m_params[itype][jtype].offset : params(itype,jtype).offset; + const KK_FLOAT expuf = exp(-rsq * uf2); + return -uf3 * log(static_cast(1.0) - expuf) - offset; +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +template +void PairUFMKokkos::allocate() +{ + PairUFM::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(); + k_params = Kokkos::DualView("PairUFM::params",n+1,n+1); + params = k_params.template view(); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +template +void PairUFMKokkos::init_style() +{ + PairUFM::init_style(); + + 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"); + } + + neighflag = lmp->kokkos->neighflag; + auto request = neighbor->find_request(this); + request->set_kokkos_host(std::is_same_v && + !std::is_same_v); + request->set_kokkos_device(std::is_same_v); + if (neighflag == FULL) request->enable_full(); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +template +double PairUFMKokkos::init_one(int i, int j) +{ + double cutone = PairUFM::init_one(i,j); + + k_params.view_host()(i,j).uf1 = static_cast(uf1[i][j]); + k_params.view_host()(i,j).uf2 = static_cast(uf2[i][j]); + k_params.view_host()(i,j).uf3 = static_cast(uf3[i][j]); + k_params.view_host()(i,j).scale = static_cast(scale[i][j]); + k_params.view_host()(i,j).offset = static_cast(offset[i][j]); + k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); + k_params.view_host()(j,i) = k_params.view_host()(i,j); + if (i(cutone*cutone); + } + + k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; + k_cutsq.modify_host(); + k_params.modify_host(); + + return cutone; +} + +namespace LAMMPS_NS { +template class PairUFMKokkos; +#ifdef LMP_KOKKOS_GPU +template class PairUFMKokkos; +#endif +} diff --git a/src/KOKKOS/pair_ufm_kokkos.h b/src/KOKKOS/pair_ufm_kokkos.h new file mode 100644 index 00000000000..e8acada88cf --- /dev/null +++ b/src/KOKKOS/pair_ufm_kokkos.h @@ -0,0 +1,117 @@ +/* -*- 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(ufm/kk,PairUFMKokkos); +PairStyle(ufm/kk/device,PairUFMKokkos); +PairStyle(ufm/kk/host,PairUFMKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_PAIR_UFM_KOKKOS_H +#define LMP_PAIR_UFM_KOKKOS_H + +#include "pair_kokkos.h" +#include "pair_ufm.h" +#include "neigh_list_kokkos.h" + +namespace LAMMPS_NS { + +template +class PairUFMKokkos : public PairUFM { + public: + enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; + enum {COUL_FLAG=0}; + typedef DeviceType device_type; + typedef ArrayTypes AT; + PairUFMKokkos(class LAMMPS *); + ~PairUFMKokkos() override; + + void compute(int, int) override; + + void init_style() override; + double init_one(int, int) override; + + struct params_ufm{ +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_ufm() {cutsq=0;uf1=0;uf2=0;uf3=0;scale=0;offset=0;}; +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + params_ufm(int /*i*/) {cutsq=0;uf1=0;uf2=0;uf3=0;scale=0;offset=0;}; + KK_FLOAT cutsq,uf1,uf2,uf3,scale,offset; + }; + + protected: + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; + + template +// NOLINTNEXTLINE + KOKKOS_INLINE_FUNCTION + KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, + const int& /*itype*/, const int& /*jtype*/) const { return 0; } + + Kokkos::DualView k_params; + typename Kokkos::DualView::t_dev_const_um params; + params_ufm m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; + typename AT::t_kkfloat_1d_3_lr_randomread x; + typename AT::t_kkfloat_1d_3_lr c_x; + typename AT::t_kkacc_1d_3 f; + typename AT::t_int_1d_randomread type; + + DAT::ttransform_kkacc_1d k_eatom; + DAT::ttransform_kkacc_1d_6 k_vatom; + typename AT::t_kkacc_1d d_eatom; + typename AT::t_kkacc_1d_6 d_vatom; + + int newton_pair; + KK_FLOAT special_lj[4]; + + DAT::ttransform_kkfloat_2d k_cutsq; + typename AT::t_kkfloat_2d d_cutsq; + + int neighflag; + int nlocal,nall,eflag,vflag; + + void allocate() override; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend EV_FLOAT pair_compute_neighlist(PairUFMKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairUFMKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairUFMKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairUFMKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairUFMKokkos*,NeighListKokkos*); + friend void pair_virial_fdotr_compute(PairUFMKokkos*); +}; + +} + +#endif +#endif diff --git a/src/KSPACE/pair_born_coul_long.cpp b/src/KSPACE/pair_born_coul_long.cpp index 9e2b9b332ac..16ae850a33f 100644 --- a/src/KSPACE/pair_born_coul_long.cpp +++ b/src/KSPACE/pair_born_coul_long.cpp @@ -51,6 +51,8 @@ PairBornCoulLong::PairBornCoulLong(LAMMPS *lmp) : Pair(lmp) PairBornCoulLong::~PairBornCoulLong() { + if (copymode) return; + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/KSPACE/pair_born_coul_long.h b/src/KSPACE/pair_born_coul_long.h index e76526457eb..024230fcab6 100644 --- a/src/KSPACE/pair_born_coul_long.h +++ b/src/KSPACE/pair_born_coul_long.h @@ -51,7 +51,7 @@ class PairBornCoulLong : public Pair { double *cut_respa; double g_ewald; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/Purge.list b/src/Purge.list index ff79d18ed19..5a22c91b385 100644 --- a/src/Purge.list +++ b/src/Purge.list @@ -1175,6 +1175,7 @@ npair_trim_kokkos.h pack_kokkos.h pair_adp_kokkos.h pair_beck_kokkos.h +pair_born_coul_long_kokkos.h pair_born_kokkos.h pair_brownian_kokkos.h pair_buck_coul_cut_kokkos.h @@ -1185,6 +1186,7 @@ pair_coul_cut_kokkos.h pair_coul_debye_kokkos.h pair_coul_dsf_kokkos.h pair_coul_long_kokkos.h +pair_coul_slater_long_kokkos.h pair_coul_wolf_kokkos.h pair_dpd_ext_kokkos.h pair_dpd_ext_tstat_kokkos.h @@ -1219,6 +1221,8 @@ pair_lj_expand_coul_long_kokkos.h pair_lj_expand_kokkos.h pair_lj_gromacs_coul_gromacs_kokkos.h pair_lj_gromacs_kokkos.h +pair_lj_smooth_kokkos.h +pair_lj_smooth_linear_kokkos.h pair_lj_spica_coul_long_kokkos.h pair_lj_spica_kokkos.h pair_meam_kokkos.h @@ -1240,6 +1244,7 @@ pair_tersoff_kokkos.h pair_tersoff_mod_kokkos.h pair_tersoff_zbl_kokkos.h pair_uf3_kokkos.h +pair_ufm_kokkos.h pair_vashishta_kokkos.h pair_yukawa_colloid_kokkos.h pair_yukawa_kokkos.h @@ -1378,6 +1383,7 @@ npair_ssa_kokkos.cpp npair_trim_kokkos.cpp pair_adp_kokkos.cpp pair_beck_kokkos.cpp +pair_born_coul_long_kokkos.cpp pair_born_kokkos.cpp pair_brownian_kokkos.cpp pair_buck_coul_cut_kokkos.cpp @@ -1388,6 +1394,7 @@ pair_coul_cut_kokkos.cpp pair_coul_debye_kokkos.cpp pair_coul_dsf_kokkos.cpp pair_coul_long_kokkos.cpp +pair_coul_slater_long_kokkos.cpp pair_coul_wolf_kokkos.cpp pair_dpd_ext_kokkos.cpp pair_dpd_ext_tstat_kokkos.cpp @@ -1421,6 +1428,8 @@ pair_lj_expand_coul_long_kokkos.cpp pair_lj_expand_kokkos.cpp pair_lj_gromacs_coul_gromacs_kokkos.cpp pair_lj_gromacs_kokkos.cpp +pair_lj_smooth_kokkos.cpp +pair_lj_smooth_linear_kokkos.cpp pair_lj_spica_coul_long_kokkos.cpp pair_lj_spica_kokkos.cpp pair_meam_kokkos.cpp @@ -1441,6 +1450,7 @@ pair_tersoff_kokkos.cpp pair_tersoff_mod_kokkos.cpp pair_tersoff_zbl_kokkos.cpp pair_uf3_kokkos.cpp +pair_ufm_kokkos.cpp pair_vashishta_kokkos.cpp pair_yukawa_colloid_kokkos.cpp pair_yukawa_kokkos.cpp From c878903047bbd96eb90d8723d89fcb31bbadb7dd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 14 May 2026 18:44:03 +0000 Subject: [PATCH 4/4] Remove lj_smooth_linear Kokkos port (failing tests) Agent-Logs-Url: https://github.com/stanmoore1/lammps/sessions/fef39969-2bfe-497c-b00b-81a23a895829 Co-authored-by: stanmoore1 <18146301+stanmoore1@users.noreply.github.com> --- doc/src/pair_lj_smooth_linear.rst | 3 +- src/EXTRA-PAIR/pair_lj_smooth_linear.cpp | 2 - src/EXTRA-PAIR/pair_lj_smooth_linear.h | 2 +- src/KOKKOS/Install.sh | 2 - src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp | 242 -------------------- src/KOKKOS/pair_lj_smooth_linear_kokkos.h | 117 ---------- src/Purge.list | 2 - 7 files changed, 2 insertions(+), 368 deletions(-) delete mode 100644 src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp delete mode 100644 src/KOKKOS/pair_lj_smooth_linear_kokkos.h diff --git a/doc/src/pair_lj_smooth_linear.rst b/doc/src/pair_lj_smooth_linear.rst index 5cdcbb14405..20b5e6cbda3 100644 --- a/doc/src/pair_lj_smooth_linear.rst +++ b/doc/src/pair_lj_smooth_linear.rst @@ -1,11 +1,10 @@ .. index:: pair_style lj/smooth/linear -.. index:: pair_style lj/smooth/linear/kk .. index:: pair_style lj/smooth/linear/omp pair_style lj/smooth/linear command =================================== -Accelerator Variants: *lj/smooth/linear/kk*, *lj/smooth/linear/omp* +Accelerator Variants: *lj/smooth/linear/omp* Syntax """""" diff --git a/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp b/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp index 61b1df80977..cde36291a28 100644 --- a/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp +++ b/src/EXTRA-PAIR/pair_lj_smooth_linear.cpp @@ -38,8 +38,6 @@ PairLJSmoothLinear::PairLJSmoothLinear(LAMMPS *lmp) : Pair(lmp) { PairLJSmoothLinear::~PairLJSmoothLinear() { - if (copymode) return; - if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/EXTRA-PAIR/pair_lj_smooth_linear.h b/src/EXTRA-PAIR/pair_lj_smooth_linear.h index c42aae3c237..b1e039e7b61 100644 --- a/src/EXTRA-PAIR/pair_lj_smooth_linear.h +++ b/src/EXTRA-PAIR/pair_lj_smooth_linear.h @@ -48,7 +48,7 @@ class PairLJSmoothLinear : public Pair { double **ljcut, **dljcut; double **lj1, **lj2, **lj3, **lj4; - virtual void allocate(); + void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 0a9dc5c69d1..51cc559beed 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -399,8 +399,6 @@ action pair_lj_gromacs_kokkos.cpp pair_lj_gromacs.cpp action pair_lj_gromacs_kokkos.h pair_lj_gromacs.h action pair_lj_smooth_kokkos.cpp pair_lj_smooth.cpp action pair_lj_smooth_kokkos.h pair_lj_smooth.h -action pair_lj_smooth_linear_kokkos.cpp pair_lj_smooth_linear.cpp -action pair_lj_smooth_linear_kokkos.h pair_lj_smooth_linear.h action pair_lj_spica_coul_long_kokkos.cpp pair_lj_spica_coul_long.cpp action pair_lj_spica_coul_long_kokkos.h pair_lj_spica_coul_long.h action pair_lj_spica_kokkos.cpp pair_lj_spica.cpp diff --git a/src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp b/src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp deleted file mode 100644 index f390de4b2f7..00000000000 --- a/src/KOKKOS/pair_lj_smooth_linear_kokkos.cpp +++ /dev/null @@ -1,242 +0,0 @@ -// 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. -------------------------------------------------------------------------- */ - -/* ---------------------------------------------------------------------- - Contributing author: Stan Moore (SNL) -------------------------------------------------------------------------- */ - -#include "pair_lj_smooth_linear_kokkos.h" - -#include "atom_kokkos.h" -#include "atom_masks.h" -#include "error.h" -#include "force.h" -#include "kokkos.h" -#include "memory_kokkos.h" -#include "neigh_request.h" -#include "neighbor.h" -#include "respa.h" -#include "update.h" - -#include - -using namespace LAMMPS_NS; - -/* ---------------------------------------------------------------------- */ - -template -PairLJSmoothLinearKokkos::PairLJSmoothLinearKokkos(LAMMPS *lmp) : PairLJSmoothLinear(lmp) -{ - respa_enable = 0; - - kokkosable = 1; - atomKK = (AtomKokkos *) atom; - execution_space = ExecutionSpaceFromDevice::space; - datamask_read = X_MASK | F_MASK | TYPE_MASK | ENERGY_MASK | VIRIAL_MASK; - datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; -} - -/* ---------------------------------------------------------------------- */ - -template -PairLJSmoothLinearKokkos::~PairLJSmoothLinearKokkos() -{ - if (copymode) return; - - if (allocated) { - memoryKK->destroy_kokkos(k_eatom,eatom); - memoryKK->destroy_kokkos(k_vatom,vatom); - memoryKK->destroy_kokkos(k_cutsq,cutsq); - } -} - -/* ---------------------------------------------------------------------- */ - -template -void PairLJSmoothLinearKokkos::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); - - if (eflag_atom) { - memoryKK->destroy_kokkos(k_eatom,eatom); - memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); - d_eatom = k_eatom.view(); - } - if (vflag_atom) { - memoryKK->destroy_kokkos(k_vatom,vatom); - memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); - d_vatom = k_vatom.view(); - } - - atomKK->sync(execution_space,datamask_read); - k_cutsq.template sync(); - k_params.template sync(); - if (eflag || vflag) atomKK->modified(execution_space,datamask_modify); - else atomKK->modified(execution_space,F_MASK); - - x = atomKK->k_x.view(); - c_x = atomKK->k_x.view(); - f = atomKK->k_f.view(); - type = atomKK->k_type.view(); - 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]; - - copymode = 1; - EV_FLOAT ev = pair_compute,void>(this,(NeighListKokkos*)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 (vflag_fdotr) pair_virial_fdotr_compute(this); - - if (eflag_atom) { - k_eatom.template modify(); - k_eatom.sync_host(); - } - - if (vflag_atom) { - k_vatom.template modify(); - k_vatom.sync_host(); - } - - copymode = 0; -} - -template -template -// NOLINTNEXTLINE -KOKKOS_INLINE_FUNCTION -KK_FLOAT PairLJSmoothLinearKokkos:: -compute_fpair(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { - const KK_FLOAT r2inv = static_cast(1.0) / rsq; - const KK_FLOAT r6inv = r2inv*r2inv*r2inv; - const KK_FLOAT rinv = sqrt(r2inv); - const KK_FLOAT lj1 = STACKPARAMS ? m_params[itype][jtype].lj1 : params(itype,jtype).lj1; - const KK_FLOAT lj2 = STACKPARAMS ? m_params[itype][jtype].lj2 : params(itype,jtype).lj2; - const KK_FLOAT dljcut = STACKPARAMS ? m_params[itype][jtype].dljcut : params(itype,jtype).dljcut; - const KK_FLOAT forcelj = rinv*r6inv*(lj1*r6inv - lj2) - dljcut; - return forcelj*rinv; -} - -template -template -// NOLINTNEXTLINE -KOKKOS_INLINE_FUNCTION -KK_FLOAT PairLJSmoothLinearKokkos:: -compute_evdwl(const KK_FLOAT &rsq, const int &, const int &, const int &itype, const int &jtype) const { - const KK_FLOAT r2inv = static_cast(1.0) / rsq; - const KK_FLOAT r6inv = r2inv*r2inv*r2inv; - const KK_FLOAT r = sqrt(rsq); - const KK_FLOAT lj3 = STACKPARAMS ? m_params[itype][jtype].lj3 : params(itype,jtype).lj3; - const KK_FLOAT lj4 = STACKPARAMS ? m_params[itype][jtype].lj4 : params(itype,jtype).lj4; - const KK_FLOAT ljcut = STACKPARAMS ? m_params[itype][jtype].ljcut : params(itype,jtype).ljcut; - const KK_FLOAT dljcut = STACKPARAMS ? m_params[itype][jtype].dljcut : params(itype,jtype).dljcut; - const KK_FLOAT cut = STACKPARAMS ? m_params[itype][jtype].cut : params(itype,jtype).cut; - return r6inv*(lj3*r6inv - lj4) - ljcut + (r - cut)*dljcut; -} - -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -template -void PairLJSmoothLinearKokkos::allocate() -{ - PairLJSmoothLinear::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(); - k_params = Kokkos::DualView("PairLJSmoothLinear::params",n+1,n+1); - params = k_params.template view(); -} - -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -template -void PairLJSmoothLinearKokkos::init_style() -{ - PairLJSmoothLinear::init_style(); - - 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"); - } - - neighflag = lmp->kokkos->neighflag; - auto request = neighbor->find_request(this); - request->set_kokkos_host(std::is_same_v && - !std::is_same_v); - request->set_kokkos_device(std::is_same_v); - if (neighflag == FULL) request->enable_full(); -} - -/* ---------------------------------------------------------------------- - init for one type pair i,j and corresponding j,i -------------------------------------------------------------------------- */ - -template -double PairLJSmoothLinearKokkos::init_one(int i, int j) -{ - double cutone = PairLJSmoothLinear::init_one(i,j); - - k_params.view_host()(i,j).lj1 = static_cast(lj1[i][j]); - k_params.view_host()(i,j).lj2 = static_cast(lj2[i][j]); - k_params.view_host()(i,j).lj3 = static_cast(lj3[i][j]); - k_params.view_host()(i,j).lj4 = static_cast(lj4[i][j]); - k_params.view_host()(i,j).ljcut = static_cast(ljcut[i][j]); - k_params.view_host()(i,j).dljcut = static_cast(dljcut[i][j]); - k_params.view_host()(i,j).cut = static_cast(cut[i][j]); - k_params.view_host()(i,j).cutsq = static_cast(cutone*cutone); - k_params.view_host()(j,i) = k_params.view_host()(i,j); - if (i(cutone*cutone); - } - - k_cutsq.view_host()(i,j) = k_cutsq.view_host()(j,i) = cutone*cutone; - k_cutsq.modify_host(); - k_params.modify_host(); - - return cutone; -} - -namespace LAMMPS_NS { -template class PairLJSmoothLinearKokkos; -#ifdef LMP_KOKKOS_GPU -template class PairLJSmoothLinearKokkos; -#endif -} diff --git a/src/KOKKOS/pair_lj_smooth_linear_kokkos.h b/src/KOKKOS/pair_lj_smooth_linear_kokkos.h deleted file mode 100644 index bb872b29067..00000000000 --- a/src/KOKKOS/pair_lj_smooth_linear_kokkos.h +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- 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(lj/smooth/linear/kk,PairLJSmoothLinearKokkos); -PairStyle(lj/smooth/linear/kk/device,PairLJSmoothLinearKokkos); -PairStyle(lj/smooth/linear/kk/host,PairLJSmoothLinearKokkos); -// clang-format on -#else - -// clang-format off -#ifndef LMP_PAIR_LJ_SMOOTH_LINEAR_KOKKOS_H -#define LMP_PAIR_LJ_SMOOTH_LINEAR_KOKKOS_H - -#include "pair_kokkos.h" -#include "pair_lj_smooth_linear.h" -#include "neigh_list_kokkos.h" - -namespace LAMMPS_NS { - -template -class PairLJSmoothLinearKokkos : public PairLJSmoothLinear { - public: - enum {EnabledNeighFlags=FULL|HALFTHREAD|HALF}; - enum {COUL_FLAG=0}; - typedef DeviceType device_type; - typedef ArrayTypes AT; - PairLJSmoothLinearKokkos(class LAMMPS *); - ~PairLJSmoothLinearKokkos() override; - - void compute(int, int) override; - - void init_style() override; - double init_one(int, int) override; - - struct params_lj_smooth_linear{ -// NOLINTNEXTLINE - KOKKOS_INLINE_FUNCTION - params_lj_smooth_linear() {cutsq=0;lj1=0;lj2=0;lj3=0;lj4=0;ljcut=0;dljcut=0;cut=0;}; -// NOLINTNEXTLINE - KOKKOS_INLINE_FUNCTION - params_lj_smooth_linear(int /*i*/) {cutsq=0;lj1=0;lj2=0;lj3=0;lj4=0;ljcut=0;dljcut=0;cut=0;}; - KK_FLOAT cutsq,lj1,lj2,lj3,lj4,ljcut,dljcut,cut; - }; - - protected: - template -// NOLINTNEXTLINE - KOKKOS_INLINE_FUNCTION - KK_FLOAT compute_fpair(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; - - template -// NOLINTNEXTLINE - KOKKOS_INLINE_FUNCTION - KK_FLOAT compute_evdwl(const KK_FLOAT& rsq, const int& i, const int&j, const int& itype, const int& jtype) const; - - template -// NOLINTNEXTLINE - KOKKOS_INLINE_FUNCTION - KK_FLOAT compute_ecoul(const KK_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, - const int& /*itype*/, const int& /*jtype*/) const { return 0; } - - Kokkos::DualView k_params; - typename Kokkos::DualView::t_dev_const_um params; - params_lj_smooth_linear m_params[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; - KK_FLOAT m_cutsq[MAX_TYPES_STACKPARAMS+1][MAX_TYPES_STACKPARAMS+1]; - typename AT::t_kkfloat_1d_3_lr_randomread x; - typename AT::t_kkfloat_1d_3_lr c_x; - typename AT::t_kkacc_1d_3 f; - typename AT::t_int_1d_randomread type; - - DAT::ttransform_kkacc_1d k_eatom; - DAT::ttransform_kkacc_1d_6 k_vatom; - typename AT::t_kkacc_1d d_eatom; - typename AT::t_kkacc_1d_6 d_vatom; - - int newton_pair; - KK_FLOAT special_lj[4]; - - DAT::ttransform_kkfloat_2d k_cutsq; - typename AT::t_kkfloat_2d d_cutsq; - - int neighflag; - int nlocal,nall,eflag,vflag; - - void allocate() override; - friend struct PairComputeFunctor; - friend struct PairComputeFunctor; - friend struct PairComputeFunctor; - friend struct PairComputeFunctor; - friend struct PairComputeFunctor; - friend struct PairComputeFunctor; - friend struct PairComputeFunctor; - friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJSmoothLinearKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairLJSmoothLinearKokkos*,NeighListKokkos*); - friend void pair_virial_fdotr_compute(PairLJSmoothLinearKokkos*); -}; - -} - -#endif -#endif diff --git a/src/Purge.list b/src/Purge.list index 5a22c91b385..d998879e577 100644 --- a/src/Purge.list +++ b/src/Purge.list @@ -1222,7 +1222,6 @@ pair_lj_expand_kokkos.h pair_lj_gromacs_coul_gromacs_kokkos.h pair_lj_gromacs_kokkos.h pair_lj_smooth_kokkos.h -pair_lj_smooth_linear_kokkos.h pair_lj_spica_coul_long_kokkos.h pair_lj_spica_kokkos.h pair_meam_kokkos.h @@ -1429,7 +1428,6 @@ pair_lj_expand_kokkos.cpp pair_lj_gromacs_coul_gromacs_kokkos.cpp pair_lj_gromacs_kokkos.cpp pair_lj_smooth_kokkos.cpp -pair_lj_smooth_linear_kokkos.cpp pair_lj_spica_coul_long_kokkos.cpp pair_lj_spica_kokkos.cpp pair_meam_kokkos.cpp