LCOV - code coverage report
Current view: top level - include/kokkos/userobjects - KokkosReducerBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 5 11 45.5 %
Date: 2026-05-29 20:35:17 Functions: 22 49 44.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14