Skip to content

Commit

Permalink
Merge pull request lammps#4167 from stanmoore1/kk_hybrid_topo
Browse files Browse the repository at this point in the history
Port hybrid bond topology styles to Kokkos
  • Loading branch information
stanmoore1 authored Jun 5, 2024
2 parents c6f32b8 + c1c3f21 commit 7ef9a93
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 67 deletions.
2 changes: 1 addition & 1 deletion doc/src/Commands_bond.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ OPT.

* :doc:`none <angle_none>`
* :doc:`zero <angle_zero>`
* :doc:`hybrid <angle_hybrid>`
* :doc:`hybrid (k) <angle_hybrid>`
*
*
*
Expand Down
9 changes: 8 additions & 1 deletion doc/src/bond_hybrid.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.. index:: bond_style hybrid
.. index:: bond_style hybrid/kk

bond_style hybrid command
=========================

Accelerator Variants: *hybrid/kk*

Syntax
""""""

Expand All @@ -15,7 +18,7 @@ Syntax
Examples
""""""""

.. code-block: LAMMPS
.. code-block:: LAMMPS
bond_style hybrid harmonic fene
bond_coeff 1 harmonic 80.0 1.2
Expand Down Expand Up @@ -60,6 +63,10 @@ bond types.

----------

.. include:: accel_styles.rst

----------

Restrictions
""""""""""""

Expand Down
2 changes: 2 additions & 0 deletions src/KOKKOS/Install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ action bond_fene_kokkos.cpp bond_fene.cpp
action bond_fene_kokkos.h bond_fene.h
action bond_harmonic_kokkos.cpp bond_harmonic.cpp
action bond_harmonic_kokkos.h bond_harmonic.h
action bond_hybrid_kokkos.cpp bond_hybrid.cpp
action bond_hybrid_kokkos.h bond_hybrid.h
action comm_kokkos.cpp
action comm_kokkos.h
action comm_tiled_kokkos.cpp
Expand Down
22 changes: 12 additions & 10 deletions src/KOKKOS/bond_class2_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ using namespace LAMMPS_NS;
template<class DeviceType>
BondClass2Kokkos<DeviceType>::BondClass2Kokkos(LAMMPS *lmp) : BondClass2(lmp)
{
kokkosable = 1;

atomKK = (AtomKokkos *) atom;
neighborKK = (NeighborKokkos *) neighbor;
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
Expand Down Expand Up @@ -122,12 +124,12 @@ void BondClass2Kokkos<DeviceType>::compute(int eflag_in, int vflag_in)

if (eflag_atom) {
k_eatom.template modify<DeviceType>();
k_eatom.template sync<LMPHostType>();
k_eatom.sync_host();
}

if (vflag_atom) {
k_vatom.template modify<DeviceType>();
k_vatom.template sync<LMPHostType>();
k_vatom.sync_host();
}

copymode = 0;
Expand Down Expand Up @@ -227,13 +229,13 @@ void BondClass2Kokkos<DeviceType>::coeff(int narg, char **arg)
k_r0.h_view[i] = r0[i];
}

k_k2.template modify<LMPHostType>();
k_k2.modify_host();
k_k2.template sync<DeviceType>();
k_k3.template modify<LMPHostType>();
k_k3.modify_host();
k_k3.template sync<DeviceType>();
k_k4.template modify<LMPHostType>();
k_k4.modify_host();
k_k4.template sync<DeviceType>();
k_r0.template modify<LMPHostType>();
k_r0.modify_host();
k_r0.template sync<DeviceType>();
}

Expand Down Expand Up @@ -264,13 +266,13 @@ void BondClass2Kokkos<DeviceType>::read_restart(FILE *fp)
k_r0.h_view[i] = r0[i];
}

k_k2.template modify<LMPHostType>();
k_k2.modify_host();
k_k2.template sync<DeviceType>();
k_k3.template modify<LMPHostType>();
k_k3.modify_host();
k_k3.template sync<DeviceType>();
k_k4.template modify<LMPHostType>();
k_k4.modify_host();
k_k4.template sync<DeviceType>();
k_r0.template modify<LMPHostType>();
k_r0.modify_host();
k_r0.template sync<DeviceType>();
}

Expand Down
7 changes: 4 additions & 3 deletions src/KOKKOS/bond_class2_kokkos.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class BondClass2Kokkos : public BondClass2 {
const F_FLOAT &ebond, const F_FLOAT &fbond, const F_FLOAT &delx,
const F_FLOAT &dely, const F_FLOAT &delz) const;

typedef typename KKDevice<DeviceType>::value KKDeviceType;
Kokkos::DualView<E_FLOAT*,Kokkos::LayoutRight,KKDeviceType> k_eatom;
Kokkos::DualView<F_FLOAT*[6],Kokkos::LayoutRight,KKDeviceType> k_vatom;

protected:

class NeighborKokkos *neighborKK;
Expand All @@ -67,9 +71,6 @@ class BondClass2Kokkos : public BondClass2 {
typename Kokkos::View<double*[3],typename AT::t_f_array::array_layout,typename KKDevice<DeviceType>::value,Kokkos::MemoryTraits<Kokkos::Atomic> > f;
typename AT::t_int_2d bondlist;

typedef typename KKDevice<DeviceType>::value KKDeviceType;
Kokkos::DualView<E_FLOAT*,Kokkos::LayoutRight,KKDeviceType> k_eatom;
Kokkos::DualView<F_FLOAT*[6],Kokkos::LayoutRight,KKDeviceType> k_vatom;
Kokkos::View<E_FLOAT*,Kokkos::LayoutRight,KKDeviceType,Kokkos::MemoryTraits<Kokkos::Atomic> > d_eatom;
Kokkos::View<F_FLOAT*[6],Kokkos::LayoutRight,KKDeviceType,Kokkos::MemoryTraits<Kokkos::Atomic> > d_vatom;

Expand Down
22 changes: 12 additions & 10 deletions src/KOKKOS/bond_fene_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ using MathConst::MY_CUBEROOT2;
template<class DeviceType>
BondFENEKokkos<DeviceType>::BondFENEKokkos(LAMMPS *lmp) : BondFENE(lmp)
{
kokkosable = 1;

atomKK = (AtomKokkos *) atom;
neighborKK = (NeighborKokkos *) neighbor;
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
Expand Down Expand Up @@ -135,12 +137,12 @@ void BondFENEKokkos<DeviceType>::compute(int eflag_in, int vflag_in)

if (eflag_atom) {
k_eatom.template modify<DeviceType>();
k_eatom.template sync<LMPHostType>();
k_eatom.sync_host();
}

if (vflag_atom) {
k_vatom.template modify<DeviceType>();
k_vatom.template sync<LMPHostType>();
k_vatom.sync_host();
}

copymode = 0;
Expand Down Expand Up @@ -267,10 +269,10 @@ void BondFENEKokkos<DeviceType>::coeff(int narg, char **arg)
k_sigma.h_view[i] = sigma[i];
}

k_k.template modify<LMPHostType>();
k_r0.template modify<LMPHostType>();
k_epsilon.template modify<LMPHostType>();
k_sigma.template modify<LMPHostType>();
k_k.modify_host();
k_r0.modify_host();
k_epsilon.modify_host();
k_sigma.modify_host();
}


Expand All @@ -291,10 +293,10 @@ void BondFENEKokkos<DeviceType>::read_restart(FILE *fp)
k_sigma.h_view[i] = sigma[i];
}

k_k.template modify<LMPHostType>();
k_r0.template modify<LMPHostType>();
k_epsilon.template modify<LMPHostType>();
k_sigma.template modify<LMPHostType>();
k_k.modify_host();
k_r0.modify_host();
k_epsilon.modify_host();
k_sigma.modify_host();
}

/* ----------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/KOKKOS/bond_fene_kokkos.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class BondFENEKokkos : public BondFENE {
const F_FLOAT &ebond, const F_FLOAT &fbond, const F_FLOAT &delx,
const F_FLOAT &dely, const F_FLOAT &delz) const;

DAT::tdual_efloat_1d k_eatom;
DAT::tdual_virial_array k_vatom;

protected:

class NeighborKokkos *neighborKK;
Expand All @@ -66,8 +69,6 @@ class BondFENEKokkos : public BondFENE {
typename ArrayTypes<DeviceType>::t_f_array f;
typename ArrayTypes<DeviceType>::t_int_2d bondlist;

DAT::tdual_efloat_1d k_eatom;
DAT::tdual_virial_array k_vatom;
typename ArrayTypes<DeviceType>::t_efloat_1d d_eatom;
typename ArrayTypes<DeviceType>::t_virial_array d_vatom;

Expand Down
25 changes: 12 additions & 13 deletions src/KOKKOS/bond_harmonic_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ using namespace LAMMPS_NS;
template<class DeviceType>
BondHarmonicKokkos<DeviceType>::BondHarmonicKokkos(LAMMPS *lmp) : BondHarmonic(lmp)
{
kokkosable = 1;

atomKK = (AtomKokkos *) atom;
neighborKK = (NeighborKokkos *) neighbor;
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
Expand Down Expand Up @@ -65,23 +67,20 @@ void BondHarmonicKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
// reallocate per-atom arrays if necessary

if (eflag_atom) {
//if(k_eatom.extent(0)<maxeatom) { // won't work without adding zero functor
if (k_eatom.extent(0) < maxeatom) {
memoryKK->destroy_kokkos(k_eatom,eatom);
memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"improper:eatom");
d_eatom = k_eatom.template view<KKDeviceType>();
//}
} else Kokkos::deep_copy(d_eatom,0.0);
}
if (vflag_atom) {
//if(k_vatom.extent(0)<maxvatom) { // won't work without adding zero functor
if (k_vatom.extent(0) < maxvatom) {
memoryKK->destroy_kokkos(k_vatom,vatom);
memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"improper:vatom");
d_vatom = k_vatom.template view<KKDeviceType>();
//}
} else Kokkos::deep_copy(d_vatom,0.0);
}

// if (eflag || vflag) atomKK->modified(execution_space,datamask_modify);
// else atomKK->modified(execution_space,F_MASK);

x = atomKK->k_x.template view<DeviceType>();
f = atomKK->k_f.template view<DeviceType>();
neighborKK->k_bondlist.template sync<DeviceType>();
Expand Down Expand Up @@ -122,12 +121,12 @@ void BondHarmonicKokkos<DeviceType>::compute(int eflag_in, int vflag_in)

if (eflag_atom) {
k_eatom.template modify<DeviceType>();
k_eatom.template sync<LMPHostType>();
k_eatom.sync_host();
}

if (vflag_atom) {
k_vatom.template modify<DeviceType>();
k_vatom.template sync<LMPHostType>();
k_vatom.sync_host();
}

copymode = 0;
Expand Down Expand Up @@ -214,8 +213,8 @@ void BondHarmonicKokkos<DeviceType>::coeff(int narg, char **arg)
k_r0.h_view[i] = r0[i];
}

k_k.template modify<LMPHostType>();
k_r0.template modify<LMPHostType>();
k_k.modify_host();
k_r0.modify_host();
k_k.template sync<DeviceType>();
k_r0.template sync<DeviceType>();
}
Expand All @@ -241,8 +240,8 @@ void BondHarmonicKokkos<DeviceType>::read_restart(FILE *fp)
k_r0.h_view[i] = r0[i];
}

k_k.template modify<LMPHostType>();
k_r0.template modify<LMPHostType>();
k_k.modify_host();
k_r0.modify_host();
k_k.template sync<DeviceType>();
k_r0.template sync<DeviceType>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/KOKKOS/bond_harmonic_kokkos.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class BondHarmonicKokkos : public BondHarmonic {
public:
typedef DeviceType device_type;
typedef EV_FLOAT value_type;
typedef ArrayTypes<DeviceType> AT;

BondHarmonicKokkos(class LAMMPS *);
~BondHarmonicKokkos() override;
Expand All @@ -62,7 +63,6 @@ class BondHarmonicKokkos : public BondHarmonic {

class NeighborKokkos *neighborKK;

typedef ArrayTypes<DeviceType> AT;
typename AT::t_x_array_randomread x;
typename Kokkos::View<double*[3],typename AT::t_f_array::array_layout,typename KKDevice<DeviceType>::value,Kokkos::MemoryTraits<Kokkos::Atomic> > f;
typename AT::t_int_2d bondlist;
Expand Down
Loading

0 comments on commit 7ef9a93

Please sign in to comment.