Disable Kokkos GPU <--> CPU overlap when using pair hybrid with non-Kokkos styles

This commit is contained in:
Stan Moore
2023-02-01 16:13:09 -07:00
parent b8b5e385b6
commit c0c5c34290
5 changed files with 78 additions and 83 deletions

View File

@ -99,6 +99,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
memoryKK = (MemoryKokkos*) memory;
auto_sync = 1;
allow_overlap = 1;
int me = 0;
MPI_Comm_rank(world,&me);

View File

@ -49,6 +49,7 @@ class KokkosLMP : protected Pointers {
int neigh_thread_set;
int neigh_transpose;
int newtonflag;
int allow_overlap;
double binsize;
static int is_finalized;

View File

@ -43,6 +43,19 @@ PairHybridKokkos::PairHybridKokkos(LAMMPS *lmp) : PairHybrid(lmp)
datamask_modify = EMPTY_MASK;
}
/* ----------------------------------------------------------------------
init specific to this pair style
------------------------------------------------------------------------- */
void PairHybridKokkos::init_style()
{
PairHybrid::init_style();
for (int m = 0; m < nstyles; m++)
if (styles[m]->execution_space == Host)
lmp->kokkos->allow_overlap = 0;
}
/* ----------------------------------------------------------------------
call each sub-style's compute() or compute_outer() function
accumulate sub-style global/peratom energy/virial in hybrid
@ -157,7 +170,6 @@ void PairHybridKokkos::compute(int eflag, int vflag)
}
}
}
}
delete [] saved_special;

View File

@ -40,6 +40,7 @@ class PairHybridKokkos : public PairHybrid {
PairHybridKokkos(class LAMMPS *);
void compute(int, int) override;
void init_style() override;
private:
DAT::t_x_array_randomread x;

View File

@ -372,123 +372,103 @@ void VerletKokkos::run(int n)
}
bool execute_on_host = false;
unsigned int datamask_read_device = 0;
unsigned int datamask_modify_device = 0;
unsigned int datamask_read_host = 0;
unsigned int datamask_exclude = 0;
int allow_overlap = lmp->kokkos->allow_overlap;
if (pair_compute_flag) {
if (force->pair->execution_space==Host) {
execute_on_host = true;
datamask_read_host |= force->pair->datamask_read;
datamask_modify_device |= force->pair->datamask_modify;
} else {
datamask_read_device |= force->pair->datamask_read;
datamask_modify_device |= force->pair->datamask_modify;
}
}
if (atomKK->molecular && force->bond) {
if (force->bond->execution_space==Host) {
execute_on_host = true;
datamask_read_host |= force->bond->datamask_read;
datamask_modify_device |= force->bond->datamask_modify;
} else {
datamask_read_device |= force->bond->datamask_read;
datamask_modify_device |= force->bond->datamask_modify;
}
}
if (atomKK->molecular && force->angle) {
if (force->angle->execution_space==Host) {
execute_on_host = true;
datamask_read_host |= force->angle->datamask_read;
datamask_modify_device |= force->angle->datamask_modify;
} else {
datamask_read_device |= force->angle->datamask_read;
datamask_modify_device |= force->angle->datamask_modify;
}
}
if (atomKK->molecular && force->dihedral) {
if (force->dihedral->execution_space==Host) {
execute_on_host = true;
datamask_read_host |= force->dihedral->datamask_read;
datamask_modify_device |= force->dihedral->datamask_modify;
} else {
datamask_read_device |= force->dihedral->datamask_read;
datamask_modify_device |= force->dihedral->datamask_modify;
}
}
if (atomKK->molecular && force->improper) {
if (force->improper->execution_space==Host) {
execute_on_host = true;
datamask_read_host |= force->improper->datamask_read;
datamask_modify_device |= force->improper->datamask_modify;
} else {
datamask_read_device |= force->improper->datamask_read;
datamask_modify_device |= force->improper->datamask_modify;
}
}
if (kspace_compute_flag) {
if (force->kspace->execution_space==Host) {
execute_on_host = true;
datamask_read_host |= force->kspace->datamask_read;
datamask_modify_device |= force->kspace->datamask_modify;
} else {
datamask_read_device |= force->kspace->datamask_read;
datamask_modify_device |= force->kspace->datamask_modify;
}
}
if (allow_overlap) {
datamask_exclude = (F_MASK | ENERGY_MASK | VIRIAL_MASK);
if (pair_compute_flag) {
if (force->pair->execution_space == Host) {
execute_on_host = true;
datamask_read_host |= force->pair->datamask_read;
}
}
if (atomKK->molecular && force->bond) {
if (force->bond->execution_space == Host) {
execute_on_host = true;
datamask_read_host |= force->bond->datamask_read;
}
}
if (atomKK->molecular && force->angle) {
if (force->angle->execution_space == Host) {
execute_on_host = true;
datamask_read_host |= force->angle->datamask_read;
}
}
if (atomKK->molecular && force->dihedral) {
if (force->dihedral->execution_space == Host) {
execute_on_host = true;
datamask_read_host |= force->dihedral->datamask_read;
}
}
if (atomKK->molecular && force->improper) {
if (force->improper->execution_space == Host) {
execute_on_host = true;
datamask_read_host |= force->improper->datamask_read;
}
}
if (kspace_compute_flag) {
if (force->kspace->execution_space == Host) {
execute_on_host = true;
datamask_read_host |= force->kspace->datamask_read;
}
}
}
if (pair_compute_flag) {
atomKK->sync(force->pair->execution_space,force->pair->datamask_read);
atomKK->sync(force->pair->execution_space,~(~force->pair->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->sync(force->pair->execution_space,~(~force->pair->datamask_read|datamask_exclude));
force->pair->compute(eflag,vflag);
atomKK->modified(force->pair->execution_space,force->pair->datamask_modify);
atomKK->modified(force->pair->execution_space,~(~force->pair->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->modified(force->pair->execution_space,~(~force->pair->datamask_modify|datamask_exclude));
timer->stamp(Timer::PAIR);
}
if (execute_on_host) {
if (pair_compute_flag && force->pair->datamask_modify!=(F_MASK | ENERGY_MASK | VIRIAL_MASK))
Kokkos::fence();
atomKK->sync_overlapping_device(Host,~(~datamask_read_host|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
if (pair_compute_flag && force->pair->execution_space!=Host) {
Kokkos::deep_copy(LMPHostType(),atomKK->k_f.h_view,0.0);
}
if (execute_on_host) {
if (pair_compute_flag && force->pair->datamask_modify != datamask_exclude)
Kokkos::fence();
atomKK->sync_overlapping_device(Host,~(~datamask_read_host|datamask_exclude));
if (pair_compute_flag && force->pair->execution_space != Host) {
Kokkos::deep_copy(LMPHostType(),atomKK->k_f.h_view,0.0);
}
}
if (atomKK->molecular) {
if (force->bond) {
atomKK->sync(force->bond->execution_space,~(~force->bond->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->sync(force->bond->execution_space,~(~force->bond->datamask_read|datamask_exclude));
force->bond->compute(eflag,vflag);
atomKK->modified(force->bond->execution_space,~(~force->bond->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->modified(force->bond->execution_space,~(~force->bond->datamask_modify|datamask_exclude));
}
if (force->angle) {
atomKK->sync(force->angle->execution_space,~(~force->angle->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->sync(force->angle->execution_space,~(~force->angle->datamask_read|datamask_exclude));
force->angle->compute(eflag,vflag);
atomKK->modified(force->angle->execution_space,~(~force->angle->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->modified(force->angle->execution_space,~(~force->angle->datamask_modify|datamask_exclude));
}
if (force->dihedral) {
atomKK->sync(force->dihedral->execution_space,~(~force->dihedral->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->sync(force->dihedral->execution_space,~(~force->dihedral->datamask_read|datamask_exclude));
force->dihedral->compute(eflag,vflag);
atomKK->modified(force->dihedral->execution_space,~(~force->dihedral->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->modified(force->dihedral->execution_space,~(~force->dihedral->datamask_modify|datamask_exclude));
}
if (force->improper) {
atomKK->sync(force->improper->execution_space,~(~force->improper->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->sync(force->improper->execution_space,~(~force->improper->datamask_read|datamask_exclude));
force->improper->compute(eflag,vflag);
atomKK->modified(force->improper->execution_space,~(~force->improper->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->modified(force->improper->execution_space,~(~force->improper->datamask_modify|datamask_exclude));
}
timer->stamp(Timer::BOND);
}
if (kspace_compute_flag) {
atomKK->sync(force->kspace->execution_space,~(~force->kspace->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->sync(force->kspace->execution_space,~(~force->kspace->datamask_read|datamask_exclude));
force->kspace->compute(eflag,vflag);
atomKK->modified(force->kspace->execution_space,~(~force->kspace->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK)));
atomKK->modified(force->kspace->execution_space,~(~force->kspace->datamask_modify|datamask_exclude));
timer->stamp(Timer::KSPACE);
}
if (execute_on_host && atomKK->k_f.h_view.data() != atomKK->k_f.d_view.data()) {
if (f_merge_copy.extent(0)<atomKK->k_f.extent(0)) {
if (f_merge_copy.extent(0) < atomKK->k_f.extent(0)) {
f_merge_copy = DAT::t_f_array("VerletKokkos::f_merge_copy",atomKK->k_f.extent(0));
}
f = atomKK->k_f.d_view;