Commit 54f24930 authored by Stan Moore's avatar Stan Moore
Browse files

Added ReductionView to Kokkos ReaxFF

parent f2dc764d
Loading
Loading
Loading
Loading
+33 −41
Original line number Diff line number Diff line
@@ -254,12 +254,18 @@ 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_reduction_view<> (k_o.d_view); // allocate duplicated memory

  // 1st cg solve over b_s, s
  cg_solve1();

  // 2nd cg solve over b_t, t
  cg_solve2();

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

  // calculate_Q();
  calculate_q();

@@ -494,13 +500,9 @@ void FixQEqReaxKokkos<DeviceType>::cg_solve1()
  Kokkos::parallel_for(inum,sparse12_functor);
  if (neighflag != FULL) {
    Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType,TagZeroQGhosts>(nlocal,nlocal+atom->nghost),*this);
    if (neighflag == HALF) {
      FixQEqReaxKokkosSparse13Functor<DeviceType,HALF> sparse13_functor(this);
      Kokkos::parallel_for(inum,sparse13_functor);
    } else {
    FixQEqReaxKokkosSparse13Functor<DeviceType,HALFTHREAD> sparse13_functor(this);
    Kokkos::parallel_for(inum,sparse13_functor);
    }
    Kokkos::Experimental::contribute(k_o.d_view, red_o);
  } else {
    Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec1> (inum, teamsize), *this);
  }
@@ -548,18 +550,14 @@ 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);
      if (neighflag == HALF) {
        FixQEqReaxKokkosSparse23Functor<DeviceType,HALF> sparse23_functor(this);
        Kokkos::parallel_for(inum,sparse23_functor);
      } else {
      red_o.reset_except(d_o);
      FixQEqReaxKokkosSparse23Functor<DeviceType,HALFTHREAD> sparse23_functor(this);
      Kokkos::parallel_for(inum,sparse23_functor);
      }
      Kokkos::Experimental::contribute(k_o.d_view, red_o);
    } else {
      Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec2> (inum, teamsize), *this);
    }


    if (neighflag != FULL) {
      k_o.template modify<DeviceType>();
      k_o.template sync<LMPHostType>();
@@ -625,13 +623,10 @@ 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);
    if (neighflag == HALF) {
      FixQEqReaxKokkosSparse33Functor<DeviceType,HALF> sparse33_functor(this);
      Kokkos::parallel_for(inum,sparse33_functor);
    } else {
    red_o.reset_except(d_o);
    FixQEqReaxKokkosSparse33Functor<DeviceType,HALFTHREAD> sparse33_functor(this);
    Kokkos::parallel_for(inum,sparse33_functor);
    }
    Kokkos::Experimental::contribute(k_o.d_view, red_o);
  } else {
    Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec3> (inum, teamsize), *this);
  }
@@ -679,13 +674,10 @@ 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);
      if (neighflag == HALF) {
        FixQEqReaxKokkosSparse23Functor<DeviceType,HALF> sparse23_functor(this);
        Kokkos::parallel_for(inum,sparse23_functor);
      } else {
      red_o.reset_except(d_o);
      FixQEqReaxKokkosSparse23Functor<DeviceType,HALFTHREAD> sparse23_functor(this);
      Kokkos::parallel_for(inum,sparse23_functor);
      }
      Kokkos::Experimental::contribute(k_o.d_view, red_o);
    } else {
      Kokkos::parallel_for(Kokkos::TeamPolicy <DeviceType, TagSparseMatvec2> (inum, teamsize), *this);
    }
@@ -797,8 +789,8 @@ template<int NEIGHFLAG>
KOKKOS_INLINE_FUNCTION
void FixQEqReaxKokkos<DeviceType>::sparse13_item(int ii) const
{
  // The q array is atomic for Half/Thread neighbor style
  Kokkos::View<F_FLOAT*, typename DAT::t_float_1d::array_layout,DeviceType,Kokkos::MemoryTraits<AtomicF<NEIGHFLAG>::value> > a_o = d_o;
  // The q array is duplicated for OpenMP, atomic for CUDA, and neither for Serial
  auto a_o = red_o.access();

  const int i = d_ilist[ii];
  if (mask[i] & groupbit) {
@@ -806,9 +798,9 @@ void FixQEqReaxKokkos<DeviceType>::sparse13_item(int ii) const
    for(int jj = d_firstnbr[i]; jj < d_firstnbr[i] + d_numnbrs[i]; jj++) {
      const int j = d_jlist(jj);
      tmp += d_val(jj) * d_s[j];
      a_o[j] += d_val(jj) * d_s[i];
      a_o(j) += d_val(jj) * d_s[i];
    }
    a_o[i] += tmp;
    a_o(i) += tmp;
  }
}

@@ -849,8 +841,8 @@ template<int NEIGHFLAG>
KOKKOS_INLINE_FUNCTION
void FixQEqReaxKokkos<DeviceType>::sparse23_item(int ii) const
{
  // The q array is atomic for Half/Thread neighbor style
  Kokkos::View<F_FLOAT*, typename DAT::t_float_1d::array_layout,DeviceType,Kokkos::MemoryTraits<AtomicF<NEIGHFLAG>::value> > a_o = d_o;
  // The q array is duplicated for OpenMP, atomic for CUDA, and neither for Serial
  auto a_o = red_o.access();

  const int i = d_ilist[ii];
  if (mask[i] & groupbit) {
@@ -858,9 +850,9 @@ void FixQEqReaxKokkos<DeviceType>::sparse23_item(int ii) const
    for(int jj = d_firstnbr[i]; jj < d_firstnbr[i] + d_numnbrs[i]; jj++) {
      const int j = d_jlist(jj);
      tmp += d_val(jj) * d_d[j];
      a_o[j] += d_val(jj) * d_d[i];
      a_o(j) += d_val(jj) * d_d[i];
    }
    a_o[i] += tmp;
    a_o(i) += tmp;
  }
}

@@ -908,8 +900,8 @@ template<int NEIGHFLAG>
KOKKOS_INLINE_FUNCTION
void FixQEqReaxKokkos<DeviceType>::sparse33_item(int ii) const
{
  // The q array is atomic for Half/Thread neighbor style
  Kokkos::View<F_FLOAT*, typename DAT::t_float_1d::array_layout,DeviceType,Kokkos::MemoryTraits<AtomicF<NEIGHFLAG>::value> > a_o = d_o;
  // The q array is duplicated for OpenMP, atomic for CUDA, and neither for Serial
  auto a_o = red_o.access();

  const int i = d_ilist[ii];
  if (mask[i] & groupbit) {
@@ -917,9 +909,9 @@ void FixQEqReaxKokkos<DeviceType>::sparse33_item(int ii) const
    for(int jj = d_firstnbr[i]; jj < d_firstnbr[i] + d_numnbrs[i]; jj++) {
      const int j = d_jlist(jj);
      tmp += d_val(jj) * d_t[j];
      a_o[j] += d_val(jj) * d_t[i];
      a_o(j) += d_val(jj) * d_t[i];
    }
    a_o[i] += tmp;
    a_o(i) += tmp;
  }
}

+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ FixStyle(qeq/reax/kk/host,FixQEqReaxKokkos<LMPHostType>)
#ifndef LMP_FIX_QEQ_REAX_KOKKOS_H
#define LMP_FIX_QEQ_REAX_KOKKOS_H

#include <Kokkos_ReductionView.hpp>
#include "fix_qeq_reax.h"
#include "kokkos_type.h"
#include "neigh_list.h"
@@ -192,6 +193,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::ReductionView<F_FLOAT*, typename AT::t_ffloat_1d::array_layout, DeviceType> red_o;

  void init_shielding_k();
  void init_hist();
  void allocate_matrix();
+14 −1
Original line number Diff line number Diff line
@@ -19,9 +19,10 @@
#define LMP_PAIR_KOKKOS_H

#include "Kokkos_Macros.hpp"
#include "Kokkos_Vectorization.hpp"
#include "Kokkos_ReductionView.hpp"
#include "pair.h"
#include "neigh_list_kokkos.h"
#include "Kokkos_Vectorization.hpp"

namespace LAMMPS_NS {

@@ -58,6 +59,18 @@ struct AtomicF<HALFTHREAD> {
  enum {value = Kokkos::Atomic|Kokkos::Unmanaged};
};

// Determine memory traits for force array
// Do atomic trait when running HALFTHREAD neighbor list style
template<int NEIGHFLAG>
struct AtomicDup {
  enum {value = Kokkos::Experimental::ReductionNonAtomic};
};

template<>
struct AtomicDup<HALFTHREAD> {
  enum {value = Kokkos::Experimental::ReductionAtomic};
};

//Specialisation for Neighborlist types Half, HalfThread, Full
template <class PairStyle, int NEIGHFLAG, bool STACKPARAMS, class Specialisation = void>
struct PairComputeFunctor  {
+138 −31

File changed.

Preview size limit exceeded, changes collapsed.

+11 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ PairStyle(reax/c/kk/host,PairReaxCKokkos<LMPHostType>)
#define LMP_PAIR_REAXC_KOKKOS_H

#include <stdio.h>
#include <Kokkos_ReductionView.hpp>
#include "pair_kokkos.h"
#include "pair_reaxc.h"
#include "neigh_list_kokkos.h"
@@ -411,6 +412,16 @@ class PairReaxCKokkos : public PairReaxC {
  typename AT::t_ffloat_2d_dl d_C1dbopi2, d_C2dbopi2, d_C3dbopi2, d_C4dbopi2;
  typename AT::t_ffloat_2d_dl d_Cdbo, d_Cdbopi, d_Cdbopi2, d_dDeltap_self;

  Kokkos::Experimental::ReductionView<F_FLOAT*, typename DAT::t_float_1d::array_layout,DeviceType> dup_total_bo;
  Kokkos::Experimental::ReductionView<F_FLOAT*, typename DAT::t_float_1d::array_layout,DeviceType> dup_CdDelta;
  Kokkos::Experimental::ReductionView<E_FLOAT*, typename DAT::t_efloat_1d::array_layout,DeviceType> dup_eatom;
  Kokkos::Experimental::ReductionView<F_FLOAT*[3], typename DAT::t_f_array::array_layout,DeviceType> dup_f;
  Kokkos::Experimental::ReductionView<F_FLOAT*[6], typename DAT::t_virial_array::array_layout,DeviceType> dup_vatom;
  Kokkos::Experimental::ReductionView<F_FLOAT**, typename DAT::t_ffloat_2d_dl::array_layout,DeviceType> dup_dDeltap_self;
  Kokkos::Experimental::ReductionView<F_FLOAT**, typename DAT::t_ffloat_2d_dl::array_layout,DeviceType> dup_Cdbo;
  Kokkos::Experimental::ReductionView<F_FLOAT**, typename DAT::t_ffloat_2d_dl::array_layout,DeviceType> dup_Cdbopi;
  Kokkos::Experimental::ReductionView<F_FLOAT**, typename DAT::t_ffloat_2d_dl::array_layout,DeviceType> dup_Cdbopi2;

  typedef Kokkos::DualView<F_FLOAT**[7],typename DeviceType::array_layout,DeviceType> tdual_ffloat_2d_n7;
  typedef typename tdual_ffloat_2d_n7::t_dev_const_randomread t_ffloat_2d_n7_randomread;
  typedef typename tdual_ffloat_2d_n7::t_host t_host_ffloat_2d_n7;