https://mooseframework.inl.gov
KokkosReducerBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "KokkosHeader.h"
13 #include "KokkosDatum.h"
14 #include "KokkosDispatcher.h"
15 
16 #include "MooseObject.h"
17 
18 class FEProblemBase;
19 
20 namespace Moose::Kokkos
21 {
22 
23 class ReducerBase : public MeshHolder, public AssemblyHolder, public SystemHolder
24 {
25 public:
26  ReducerBase(const MooseObject * object);
27 
31  ReducerBase(const ReducerBase & reducer);
32 
36  struct ReducerLoop
37  {
38  };
39 
44  template <typename Derived>
46  KOKKOS_FUNCTION void reduce(Datum & /* datum */, Real * /* result */) const
47  {
48  ::Kokkos::abort("Default reduce() should never be called. Make sure you properly redefined "
49  "this method in your class without typos.");
50  }
51  template <typename Derived>
52  KOKKOS_FUNCTION void join(Real * /* result */, const Real * /* source */) const
53  {
54  ::Kokkos::abort("Default join() should never be called. Make sure you properly redefined this "
55  "method in your class without typos.");
56  }
57  template <typename Derived>
58  KOKKOS_FUNCTION void init(Real * /* result */) const
59  {
60  ::Kokkos::abort("Default init() should never be called. Make sure you properly redefined this "
61  "method in your class without typos.");
62  }
64 
69  template <typename Derived>
70  static auto defaultReduce()
71  {
72  return &ReducerBase::reduce<Derived>;
73  }
75 
76 protected:
80  virtual void computeReducer();
84  virtual ThreadID numReducerThreads() const = 0;
88  void allocateReductionBuffer(const unsigned int size)
89  {
90  ::Kokkos::realloc(_reduction_buffer, size);
91  }
92 
100  std::unique_ptr<DispatcherBase> _reducer_dispatcher;
104  ::Kokkos::View<Real *, ::Kokkos::HostSpace> _reduction_buffer;
105 };
106 
107 } // namespace Moose::Kokkos
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:23
ReducerBase(const MooseObject *object)
virtual ThreadID numReducerThreads() const =0
Get the number of threads.
KOKKOS_FUNCTION void join(Real *, const Real *) const
void allocateReductionBuffer(const unsigned int size)
Allocate reduction buffer.
The Kokkos interface that holds the host reference of the Kokkos systems and copies it to device duri...
Definition: KokkosSystem.h:753
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition: KokkosMesh.h:430
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
KOKKOS_FUNCTION void init(Real *) const
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
const MooseObject * _reducer_object
MOOSE object.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
The Kokkos interface that holds the host reference of the Kokkos assembly and copies it to device dur...
virtual void computeReducer()
Dispatch reduction operation.
KOKKOS_FUNCTION void reduce(Datum &, Real *) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
static auto defaultReduce()
Function used to check if users have overriden the hook method.
::Kokkos::View< Real *, ::Kokkos::HostSpace > _reduction_buffer
Reduction buffer.
std::unique_ptr< DispatcherBase > _reducer_dispatcher
Kokkos functor dispatcher.