Skip to content

Commit

Permalink
Merge pull request lammps#4346 from cjknight/lubricate_patch
Browse files Browse the repository at this point in the history
features + bug fixes for granular simulations w/ Kokkos
  • Loading branch information
akohlmey authored Oct 5, 2024
2 parents 36dd4de + 70cbf05 commit 224468d
Show file tree
Hide file tree
Showing 32 changed files with 1,071 additions and 215 deletions.
2 changes: 1 addition & 1 deletion doc/src/Commands_pair.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OPT.
* :doc:`born/coul/wolf/cs (g) <pair_cs>`
* :doc:`born/gauss <pair_born_gauss>`
* :doc:`bpm/spring <pair_bpm_spring>`
* :doc:`brownian (o) <pair_brownian>`
* :doc:`brownian (ko) <pair_brownian>`
* :doc:`brownian/poly (o) <pair_brownian>`
* :doc:`buck (giko) <pair_buck>`
* :doc:`buck/coul/cut (giko) <pair_buck>`
Expand Down
3 changes: 2 additions & 1 deletion doc/src/pair_brownian.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.. index:: pair_style brownian
.. index:: pair_style brownian/omp
.. index:: pair_style brownian/kk
.. index:: pair_style brownian/poly
.. index:: pair_style brownian/poly/omp

pair_style brownian command
===========================

Accelerator Variants: *brownian/omp*
Accelerator Variants: *brownian/omp*, *brownian/kk*

pair_style brownian/poly command
================================
Expand Down
2 changes: 2 additions & 0 deletions src/COLLOID/pair_brownian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ PairBrownian::PairBrownian(LAMMPS *lmp) : Pair(lmp)

PairBrownian::~PairBrownian()
{
if (copymode) return;

if (allocated) {
memory->destroy(setflag);
memory->destroy(cutsq);
Expand Down
4 changes: 2 additions & 2 deletions src/COLLOID/pair_brownian.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PairBrownian : public Pair {
void compute(int, int) override;
void settings(int, char **) override;
void coeff(int, char **) override;
double init_one(int, int) override;
virtual double init_one(int, int) override;
void init_style() override;
void write_restart(FILE *) override;
void read_restart(FILE *) override;
Expand All @@ -55,7 +55,7 @@ class PairBrownian : public Pair {
class RanMars *random;

void set_3_orthogonal_vectors(double *, double *, double *);
void allocate();
virtual void allocate();
};

} // namespace LAMMPS_NS
Expand Down
2 changes: 2 additions & 0 deletions src/KOKKOS/Install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ action npair_trim_kokkos.h
action pack_kokkos.h pack.h
action pair_adp_kokkos.cpp pair_adp.cpp
action pair_adp_kokkos.h pair_adp.h
action pair_brownian_kokkos.cpp pair_brownian.cpp
action pair_brownian_kokkos.h pair_brownian.h
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
Expand Down
20 changes: 17 additions & 3 deletions src/KOKKOS/compute_temp_deform_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,20 @@ void ComputeTempDeformKokkos<DeviceType>::operator()(TagComputeTempDeformVector<
}

/* ---------------------------------------------------------------------- */

template<class DeviceType>
void ComputeTempDeformKokkos<DeviceType>::remove_bias_all()
{
atomKK->sync(execution_space,datamask_read);
remove_bias_all_kk();
atomKK->sync(Host,V_MASK);
}

/* ---------------------------------------------------------------------- */

template<class DeviceType>
void ComputeTempDeformKokkos<DeviceType>::remove_bias_all_kk()
{
atomKK->sync(execution_space,X_MASK|V_MASK);
v = atomKK->k_v.view<DeviceType>();
x = atomKK->k_x.view<DeviceType>();
mask = atomKK->k_mask.view<DeviceType>();
Expand All @@ -214,6 +224,8 @@ void ComputeTempDeformKokkos<DeviceType>::remove_bias_all()
copymode = 0;

domainKK->lamda2x(nlocal);

atomKK->modified(execution_space,V_MASK);
}

template<class DeviceType>
Expand All @@ -230,18 +242,20 @@ void ComputeTempDeformKokkos<DeviceType>::operator()(TagComputeTempDeformRemoveB
}

/* ---------------------------------------------------------------------- */

template<class DeviceType>
void ComputeTempDeformKokkos<DeviceType>::restore_bias_all()
{
atomKK->sync(execution_space,datamask_read);
atomKK->sync(execution_space,V_MASK);
v = atomKK->k_v.view<DeviceType>();
x = atomKK->k_x.view<DeviceType>();
mask = atomKK->k_mask.view<DeviceType>();
int nlocal = atom->nlocal;

copymode = 1;
Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType, TagComputeTempDeformRestoreBias >(0,nlocal),*this);
copymode = 0;

atomKK->modified(execution_space,V_MASK);
}

template<class DeviceType>
Expand Down
1 change: 1 addition & 0 deletions src/KOKKOS/compute_temp_deform_kokkos.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ComputeTempDeformKokkos: public ComputeTempDeform {
double compute_scalar() override;
void compute_vector() override;
void remove_bias_all() override;
void remove_bias_all_kk() override;
void restore_bias_all() override;

template<int RMASS>
Expand Down
8 changes: 6 additions & 2 deletions src/KOKKOS/fix_deform_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ void FixDeformKokkos::pre_exchange()

void FixDeformKokkos::end_of_step()
{
atomKK->sync(Host,ALL_MASK);
if (remapflag == Domain::X_REMAP && rfix.size() > 0)
atomKK->sync(Host,ALL_MASK);

FixDeform::end_of_step();
atomKK->modified(Host,ALL_MASK);

if (remapflag == Domain::X_REMAP && rfix.size() > 0)
atomKK->modified(Host,ALL_MASK);
}
28 changes: 17 additions & 11 deletions src/KOKKOS/fix_langevin_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ FixLangevinKokkos<DeviceType>::FixLangevinKokkos(LAMMPS *lmp, int narg, char **a
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
datamask_read = V_MASK | F_MASK | MASK_MASK | RMASS_MASK | TYPE_MASK;
datamask_modify = F_MASK;

}

/* ---------------------------------------------------------------------- */
Expand Down Expand Up @@ -227,12 +226,16 @@ void FixLangevinKokkos<DeviceType>::post_force(int /*vflag*/)

// account for bias velocity
if (tbiasflag == BIAS) {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->compute_scalar();
temperature->remove_bias_all(); // modifies velocities
// if temeprature compute is kokkosized host-device comm won't be needed
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
if (temperature->kokkosable) {
temperature->compute_scalar();
temperature->remove_bias_all_kk();
} else {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->compute_scalar();
temperature->remove_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
}
}

// compute langevin force in parallel on the device
Expand Down Expand Up @@ -526,10 +529,13 @@ void FixLangevinKokkos<DeviceType>::post_force(int /*vflag*/)


if (tbiasflag == BIAS) {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->restore_bias_all(); // modifies velocities
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
if (temperature->kokkosable) temperature->restore_bias_all();
else {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->restore_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
}
}

// set modify flags for the views modified in post_force functor
Expand Down
74 changes: 54 additions & 20 deletions src/KOKKOS/fix_nh_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ void FixNHKokkos<DeviceType>::setup(int /*vflag*/)
{
// tdof needed by compute_temp_target()

atomKK->sync(temperature->execution_space,temperature->datamask_read);
t_current = temperature->compute_scalar();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);

tdof = temperature->dof;

// t_target is needed by NPH and NPT in compute_scalar()
Expand All @@ -105,6 +109,7 @@ void FixNHKokkos<DeviceType>::setup(int /*vflag*/)
atomKK->sync(temperature->execution_space,temperature->datamask_read);
t0 = temperature->compute_scalar();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
if (t0 < EPSILON)
error->all(FLERR,"Current temperature too close to zero, consider using ptemp keyword");
}
Expand All @@ -117,6 +122,8 @@ void FixNHKokkos<DeviceType>::setup(int /*vflag*/)
atomKK->sync(temperature->execution_space,temperature->datamask_read);
t_current = temperature->compute_scalar();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);

tdof = temperature->dof;

if (pstat_flag) {
Expand Down Expand Up @@ -194,16 +201,18 @@ void FixNHKokkos<DeviceType>::initial_integrate(int /*vflag*/)

if (pstat_flag) {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
//atomKK->sync(pressure->execution_space,pressure->datamask_read);
//atomKK->modified(pressure->execution_space,pressure->datamask_modify);
atomKK->sync(pressure->execution_space,pressure->datamask_read);
if (pstyle == ISO) {
temperature->compute_scalar();
pressure->compute_scalar();
} else {
temperature->compute_vector();
pressure->compute_vector();
}
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->modified(pressure->execution_space,pressure->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,pressure->datamask_modify);
couple();
pressure->addstep(update->ntimestep+1);
}
Expand Down Expand Up @@ -250,6 +259,7 @@ void FixNHKokkos<DeviceType>::final_integrate()
atomKK->sync(temperature->execution_space,temperature->datamask_read);
t_current = temperature->compute_scalar();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
}

if (pstat_flag) nh_v_press();
Expand All @@ -260,15 +270,24 @@ void FixNHKokkos<DeviceType>::final_integrate()
atomKK->sync(temperature->execution_space,temperature->datamask_read);
t_current = temperature->compute_scalar();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
tdof = temperature->dof;

if (pstat_flag) {
//atomKK->sync(pressure->execution_space,pressure->datamask_read);
//atomKK->modified(pressure->execution_space,pressure->datamask_modify);
if (pstyle == ISO) pressure->compute_scalar();
else {
if (pstyle == ISO) {
atomKK->sync(pressure->execution_space,pressure->datamask_read);
pressure->compute_scalar();
atomKK->modified(pressure->execution_space,pressure->datamask_modify);
atomKK->sync(execution_space,pressure->datamask_modify);
} else {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
atomKK->sync(pressure->execution_space,pressure->datamask_read);
temperature->compute_vector();
pressure->compute_vector();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->modified(pressure->execution_space,pressure->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,pressure->datamask_modify);
}
couple();
pressure->addstep(update->ntimestep+1);
Expand Down Expand Up @@ -480,9 +499,13 @@ void FixNHKokkos<DeviceType>::nh_v_press()
factor[2] = exp(-dt4*(omega_dot[2]+mtk_term2));

if (which == BIAS) {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->remove_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
if (temperature->kokkosable) temperature->remove_bias_all_kk();
else {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->remove_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
}
}

atomKK->sync(execution_space,V_MASK | MASK_MASK);
Expand All @@ -497,11 +520,14 @@ void FixNHKokkos<DeviceType>::nh_v_press()
atomKK->modified(execution_space,V_MASK);

if (which == BIAS) {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->restore_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
if (temperature->kokkosable) temperature->restore_bias_all();
else {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->restore_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
}
}

}

template<class DeviceType>
Expand Down Expand Up @@ -617,9 +643,13 @@ void FixNHKokkos<DeviceType>::nh_v_temp()
if (igroup == atomKK->firstgroup) nlocal = atomKK->nfirst;

if (which == BIAS) {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->remove_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
if (temperature->kokkosable) temperature->remove_bias_all_kk();
else {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->remove_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
}
}

atomKK->sync(execution_space,V_MASK | MASK_MASK);
Expand All @@ -631,9 +661,13 @@ void FixNHKokkos<DeviceType>::nh_v_temp()
atomKK->modified(execution_space,V_MASK);

if (which == BIAS) {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->restore_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
if (temperature->kokkosable) temperature->restore_bias_all();
else {
atomKK->sync(temperature->execution_space,temperature->datamask_read);
temperature->restore_bias_all();
atomKK->modified(temperature->execution_space,temperature->datamask_modify);
atomKK->sync(execution_space,temperature->datamask_modify);
}
}
}

Expand Down
Loading

0 comments on commit 224468d

Please sign in to comment.