diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index ebafb87466060dfc6a10fca33c23b580b754c184..7a725a021c7073228568d8fe1ef2d47b68d1bd33 100644 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -109,6 +109,8 @@ action neigh_list_kokkos.cpp action neigh_list_kokkos.h action neighbor_kokkos.cpp action neighbor_kokkos.h +action npair_copy_kokkos.cpp +action npair_copy_kokkos.h action npair_kokkos.cpp action npair_kokkos.h action nbin_kokkos.cpp diff --git a/src/KOKKOS/nbin_kokkos.cpp b/src/KOKKOS/nbin_kokkos.cpp index feec72f45acaaca8c42c44735aba6dda0f424b79..9a73e23b42ede4b3abf8a504d311ac7167d0f8f4 100644 --- a/src/KOKKOS/nbin_kokkos.cpp +++ b/src/KOKKOS/nbin_kokkos.cpp @@ -116,6 +116,7 @@ void NBinKokkos<DeviceType>::bin_atoms() k_bins = DAT::tdual_int_2d("bins", mbins, atoms_per_bin); bins = k_bins.view<DeviceType>(); c_bins = bins; + last_bin_memory = update->ntimestep; } } } diff --git a/src/KOKKOS/npair_copy_kokkos.cpp b/src/KOKKOS/npair_copy_kokkos.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6835d8c1b54ee37d5be17f7d60cfc1dda1370cbd --- /dev/null +++ b/src/KOKKOS/npair_copy_kokkos.cpp @@ -0,0 +1,62 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "npair_copy_kokkos.h" +#include "neighbor.h" +#include "neigh_list_kokkos.h" +#include "atom.h" +#include "atom_vec.h" +#include "molecule.h" +#include "domain.h" +#include "my_page.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +template<class DeviceType> +NPairCopyKokkos<DeviceType>::NPairCopyKokkos(LAMMPS *lmp) : NPair(lmp) {} + +/* ---------------------------------------------------------------------- + create list which is simply a copy of parent list +------------------------------------------------------------------------- */ + +template<class DeviceType> +void NPairCopyKokkos<DeviceType>::build(NeighList *list) +{ + NeighList *listcopy = list->listcopy; + + list->inum = listcopy->inum; + list->gnum = listcopy->gnum; + list->ilist = listcopy->ilist; + list->numneigh = listcopy->numneigh; + list->firstneigh = listcopy->firstneigh; + list->firstdouble = listcopy->firstdouble; + list->ipage = listcopy->ipage; + list->dpage = listcopy->dpage; + + NeighListKokkos<DeviceType>* list_kk = (NeighListKokkos<DeviceType>*) list; + NeighListKokkos<DeviceType>* listcopy_kk = (NeighListKokkos<DeviceType>*) list->listcopy; + + list_kk->d_ilist = listcopy_kk->d_ilist; + list_kk->d_numneigh = listcopy_kk->d_numneigh; + list_kk->d_neighbors = listcopy_kk->d_neighbors; +} + +namespace LAMMPS_NS { +template class NPairCopyKokkos<LMPDeviceType>; +#ifdef KOKKOS_HAVE_CUDA +template class NPairCopyKokkos<LMPHostType>; +#endif +} diff --git a/src/KOKKOS/npair_copy_kokkos.h b/src/KOKKOS/npair_copy_kokkos.h new file mode 100644 index 0000000000000000000000000000000000000000..84eb10b204122d03ff612209b39070fff3cb1a8e --- /dev/null +++ b/src/KOKKOS/npair_copy_kokkos.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef NPAIR_CLASS + +NPairStyle(copy/kk/device, + NPairCopyKokkos<LMPDeviceType>, + NP_COPY | NP_KOKKOS_DEVICE) + +NPairStyle(copy/kk/host, + NPairCopyKokkos<LMPHostType>, + NP_COPY | NP_KOKKOS_HOST) + +#else + +#ifndef LMP_NPAIR_COPY_KOKKOS_H +#define LMP_NPAIR_COPY_KOKKOS_H + +#include "npair.h" + +namespace LAMMPS_NS { + +template<class DeviceType> +class NPairCopyKokkos : public NPair { + public: + NPairCopyKokkos(class LAMMPS *); + ~NPairCopyKokkos() {} + void build(class NeighList *); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index f9873044520e00627d177bbe05ae1fe59c1bc3c4..fd32cd463e548045f826c10295310515b5f765db 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -51,9 +51,9 @@ void NPairKokkos<DeviceType,HALF_NEIGH,GHOST>::copy_neighbor_info() k_ex2_type = neighborKK->k_ex2_type; k_ex_type = neighborKK->k_ex_type; k_ex1_group = neighborKK->k_ex1_group; - k_ex2_group = neighborKK->k_ex1_group; - k_ex1_bit = neighborKK->k_ex1_group; - k_ex2_bit = neighborKK->k_ex1_group; + k_ex2_group = neighborKK->k_ex2_group; + k_ex1_bit = neighborKK->k_ex1_bit; + k_ex2_bit = neighborKK->k_ex2_bit; k_ex_mol_group = neighborKK->k_ex_mol_group; k_ex_mol_bit = neighborKK->k_ex_mol_bit; } @@ -135,16 +135,16 @@ void NPairKokkos<DeviceType,HALF_NEIGH,GHOST>::build(NeighList *list_) atomKK->molecular, nbinx,nbiny,nbinz,mbinx,mbiny,mbinz,mbinxlo,mbinylo,mbinzlo, bininvx,bininvy,bininvz, - exclude, nex_type,maxex_type, + exclude, nex_type, k_ex1_type.view<DeviceType>(), k_ex2_type.view<DeviceType>(), k_ex_type.view<DeviceType>(), - nex_group,maxex_group, + nex_group, k_ex1_group.view<DeviceType>(), k_ex2_group.view<DeviceType>(), k_ex1_bit.view<DeviceType>(), k_ex2_bit.view<DeviceType>(), - nex_mol, maxex_mol, + nex_mol, k_ex_mol_group.view<DeviceType>(), k_ex_mol_bit.view<DeviceType>(), bboxhi,bboxlo, @@ -161,6 +161,8 @@ void NPairKokkos<DeviceType,HALF_NEIGH,GHOST>::build(NeighList *list_) k_ex2_bit.sync<DeviceType>(); k_ex_mol_group.sync<DeviceType>(); k_ex_mol_bit.sync<DeviceType>(); + k_bincount.sync<DeviceType>(), + k_bins.sync<DeviceType>(), atomKK->sync(Device,X_MASK|TYPE_MASK|MASK_MASK|MOLECULE_MASK|TAG_MASK|SPECIAL_MASK); data.special_flag[0] = special_flag[0]; @@ -415,6 +417,7 @@ void NeighborKokkosExecute<DeviceType>:: if(n >= new_maxneighs()) new_maxneighs() = n; } + neigh_list.d_ilist(i) = i; } diff --git a/src/KOKKOS/npair_kokkos.h b/src/KOKKOS/npair_kokkos.h index 666508a22de083a5f76204c7a93ee962e4dcc51f..4b771751915d591f61245034d9fa8a90cf6f8d7a 100644 --- a/src/KOKKOS/npair_kokkos.h +++ b/src/KOKKOS/npair_kokkos.h @@ -75,14 +75,6 @@ class NPairKokkos : public NPair { private: int newton_pair; - int nex_type; - int maxex_type; - - int nex_group; - int maxex_group; - - int nex_mol; - int maxex_mol; // data from Neighbor class @@ -127,17 +119,14 @@ class NeighborKokkosExecute const int exclude; const int nex_type; - const int maxex_type; const typename AT::t_int_1d_const ex1_type,ex2_type; const typename AT::t_int_2d_const ex_type; const int nex_group; - const int maxex_group; const typename AT::t_int_1d_const ex1_group,ex2_group; const typename AT::t_int_1d_const ex1_bit,ex2_bit; const int nex_mol; - const int maxex_mol; const typename AT::t_int_1d_const ex_mol_group; const typename AT::t_int_1d_const ex_mol_bit; @@ -204,16 +193,16 @@ class NeighborKokkosExecute const int & _mbinx,const int & _mbiny,const int & _mbinz, const int & _mbinxlo,const int & _mbinylo,const int & _mbinzlo, const X_FLOAT &_bininvx,const X_FLOAT &_bininvy,const X_FLOAT &_bininvz, - const int & _exclude,const int & _nex_type,const int & _maxex_type, + const int & _exclude,const int & _nex_type, const typename AT::t_int_1d_const & _ex1_type, const typename AT::t_int_1d_const & _ex2_type, const typename AT::t_int_2d_const & _ex_type, - const int & _nex_group,const int & _maxex_group, + const int & _nex_group, const typename AT::t_int_1d_const & _ex1_group, const typename AT::t_int_1d_const & _ex2_group, const typename AT::t_int_1d_const & _ex1_bit, const typename AT::t_int_1d_const & _ex2_bit, - const int & _nex_mol,const int & _maxex_mol, + const int & _nex_mol, const typename AT::t_int_1d_const & _ex_mol_group, const typename AT::t_int_1d_const & _ex_mol_bit, const X_FLOAT *_bboxhi, const X_FLOAT* _bboxlo, @@ -229,11 +218,11 @@ class NeighborKokkosExecute mbinx(_mbinx),mbiny(_mbiny),mbinz(_mbinz), mbinxlo(_mbinxlo),mbinylo(_mbinylo),mbinzlo(_mbinzlo), bininvx(_bininvx),bininvy(_bininvy),bininvz(_bininvz), - exclude(_exclude),nex_type(_nex_type),maxex_type(_maxex_type), + exclude(_exclude),nex_type(_nex_type), ex1_type(_ex1_type),ex2_type(_ex2_type),ex_type(_ex_type), - nex_group(_nex_group),maxex_group(_maxex_group), + nex_group(_nex_group), ex1_group(_ex1_group),ex2_group(_ex2_group), - ex1_bit(_ex1_bit),ex2_bit(_ex2_bit),nex_mol(_nex_mol),maxex_mol(_maxex_mol), + ex1_bit(_ex1_bit),ex2_bit(_ex2_bit),nex_mol(_nex_mol), ex_mol_group(_ex_mol_group),ex_mol_bit(_ex_mol_bit), xperiodic(_xperiodic),yperiodic(_yperiodic),zperiodic(_zperiodic), xprd_half(_xprd_half),yprd_half(_yprd_half),zprd_half(_zprd_half) { diff --git a/src/neighbor.cpp b/src/neighbor.cpp index f27376cb2a2819b8e4d72a900a50df21c17ba5af..81f33e24791f684c9ebdc12f783f52ede7524263 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -660,10 +660,8 @@ void Neighbor::init_pair() // processes copy,skip,half_from_full,granhistory,respaouter lists // error checks and resets internal ptrs to other lists that now exist - for (i = 0; i < nrequest; i++) { - if (!lists[i]) continue; + for (i = 0; i < nrequest; i++) lists[i]->post_constructor(requests[i]); - } // (B) rule: // if request = pair, half, newton != 2 @@ -680,6 +678,10 @@ void Neighbor::init_pair() for (i = 0; i < nrequest; i++) { if (requests[i]->pair && requests[i]->half && requests[i]->newton != 2) { for (j = 0; j < nrequest; j++) { + // Kokkos doesn't yet support half from full + if (requests[i]->kokkos_device || requests[j]->kokkos_device) continue; + if (requests[i]->kokkos_host || requests[j]->kokkos_host) continue; + if (requests[j]->full && requests[j]->occasional == 0 && !requests[j]->skip && !requests[j]->copy) break; } @@ -706,6 +708,10 @@ void Neighbor::init_pair() for (i = 0; i < nrequest; i++) { if (!requests[i]->fix && !requests[i]->compute) continue; for (j = 0; j < nrequest; j++) { + // Kokkos flags must match + if (requests[i]->kokkos_device != requests[j]->kokkos_device) continue; + if (requests[i]->kokkos_host != requests[j]->kokkos_host) continue; + if (requests[i]->half && requests[j]->pair && !requests[j]->skip && requests[j]->half && !requests[j]->copy) break; @@ -727,6 +733,10 @@ void Neighbor::init_pair() continue; } for (j = 0; j < nrequest; j++) { + // Kokkos doesn't yet support half from full + if (requests[i]->kokkos_device || requests[j]->kokkos_device) continue; + if (requests[i]->kokkos_host || requests[j]->kokkos_host) continue; + if (requests[i]->half && requests[j]->pair && !requests[j]->skip && requests[j]->full && !requests[j]->copy) break; @@ -1434,7 +1444,11 @@ int Neighbor::choose_pair(NeighRequest *rq) for (int i = 0; i < npclass; i++) { mask = pairmasks[i]; - if (copyflag && (mask & NP_COPY)) return i+1; + if (copyflag && (mask & NP_COPY)) { + if (kokkos_device_flag != (mask & NP_KOKKOS_DEVICE)) continue; + if (kokkos_host_flag != (mask & NP_KOKKOS_HOST)) continue; + return i+1; + } if (skipflag != (mask & NP_SKIP)) continue; if (halfflag) {