Commit 6dd8efd0 authored by Stan Moore's avatar Stan Moore
Browse files

Add if statements

parent dbc308f3
Loading
Loading
Loading
Loading
+32 −14
Original line number Diff line number Diff line
@@ -249,8 +249,12 @@ void FixQEqReaxKokkos<DeviceType>::pre_force(int vflag)
  k_t.template modify<LMPHostType>();
  k_t.template sync<DeviceType>();

  if (neighflag != FULL)
    red_o = Kokkos::Experimental::create_scatter_view<> (d_o); // allocate duplicated memory
  need_dup = lmp->kokkos->need_dup<DeviceType>();

  if (need_dup)
    dup_o = Kokkos::Experimental::create_scatter_view<Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterDuplicated> (d_o); // allocate duplicated memory
  else
    ndup_o = Kokkos::Experimental::create_scatter_view<Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterNonDuplicated> (d_o);

  // 1st cg solve over b_s, s
  cg_solve1();
@@ -258,8 +262,8 @@ void FixQEqReaxKokkos<DeviceType>::pre_force(int vflag)
  // 2nd cg solve over b_t, t
  cg_solve2();

  if (neighflag != FULL)
    red_o = decltype(red_o)(); // free duplicated memory
  if (need_dup)
    dup_o = decltype(dup_o)(); // free duplicated memory

  // calculate_Q();
  calculate_q();
@@ -489,7 +493,9 @@ void FixQEqReaxKokkos<DeviceType>::cg_solve1()
    Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType,TagZeroQGhosts>(nlocal,nlocal+atom->nghost),*this);
    FixQEqReaxKokkosSparse13Functor<DeviceType,HALFTHREAD> sparse13_functor(this);
    Kokkos::parallel_for(inum,sparse13_functor);
    Kokkos::Experimental::contribute(d_o, red_o);
    if (need_dup)
        if (need_dup)
    Kokkos::Experimental::contribute(d_o, dup_o);
  } else {
    Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec1> (inum, teamsize), *this);
  }
@@ -537,10 +543,13 @@ void FixQEqReaxKokkos<DeviceType>::cg_solve1()
    Kokkos::parallel_for(inum,sparse22_functor);
    if (neighflag != FULL) {
      Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType,TagZeroQGhosts>(nlocal,nlocal+atom->nghost),*this);
      red_o.reset_except(d_o);
      if (need_dup)
        dup_o.reset_except(d_o);
      FixQEqReaxKokkosSparse23Functor<DeviceType,HALFTHREAD> sparse23_functor(this);
      Kokkos::parallel_for(inum,sparse23_functor);
      Kokkos::Experimental::contribute(d_o, red_o);
      if (need_dup)
          if (need_dup)
    Kokkos::Experimental::contribute(d_o, dup_o);
    } else {
      Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec2> (inum, teamsize), *this);
    }
@@ -610,10 +619,13 @@ void FixQEqReaxKokkos<DeviceType>::cg_solve2()
  Kokkos::parallel_for(inum,sparse32_functor);
  if (neighflag != FULL) {
    Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType,TagZeroQGhosts>(nlocal,nlocal+atom->nghost),*this);
    red_o.reset_except(d_o);
    if (need_dup)
      dup_o.reset_except(d_o);
    FixQEqReaxKokkosSparse33Functor<DeviceType,HALFTHREAD> sparse33_functor(this);
    Kokkos::parallel_for(inum,sparse33_functor);
    Kokkos::Experimental::contribute(d_o, red_o);
    if (need_dup)
        if (need_dup)
    Kokkos::Experimental::contribute(d_o, dup_o);
  } else {
    Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec3> (inum, teamsize), *this);
  }
@@ -661,10 +673,13 @@ void FixQEqReaxKokkos<DeviceType>::cg_solve2()
    Kokkos::parallel_for(inum,sparse22_functor);
    if (neighflag != FULL) {
      Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType,TagZeroQGhosts>(nlocal,nlocal+atom->nghost),*this);
      red_o.reset_except(d_o);
      if (need_dup)
        dup_o.reset_except(d_o);
      FixQEqReaxKokkosSparse23Functor<DeviceType,HALFTHREAD> sparse23_functor(this);
      Kokkos::parallel_for(inum,sparse23_functor);
      Kokkos::Experimental::contribute(d_o, red_o);
      if (need_dup)
          if (need_dup)
    Kokkos::Experimental::contribute(d_o, dup_o);
    } else {
      Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec2> (inum, teamsize), *this);
    }
@@ -777,7 +792,8 @@ KOKKOS_INLINE_FUNCTION
void FixQEqReaxKokkos<DeviceType>::sparse13_item(int ii) const
{
  // The q array is duplicated for OpenMP, atomic for CUDA, and neither for Serial
  auto a_o = red_o.template access<AtomicDup<NEIGHFLAG,DeviceType>::value>();
  auto v_o = ScatterViewHelper<NeedDup<NEIGHFLAG,DeviceType>::value,decltype(dup_o),decltype(ndup_o)>::get(dup_o,ndup_o);
  auto a_o = v_o.template access<AtomicDup<NEIGHFLAG,DeviceType>::value>();

  const int i = d_ilist[ii];
  if (mask[i] & groupbit) {
@@ -829,7 +845,8 @@ KOKKOS_INLINE_FUNCTION
void FixQEqReaxKokkos<DeviceType>::sparse23_item(int ii) const
{
  // The q array is duplicated for OpenMP, atomic for CUDA, and neither for Serial
  auto a_o = red_o.template access<AtomicDup<NEIGHFLAG,DeviceType>::value>();
  auto v_o = ScatterViewHelper<NeedDup<NEIGHFLAG,DeviceType>::value,decltype(dup_o),decltype(ndup_o)>::get(dup_o,ndup_o);
  auto a_o = v_o.template access<AtomicDup<NEIGHFLAG,DeviceType>::value>();

  const int i = d_ilist[ii];
  if (mask[i] & groupbit) {
@@ -888,7 +905,8 @@ KOKKOS_INLINE_FUNCTION
void FixQEqReaxKokkos<DeviceType>::sparse33_item(int ii) const
{
  // The q array is duplicated for OpenMP, atomic for CUDA, and neither for Serial
  auto a_o = red_o.template access<AtomicDup<NEIGHFLAG,DeviceType>::value>();
  auto v_o = ScatterViewHelper<NeedDup<NEIGHFLAG,DeviceType>::value,decltype(dup_o),decltype(ndup_o)>::get(dup_o,ndup_o);
  auto a_o = v_o.template access<AtomicDup<NEIGHFLAG,DeviceType>::value>();

  const int i = d_ilist[ii];
  if (mask[i] & groupbit) {
+3 −1
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ class FixQEqReaxKokkos : public FixQEqReax {
 private:
  int inum;
  int allocated_flag;
  int need_dup;

  typedef Kokkos::DualView<int***,DeviceType> tdual_int_1d;
  Kokkos::DualView<params_qeq*,Kokkos::LayoutRight,DeviceType> k_params;
@@ -193,7 +194,8 @@ class FixQEqReaxKokkos : public FixQEqReax {
  HAT::t_ffloat_2d h_s_hist, h_t_hist;
  typename AT::t_ffloat_2d_randomread r_s_hist, r_t_hist;

  Kokkos::Experimental::ScatterView<F_FLOAT*, typename AT::t_ffloat_1d::array_layout, DeviceType> red_o;
  Kokkos::Experimental::ScatterView<F_FLOAT*, typename AT::t_ffloat_1d::array_layout, DeviceType, Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterDuplicated> dup_o;
  Kokkos::Experimental::ScatterView<F_FLOAT*, typename AT::t_ffloat_1d::array_layout, DeviceType, Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterNonDuplicated> ndup_o;

  void init_shielding_k();
  void init_hist();
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include "pointers.h"
#include "kokkos_type.h"
#include "pair_kokkos.h"

namespace LAMMPS_NS {

@@ -39,6 +40,18 @@ class KokkosLMP : protected Pointers {
  ~KokkosLMP();
  void accelerator(int, char **);
  int neigh_count(int);

  template<class DeviceType>
  int need_dup()
  {
    int value = 0;
  
    if (neighflag == HALFTHREAD)
      value = NeedDup<HALFTHREAD,DeviceType>::value;
  
    return value;
  };

 private:
  static void my_signal_handler(int);
};
+25 −4
Original line number Diff line number Diff line
@@ -95,8 +95,8 @@ struct AtomicDup<HALFTHREAD,Kokkos::Threads> {

// Determine duplication traits for force array
// Use duplication when running threaded and not using atomics
template<class DeviceType>
struct DupF {
template<int NEIGHFLAG, class DeviceType>
struct NeedDup {
  enum {value = Kokkos::Experimental::ScatterNonDuplicated};
};

@@ -104,20 +104,41 @@ struct DupF {

#ifdef KOKKOS_ENABLE_OPENMP
template<>
struct DupF<Kokkos::OpenMP> {
struct NeedDup<HALFTHREAD,Kokkos::OpenMP> {
  enum {value = Kokkos::Experimental::ScatterDuplicated};
};
#endif

#ifdef KOKKOS_ENABLE_THREADS
template<>
struct DupF<Kokkos::Threads> {
struct NeedDup<HALFTHREAD,Kokkos::Threads> {
  enum {value = Kokkos::Experimental::ScatterDuplicated};
};
#endif

#endif

template<int value, typename T1, typename T2>
class ScatterViewHelper {};

template<typename T1, typename T2>
class ScatterViewHelper<Kokkos::Experimental::ScatterDuplicated,T1,T2> {
public:
  KOKKOS_INLINE_FUNCTION
  static T1 get(const T1 &dup, const T2 &nondup) {
    return dup;
  }
};

template<typename T1, typename T2>
class ScatterViewHelper<Kokkos::Experimental::ScatterNonDuplicated,T1,T2> {
public:
  KOKKOS_INLINE_FUNCTION
  static T2 get(const T1 &dup, const T2 &nondup) {
    return nondup;
  }
};


//Specialisation for Neighborlist types Half, HalfThread, Full
template <class PairStyle, int NEIGHFLAG, bool STACKPARAMS, class Specialisation = void>
+134 −78

File changed.

Preview size limit exceeded, changes collapsed.

Loading