From b6f98244dcac749f8b46159b548cde577e225f3c Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Fri, 27 Jan 2023 11:28:17 -0700 Subject: [PATCH] Fix out of bounds access in pair_vashishta_kokkos with skip list --- src/KOKKOS/pair_sw_kokkos.cpp | 2 +- src/KOKKOS/pair_vashishta_kokkos.cpp | 61 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/KOKKOS/pair_sw_kokkos.cpp b/src/KOKKOS/pair_sw_kokkos.cpp index 679d022437..db7320623d 100644 --- a/src/KOKKOS/pair_sw_kokkos.cpp +++ b/src/KOKKOS/pair_sw_kokkos.cpp @@ -47,7 +47,6 @@ PairSWKokkos::PairSWKokkos(LAMMPS *lmp) : PairSW(lmp) { respa_enable = 0; - kokkosable = 1; atomKK = (AtomKokkos *) atom; execution_space = ExecutionSpaceFromDevice::space; @@ -138,6 +137,7 @@ void PairSWKokkos::compute(int eflag_in, int vflag_in) } if ((int)d_numneigh_short.extent(0) < ignum) d_numneigh_short = Kokkos::View("SW::numneighs_short",ignum*1.2); + Kokkos::parallel_for(Kokkos::RangePolicy(0,inum), *this); // loop over neighbor list of my atoms diff --git a/src/KOKKOS/pair_vashishta_kokkos.cpp b/src/KOKKOS/pair_vashishta_kokkos.cpp index aa8cb550c7..0bb2b49ece 100644 --- a/src/KOKKOS/pair_vashishta_kokkos.cpp +++ b/src/KOKKOS/pair_vashishta_kokkos.cpp @@ -117,24 +117,23 @@ void PairVashishtaKokkos::compute(int eflag_in, int vflag_in) EV_FLOAT ev; EV_FLOAT ev_all; + // build short neighbor list + int max_neighs = d_neighbors.extent(1); - if (((int)d_neighbors_short_2body.extent(1) != max_neighs) || - ((int)d_neighbors_short_2body.extent(0) != ignum)) { - d_neighbors_short_2body = Kokkos::View("Vashishta::neighbors_short_2body",ignum,max_neighs); - } - if ((int)d_numneigh_short_2body.extent(0)!=ignum) { - d_numneigh_short_2body = Kokkos::View("Vashishta::numneighs_short_2body",ignum); + if (((int)d_neighbors_short_2body.extent(1) < max_neighs) || + ((int)d_neighbors_short_2body.extent(0) < ignum)) { + d_neighbors_short_2body = Kokkos::View("Vashishta::neighbors_short_2body",ignum*1.2,max_neighs); } + if ((int)d_numneigh_short_2body.extent(0) < ignum) + d_numneigh_short_2body = Kokkos::View("Vashishta::numneighs_short_2body",ignum*1.2); - if (((int)d_neighbors_short_3body.extent(1) != max_neighs) || - ((int)d_neighbors_short_3body.extent(0) != ignum)) { - d_neighbors_short_3body = Kokkos::View("Vashishta::neighbors_short_3body",ignum,max_neighs); - } - - if ((int)d_numneigh_short_3body.extent(0)!=ignum) { - d_numneigh_short_3body = Kokkos::View("Vashishta::numneighs_short_3body",ignum); + if (((int)d_neighbors_short_3body.extent(1) < max_neighs) || + ((int)d_neighbors_short_3body.extent(0) < ignum)) { + d_neighbors_short_3body = Kokkos::View("Vashishta::neighbors_short_3body",ignum*1.2,max_neighs); } + if ((int)d_numneigh_short_3body.extent(0) < ignum) + d_numneigh_short_3body = Kokkos::View("Vashishta::numneighs_short_3body",ignum*1.2); Kokkos::parallel_for(Kokkos::RangePolicy(0,neighflag==FULL?ignum:inum), *this); @@ -217,17 +216,17 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeShortNei const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; if (rsq < d_params[ijparam].cutsq) { - d_neighbors_short_2body(i,inside_2body) = j; + d_neighbors_short_2body(ii,inside_2body) = j; inside_2body++; } if (rsq < d_params[ijparam].cutsq2) { - d_neighbors_short_3body(i,inside_3body) = j; + d_neighbors_short_3body(ii,inside_3body) = j; inside_3body++; } } - d_numneigh_short_2body(i) = inside_2body; - d_numneigh_short_3body(i) = inside_3body; + d_numneigh_short_2body(ii) = inside_2body; + d_numneigh_short_3body(ii) = inside_3body; } template @@ -252,14 +251,14 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullB= nlocal) continue; const int jtype = d_map[type[j]]; @@ -502,10 +501,10 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeFullB