22 using Policy = ::Kokkos::RangePolicy<ExecSpace, ::Kokkos::IndexType<ThreadID>>;
46 template <
typename Operation,
typename Object>
70 ::Kokkos::parallel_for(policy, *
this);
106 virtual std::unique_ptr<DispatcherBase>
build(
const void *
object)
const = 0;
135 template <
typename Operation,
typename Object>
139 std::unique_ptr<DispatcherBase>
build(
const void *
object)
const override final 141 return std::make_unique<Dispatcher<Operation, Object>>(object);
165 template <
typename Operation,
typename Object>
166 static void add(
const std::string & name)
168 auto operation = std::type_index(
typeid(Operation));
171 std::make_unique<DispatcherRegistryEntry<Operation, Object>>();
180 template <
typename Operation>
192 template <
typename Operation>
205 template <
typename Operation>
206 static std::unique_ptr<DispatcherBase>
build(
const void *
object,
const std::string & name)
208 return getDispatcher<Operation>(
name)->
build(
object);
224 template <
typename Operation>
227 auto operation = std::type_index(
typeid(Operation));
231 mooseError(
"Kokkos functor dispatcher not registered for object type '",
233 "'. Double check that you used Kokkos-specific registration macro.");
242 std::map<std::pair<std::type_index, std::string>, std::unique_ptr<DispatcherRegistryEntryBase>>
249 #define callRegisterKokkosResidualObjectFunction(classname, objectname) \ 250 static char registerKokkosResidualObject##classname() \ 252 using namespace Moose::Kokkos; \ 254 DispatcherRegistry::add<classname::ResidualLoop, classname>(objectname); \ 255 DispatcherRegistry::add<classname::JacobianLoop, classname>(objectname); \ 256 DispatcherRegistry::add<classname::OffDiagJacobianLoop, classname>(objectname); \ 257 DispatcherRegistry::hasUserMethod<classname::JacobianLoop>( \ 258 objectname, &classname::computeQpJacobian != classname::defaultJacobian()); \ 259 DispatcherRegistry::hasUserMethod<classname::OffDiagJacobianLoop>( \ 260 objectname, &classname::computeQpOffDiagJacobian != classname::defaultOffDiagJacobian()); \ 265 static char combineNames(kokkos_dispatcher_residual_object_##classname, __COUNTER__) = \ 266 registerKokkosResidualObject##classname() 268 #define registerKokkosResidualObject(app, classname) \ 269 registerMooseObject(app, classname); \ 270 callRegisterKokkosResidualObjectFunction(classname, #classname) 272 #define registerKokkosResidualObjectAliased(app, classname, alias) \ 273 registerMooseObjectAliased(app, classname, alias); \ 274 callRegisterKokkosResidualObjectFunction(classname, alias) 276 #define callRegisterKokkosMaterialFunction(classname, objectname) \ 277 static char registerKokkosMaterial##classname() \ 279 using namespace Moose::Kokkos; \ 281 DispatcherRegistry::add<classname::ElementInit, classname>(objectname); \ 282 DispatcherRegistry::add<classname::SideInit, classname>(objectname); \ 283 DispatcherRegistry::add<classname::NeighborInit, classname>(objectname); \ 284 DispatcherRegistry::add<classname::ElementCompute, classname>(objectname); \ 285 DispatcherRegistry::add<classname::SideCompute, classname>(objectname); \ 286 DispatcherRegistry::add<classname::NeighborCompute, classname>(objectname); \ 287 DispatcherRegistry::hasUserMethod<classname::ElementInit>( \ 288 objectname, &classname::initQpStatefulProperties != classname::defaultInitStateful()); \ 289 DispatcherRegistry::hasUserMethod<classname::SideInit>( \ 290 objectname, &classname::initQpStatefulProperties != classname::defaultInitStateful()); \ 291 DispatcherRegistry::hasUserMethod<classname::NeighborInit>( \ 292 objectname, &classname::initQpStatefulProperties != classname::defaultInitStateful()); \ 297 static char combineNames(kokkos_dispatcher_material_##classname, __COUNTER__) = \ 298 registerKokkosMaterial##classname() 300 #define registerKokkosMaterial(app, classname) \ 301 registerMooseObject(app, classname); \ 302 callRegisterKokkosMaterialFunction(classname, #classname) 304 #define registerKokkosMaterialAliased(app, classname, alias) \ 305 registerMooseObjectAliased(app, classname, alias); \ 306 callRegisterKokkosMaterialFunction(classname, alias) std::string name(const ElemQuality q)
std::unique_ptr< DispatcherBase > build(const void *object) const override final
Build a dispatcher for this operation and functor.
static void add(const std::string &name)
Register a dispatcher of an operation of a functor.
Class that dispatches an operation of a Kokkos functor.
static bool hasUserMethod(const std::string &name)
Get whether the user has overriden the hook method associated with an operation of a functor...
DispatcherRegistry & operator=(DispatcherRegistry const &)=delete
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
KOKKOS_FUNCTION void operator()(const ThreadID tid) const
The parallel computation entry function called by Kokkos.
const Object _functor_device
Copy of the functor on device.
static auto & getDispatcher(const std::string &name)
Get the dispatcher shell of an operation of a functor.
Class that stores the information of a dispatcher and builds it.
::Kokkos::RangePolicy< ExecSpace, ::Kokkos::IndexType< ThreadID > > Policy
Base class for dispatcher registry entry.
static void hasUserMethod(const std::string &name, bool flag)
Set whether the user has overriden the hook method associated with an operation of a functor...
virtual ~DispatcherRegistryEntryBase()
virtual void parallelFor(const Policy &policy)=0
Dispatch this functor with Kokkos parallel_for() given a Kokkos execution policy. ...
static std::unique_ptr< DispatcherBase > build(const void *object, const std::string &name)
Build and get a dispatcher of an operation of a functor.
bool _has_user_method
Flag whether the user has overriden the hook method associated with this operation.
bool hasUserMethod() const
Get whether the user has overriden the hook method associated with this operation.
void hasUserMethod(bool flag)
Set whether the user has overriden the hook method associated with this operation.
DispatcherRegistry()=default
Base class for Kokkos functor dispatcher.
const Object & _functor_host
Reference of the functor on host.
Dispatcher(const void *object)
Constructor.
void parallelFor(const Policy &policy) override final
Dispatch this functor with Kokkos parallel_for() given a Kokkos execution policy. ...
std::map< std::pair< std::type_index, std::string >, std::unique_ptr< DispatcherRegistryEntryBase > > _dispatchers
Map containing the dispatcher shells with the key being the pair of function tag type index and regis...
Class that registers dispatchers of all Kokkos functors.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
static DispatcherRegistry & getRegistry()
Get the registry singleton.
virtual std::unique_ptr< DispatcherBase > build(const void *object) const =0
Build a dispatcher for this operation and functor.
Dispatcher(const Dispatcher &functor)
Copy constructor for parallel dispatch.
virtual ~DispatcherBase()