Line data Source code
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 : #include "KokkosFESystem.h" 16 : 17 : #include "MooseObject.h" 18 : 19 : class FEProblemBase; 20 : 21 : namespace Moose::Kokkos 22 : { 23 : 24 : class ReducerBase : public MeshHolder, public AssemblyHolder, public FESystemHolder 25 : { 26 : public: 27 : ReducerBase(const MooseObject * object); 28 : 29 : /** 30 : * Copy constructor for parallel dispatch 31 : */ 32 : ReducerBase(const ReducerBase & reducer); 33 : 34 : /** 35 : * Kokkos function tag 36 : */ 37 : struct ReducerLoop 38 : { 39 : }; 40 : 41 : /** 42 : * Default methods to prevent compile errors even when these methods were not defined in the 43 : * derived class 44 : */ 45 : ///@{ 46 : template <typename Derived> 47 0 : KOKKOS_FUNCTION void reduce(Datum & /* datum */, Real * /* result */) const 48 : { 49 0 : ::Kokkos::abort("Default reduce() should never be called. Make sure you properly redefined " 50 : "this method in your class without typos."); 51 : } 52 : template <typename Derived> 53 0 : KOKKOS_FUNCTION void join(Real * /* result */, const Real * /* source */) const 54 : { 55 0 : ::Kokkos::abort("Default join() should never be called. Make sure you properly redefined this " 56 : "method in your class without typos."); 57 : } 58 : template <typename Derived> 59 0 : KOKKOS_FUNCTION void init(Real * /* result */) const 60 : { 61 0 : ::Kokkos::abort("Default init() should never be called. Make sure you properly redefined this " 62 : "method in your class without typos."); 63 : } 64 : ///@} 65 : 66 : /** 67 : * Function used to check if users have overriden the hook method 68 : * @returns The function pointer of the default hook method 69 : */ 70 : template <typename Derived> 71 863133 : static auto defaultReduce() 72 : { 73 863133 : return &ReducerBase::reduce<Derived>; 74 : } 75 : ///@} 76 : 77 : protected: 78 : /** 79 : * Dispatch reduction operation 80 : */ 81 : virtual void computeReducer(); 82 : /** 83 : * Get the number of threads 84 : */ 85 : virtual ThreadID numReducerThreads() const = 0; 86 : /** 87 : * Allocate reduction buffer 88 : */ 89 2262 : void allocateReductionBuffer(const unsigned int size) 90 : { 91 2262 : ::Kokkos::realloc(_reduction_buffer, size); 92 2262 : } 93 : 94 : /** 95 : * MOOSE object 96 : */ 97 : const MooseObject * _reducer_object; 98 : /** 99 : * Kokkos functor dispatcher 100 : */ 101 : std::unique_ptr<DispatcherBase> _reducer_dispatcher; 102 : /** 103 : * Reduction buffer 104 : */ 105 : ::Kokkos::View<Real *, ::Kokkos::HostSpace> _reduction_buffer; 106 : }; 107 : 108 : } // namespace Moose::Kokkos