From 9e35e76b8ce9665e5f870b0c2fe0e424e489b168 Mon Sep 17 00:00:00 2001 From: smoore Date: Sat, 13 Jan 2018 21:32:59 -0700 Subject: [PATCH] Fix issues in Kokkos npair_halffull and npair_skip --- src/KOKKOS/npair_halffull_kokkos.cpp | 5 +++- src/KOKKOS/npair_halffull_kokkos.h | 2 -- src/KOKKOS/npair_skip_kokkos.cpp | 44 ++++++++++++++++------------ src/KOKKOS/npair_skip_kokkos.h | 6 ++-- src/npair.cpp | 4 +++ src/npair.h | 3 ++ 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/KOKKOS/npair_halffull_kokkos.cpp b/src/KOKKOS/npair_halffull_kokkos.cpp index 67952fcd62..67481985da 100644 --- a/src/KOKKOS/npair_halffull_kokkos.cpp +++ b/src/KOKKOS/npair_halffull_kokkos.cpp @@ -59,18 +59,21 @@ void NPairHalffullKokkos::build(NeighList *list) NeighListKokkos* k_list = static_cast*>(list); k_list->maxneighs = k_list_full->maxneighs; // simple, but could be made more memory efficient - k_list->grow(inum_full); + k_list->grow(atom->nmax); d_ilist = k_list->d_ilist; d_numneigh = k_list->d_numneigh; d_neighbors = k_list->d_neighbors; // loop over parent full list + copymode = 1; Kokkos::parallel_for(Kokkos::RangePolicy(0,inum_full),*this); list->inum = k_list_full->inum; list->gnum = k_list_full->gnum; k_list->k_ilist.template modify(); + + copymode = 0; } template diff --git a/src/KOKKOS/npair_halffull_kokkos.h b/src/KOKKOS/npair_halffull_kokkos.h index f52eff503e..15505a376c 100644 --- a/src/KOKKOS/npair_halffull_kokkos.h +++ b/src/KOKKOS/npair_halffull_kokkos.h @@ -156,8 +156,6 @@ class NPairHalffullKokkos : public NPair { typename AT::t_neighbors_2d d_neighbors; typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - - ExecutionSpace execution_space; }; } diff --git a/src/KOKKOS/npair_skip_kokkos.cpp b/src/KOKKOS/npair_skip_kokkos.cpp index 1bd4b641d9..db330f23e6 100644 --- a/src/KOKKOS/npair_skip_kokkos.cpp +++ b/src/KOKKOS/npair_skip_kokkos.cpp @@ -54,12 +54,12 @@ void NPairSkipKokkos::build(NeighList *list) d_numneigh_skip = k_list_skip->d_numneigh; d_neighbors_skip = k_list_skip->d_neighbors; - int num_skip = list->listskip->inum; + num_skip = list->listskip->inum; if (list->ghost) num_skip += list->listskip->gnum; NeighListKokkos* k_list = static_cast*>(list); k_list->maxneighs = k_list_skip->maxneighs; // simple, but could be made more memory efficient - k_list->grow(num_skip); + k_list->grow(atom->nmax); d_ilist = k_list->d_ilist; d_numneigh = k_list->d_numneigh; d_neighbors = k_list->d_neighbors; @@ -83,13 +83,12 @@ void NPairSkipKokkos::build(NeighList *list) k_iskip.sync(); k_ijskip.sync(); - Kokkos::deep_copy(d_inum,0); - // loop over atoms in other list // skip I atom entirely if iskip is set for type[I] // skip I,J pair if ijskip is set for type[I],type[J] - Kokkos::parallel_for(Kokkos::RangePolicy(0,num_skip),*this); + copymode = 1; + Kokkos::parallel_scan(Kokkos::RangePolicy(0,num_skip),*this); auto h_inum = Kokkos::create_mirror_view(d_inum); Kokkos::deep_copy(h_inum,d_inum); @@ -101,34 +100,41 @@ void NPairSkipKokkos::build(NeighList *list) list->inum = num; list->gnum = inum - num; } + copymode = 0; } template KOKKOS_INLINE_FUNCTION -void NPairSkipKokkos::operator()(TagNPairSkipCompute, const int &ii) const { +void NPairSkipKokkos::operator()(TagNPairSkipCompute, const int &ii, int &inum, const bool &final) const { const int i = d_ilist_skip(ii); const int itype = type(i); if (d_iskip(itype)) return; - int n = 0; + if (final) { - // loop over parent non-skip list + int n = 0; - const int jnum = d_numneigh_skip(i); - const AtomNeighbors neighbors_i = AtomNeighbors(&d_neighbors(i,0),d_numneigh(i), - &d_neighbors(i,1)-&d_neighbors(i,0)); + // loop over parent non-skip list - for (int jj = 0; jj < jnum; jj++) { - const int joriginal = d_neighbors_skip(i,jj); - int j = joriginal & NEIGHMASK; - if (d_ijskip(itype,type(j))) continue; - neighbors_i(n++) = joriginal; + const int jnum = d_numneigh_skip(i); + const AtomNeighbors neighbors_i = AtomNeighbors(&d_neighbors(i,0),d_numneigh(i), + &d_neighbors(i,1)-&d_neighbors(i,0)); + + for (int jj = 0; jj < jnum; jj++) { + const int joriginal = d_neighbors_skip(i,jj); + int j = joriginal & NEIGHMASK; + if (d_ijskip(itype,type(j))) continue; + neighbors_i(n++) = joriginal; + } + + d_numneigh(i) = n; + d_ilist(inum) = i; + if (ii == num_skip-1) + d_inum() = inum+1; } - d_numneigh(i) = n; - const int inum = Kokkos::atomic_fetch_add(&d_inum(),1); - d_ilist(inum) = i; + inum++; } template diff --git a/src/KOKKOS/npair_skip_kokkos.h b/src/KOKKOS/npair_skip_kokkos.h index 96840bf04d..a274c1738c 100644 --- a/src/KOKKOS/npair_skip_kokkos.h +++ b/src/KOKKOS/npair_skip_kokkos.h @@ -66,13 +66,13 @@ class NPairSkipKokkos : public NPair { void build(class NeighList *); KOKKOS_INLINE_FUNCTION - void operator()(TagNPairSkipCompute, const int&) const; + void operator()(TagNPairSkipCompute, const int&, int&, const bool&) const; KOKKOS_INLINE_FUNCTION void operator()(TagNPairSkipCountLocal, const int&, int&) const; private: - int nlocal; + int nlocal,num_skip; typename AT::t_int_1d_randomread type; @@ -90,8 +90,6 @@ class NPairSkipKokkos : public NPair { DAT::tdual_int_2d k_ijskip; typename AT::t_int_1d d_iskip; typename AT::t_int_2d d_ijskip; - - ExecutionSpace execution_space; }; } diff --git a/src/npair.cpp b/src/npair.cpp index dd3a73926e..4d06850e65 100644 --- a/src/npair.cpp +++ b/src/npair.cpp @@ -32,12 +32,16 @@ NPair::NPair(LAMMPS *lmp) last_build = -1; mycutneighsq = NULL; molecular = atom->molecular; + copymode = 0; + execution_space = Host; } /* ---------------------------------------------------------------------- */ NPair::~NPair() { + if (copymode) return; + memory->destroy(mycutneighsq); } diff --git a/src/npair.h b/src/npair.h index 289a1348d9..186f921a00 100644 --- a/src/npair.h +++ b/src/npair.h @@ -134,6 +134,9 @@ class NPair : protected Pointers { } return 0; }; + + int copymode; + ExecutionSpace execution_space; }; }