https://mooseframework.inl.gov
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
Moose::Kokkos::Reducer< Operation, Object > Class Template Reference

Class that dispatches a parallel reduction operation of a Kokkos functor. More...

#include <KokkosDispatcher.h>

Inheritance diagram for Moose::Kokkos::Reducer< Operation, Object >:
[legend]

Public Types

using value_type = Real[]
 
using size_type = ::Kokkos::View< Real * >::size_type
 

Public Member Functions

 Reducer (const void *object)
 Constructor. More...
 
 Reducer (const Reducer &functor)
 Copy constructor for parallel dispatch. More...
 
void parallelReduce (const Policy &policy, ::Kokkos::View< Real *, ::Kokkos::HostSpace > &result) override final
 Dispatch this functor with Kokkos parallel_reduce() given a Kokkos execution policy and result buffer. More...
 
KOKKOS_FUNCTION void operator() (const ThreadID tid, value_type result) const
 The parallel computation entry function called by Kokkos::parallel_reduce. More...
 
virtual void parallelFor (const Policy &)
 Dispatch this functor with Kokkos parallel_for() given a Kokkos execution policy. More...
 
KOKKOS_FUNCTION void join (value_type result, const value_type source) const
 Functions required by the reducer concept of Kokkos. More...
 
KOKKOS_FUNCTION void init (value_type result) const
 

Public Attributes

size_type value_count
 

Private Attributes

const Object & _functor_host
 Reference of the functor on host. More...
 
const Object _functor_device
 Copy of the functor on device. More...
 

Detailed Description

template<typename Operation, typename Object>
class Moose::Kokkos::Reducer< Operation, Object >

Class that dispatches a parallel reduction operation of a Kokkos functor.

Calls operator() of the functor with a specified function tag.

Template Parameters
OperationThe function tag of operator() to be dispatched
ObjectThe functor class type

Definition at line 112 of file KokkosDispatcher.h.

Member Typedef Documentation

◆ size_type

template<typename Operation , typename Object >
using Moose::Kokkos::Reducer< Operation, Object >::size_type = ::Kokkos::View<Real *>::size_type

Definition at line 145 of file KokkosDispatcher.h.

◆ value_type

template<typename Operation , typename Object >
using Moose::Kokkos::Reducer< Operation, Object >::value_type = Real[]

Definition at line 144 of file KokkosDispatcher.h.

Constructor & Destructor Documentation

◆ Reducer() [1/2]

template<typename Operation , typename Object >
Moose::Kokkos::Reducer< Operation, Object >::Reducer ( const void object)
inline

Constructor.

Parameters
objectThe pointer to the functor. This reducer is constructed by the base class of functors, and the actual type of functors is unknown by the base class. Therefore, it is passed as a void pointer and cast to the actual type here.

Definition at line 121 of file KokkosDispatcher.h.

122  : _functor_host(*static_cast<const Object *>(object)), _functor_device(_functor_host)
123  {
124  }
const Object _functor_device
Copy of the functor on device.
const Object & _functor_host
Reference of the functor on host.

◆ Reducer() [2/2]

template<typename Operation , typename Object >
Moose::Kokkos::Reducer< Operation, Object >::Reducer ( const Reducer< Operation, Object > &  functor)
inline

Copy constructor for parallel dispatch.

Definition at line 128 of file KokkosDispatcher.h.

129  : value_count(functor.value_count),
130  _functor_host(functor._functor_host),
131  _functor_device(functor._functor_host)
132  {
133  }
const Object _functor_device
Copy of the functor on device.
const Object & _functor_host
Reference of the functor on host.

Member Function Documentation

◆ init()

template<typename Operation , typename Object >
KOKKOS_FUNCTION void Moose::Kokkos::Reducer< Operation, Object >::init ( value_type  result) const
inline

Definition at line 165 of file KokkosDispatcher.h.

166  {
167  _functor_device.template init<Object>(result);
168  }
const Object _functor_device
Copy of the functor on device.

◆ join()

template<typename Operation , typename Object >
KOKKOS_FUNCTION void Moose::Kokkos::Reducer< Operation, Object >::join ( value_type  result,
const value_type  source 
) const
inline

Functions required by the reducer concept of Kokkos.

Definition at line 161 of file KokkosDispatcher.h.

162  {
163  _functor_device.template join<Object>(result, source);
164  }
const Object _functor_device
Copy of the functor on device.

◆ operator()()

template<typename Operation , typename Object >
KOKKOS_FUNCTION void Moose::Kokkos::Reducer< Operation, Object >::operator() ( const ThreadID  tid,
value_type  result 
) const
inline

The parallel computation entry function called by Kokkos::parallel_reduce.

Definition at line 152 of file KokkosDispatcher.h.

153  {
154  _functor_device(Operation{}, tid, _functor_device, result);
155  }
const Object _functor_device
Copy of the functor on device.

◆ parallelFor()

virtual void Moose::Kokkos::DispatcherBase::parallelFor ( const Policy )
inlinevirtualinherited

Dispatch this functor with Kokkos parallel_for() given a Kokkos execution policy.

Parameters
policyThe Kokkos execution policy

Reimplemented in Moose::Kokkos::Dispatcher< Operation, Object >.

Definition at line 35 of file KokkosDispatcher.h.

36  {
37  mooseError("parallelFor() called for an instance that is not a dispatcher.");
38  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311

◆ parallelReduce()

template<typename Operation , typename Object >
void Moose::Kokkos::Reducer< Operation, Object >::parallelReduce ( const Policy ,
::Kokkos::View< Real *, ::Kokkos::HostSpace > &   
)
inlinefinaloverridevirtual

Dispatch this functor with Kokkos parallel_reduce() given a Kokkos execution policy and result buffer.

Parameters
policyThe Kokkos execution policy
resultThe result buffer

Reimplemented from Moose::Kokkos::DispatcherBase.

Definition at line 135 of file KokkosDispatcher.h.

137  {
138  value_count = result.size();
139 
140  ::Kokkos::parallel_reduce(policy, *this, result);
141  ::Kokkos::fence();
142  }

Member Data Documentation

◆ _functor_device

template<typename Operation , typename Object >
const Object Moose::Kokkos::Reducer< Operation, Object >::_functor_device
private

◆ _functor_host

template<typename Operation , typename Object >
const Object& Moose::Kokkos::Reducer< Operation, Object >::_functor_host
private

Reference of the functor on host.

Definition at line 175 of file KokkosDispatcher.h.

◆ value_count

template<typename Operation , typename Object >
size_type Moose::Kokkos::Reducer< Operation, Object >::value_count

The documentation for this class was generated from the following file: