20 using Policy = ::Kokkos::RangePolicy<ExecSpace, ::Kokkos::IndexType<ThreadID>>;
37 mooseError(
"parallelFor() called for an instance that is not a dispatcher.");
46 ::Kokkos::View<Real *, ::Kokkos::HostSpace> & )
48 mooseError(
"parallelReduce() called for an instance that is not a reducer.");
58 template <
typename Operation,
typename Object>
82 ::Kokkos::parallel_for(policy, *
this);
111 template <
typename Operation,
typename Object>
136 ::Kokkos::View<Real *, ::Kokkos::HostSpace> & result)
override final 140 ::Kokkos::parallel_reduce(policy, *
this, result);
196 virtual std::unique_ptr<DispatcherBase>
build(
const void *
object)
const = 0;
225 template <
typename Operation,
typename Object>
230 std::unique_ptr<DispatcherBase>
build(
const void *
object)
const override final 232 return std::make_unique<Dispatcher<Operation, Object>>(object);
236 template <
typename Operation,
typename Object>
240 std::unique_ptr<DispatcherBase>
build(
const void *
object)
const override final 242 return std::make_unique<Reducer<Operation, Object>>(object);
267 template <
typename Operation,
typename Object>
270 auto operation = std::type_index(
typeid(Operation));
273 std::make_unique<DispatcherRegistryEntry<Operation, Object>>();
282 template <
typename Operation,
typename Object>
285 auto operation = std::type_index(
typeid(Operation));
288 std::make_unique<ReducerRegistryEntry<Operation, Object>>();
297 template <
typename Operation>
309 template <
typename Operation>
322 template <
typename Operation>
323 static std::unique_ptr<DispatcherBase>
build(
const void *
object,
const std::string & name)
325 return getDispatcher<Operation>(
name)->
build(
object);
341 template <
typename Operation>
344 auto operation = std::type_index(
typeid(Operation));
348 mooseError(
"Kokkos functor dispatcher not registered for object type '",
350 "'. Double check that you used Kokkos-specific registration macro.");
359 std::map<std::pair<std::type_index, std::string>, std::unique_ptr<DispatcherRegistryEntryBase>>
367 #define callRegisterKokkosResidualObjectFunction(classname, objectname) \ 368 static char registerKokkosResidualObject##classname() \ 370 using namespace Moose::Kokkos; \ 372 DispatcherRegistry::addDispatcher<classname::ResidualLoop, classname>(objectname); \ 373 DispatcherRegistry::addDispatcher<classname::JacobianLoop, classname>(objectname); \ 374 DispatcherRegistry::addDispatcher<classname::OffDiagJacobianLoop, classname>(objectname); \ 375 DispatcherRegistry::hasUserMethod<classname::JacobianLoop>( \ 377 &classname::computeQpJacobian<classname> != classname::defaultJacobian<classname>()); \ 378 DispatcherRegistry::hasUserMethod<classname::OffDiagJacobianLoop>( \ 380 &classname::computeQpOffDiagJacobian<classname> != \ 381 classname::defaultOffDiagJacobian<classname>()); \ 386 static char combineNames(kokkos_dispatcher_residual_object_##classname, __COUNTER__) = \ 387 registerKokkosResidualObject##classname() 389 #define registerKokkosResidualObject(app, classname) \ 390 registerMooseObject(app, classname); \ 391 callRegisterKokkosResidualObjectFunction(classname, #classname) 393 #define registerKokkosResidualObjectAliased(app, classname, alias) \ 394 registerMooseObjectAliased(app, classname, alias); \ 395 callRegisterKokkosResidualObjectFunction(classname, alias) 399 #define callRegisterKokkosADResidualObjectFunction(classname, objectname) \ 400 static char registerKokkosADResidualObject##classname() \ 402 using namespace Moose::Kokkos; \ 404 DispatcherRegistry::addDispatcher<classname::ResidualLoop, classname>(objectname); \ 409 static char combineNames(kokkos_dispatcher_ad_residual_object_##classname, __COUNTER__) = \ 410 registerKokkosADResidualObject##classname() 412 #define registerKokkosADResidualObject(app, classname) \ 413 registerMooseObject(app, classname); \ 414 callRegisterKokkosADResidualObjectFunction(classname, #classname) 416 #define registerKokkosADResidualObjectAliased(app, classname, alias) \ 417 registerMooseObjectAliased(app, classname, alias); \ 418 callRegisterKokkosADResidualObjectFunction(classname, alias) 422 #define callRegisterKokkosMaterialFunction(classname, objectname) \ 423 static char registerKokkosMaterial##classname() \ 425 using namespace Moose::Kokkos; \ 427 DispatcherRegistry::addDispatcher<classname::ElementInit, classname>(objectname); \ 428 DispatcherRegistry::addDispatcher<classname::SideInit, classname>(objectname); \ 429 DispatcherRegistry::addDispatcher<classname::NeighborInit, classname>(objectname); \ 430 DispatcherRegistry::addDispatcher<classname::ElementCompute, classname>(objectname); \ 431 DispatcherRegistry::addDispatcher<classname::SideCompute, classname>(objectname); \ 432 DispatcherRegistry::addDispatcher<classname::NeighborCompute, classname>(objectname); \ 433 DispatcherRegistry::hasUserMethod<classname::ElementInit>( \ 435 &classname::initQpStatefulProperties<classname> != \ 436 classname::defaultInitStateful<classname>()); \ 437 DispatcherRegistry::hasUserMethod<classname::SideInit>( \ 439 &classname::initQpStatefulProperties<classname> != \ 440 classname::defaultInitStateful<classname>()); \ 441 DispatcherRegistry::hasUserMethod<classname::NeighborInit>( \ 443 &classname::initQpStatefulProperties<classname> != \ 444 classname::defaultInitStateful<classname>()); \ 449 static char combineNames(kokkos_dispatcher_material_##classname, __COUNTER__) = \ 450 registerKokkosMaterial##classname() 452 #define registerKokkosMaterial(app, classname) \ 453 registerMooseObject(app, classname); \ 454 callRegisterKokkosMaterialFunction(classname, #classname) 456 #define registerKokkosMaterialAliased(app, classname, alias) \ 457 registerMooseObjectAliased(app, classname, alias); \ 458 callRegisterKokkosMaterialFunction(classname, alias) 462 #define callRegisterKokkosAuxKernelFunction(classname, objectname) \ 463 static char registerKokkosAuxKernel##classname() \ 465 using namespace Moose::Kokkos; \ 467 DispatcherRegistry::addDispatcher<classname::ElementLoop, classname>(objectname); \ 468 DispatcherRegistry::addDispatcher<classname::NodeLoop, classname>(objectname); \ 473 static char combineNames(kokkos_dispatcher_auxkernel_##classname, __COUNTER__) = \ 474 registerKokkosAuxKernel##classname() 476 #define registerKokkosAuxKernel(app, classname) \ 477 registerMooseObject(app, classname); \ 478 callRegisterKokkosAuxKernelFunction(classname, #classname) 480 #define registerKokkosAuxKernelAliased(app, classname, alias) \ 481 registerMooseObjectAliased(app, classname, alias); \ 482 callRegisterKokkosAuxKernelFunction(classname, alias) 486 #define callRegisterKokkosUserObjectFunction(classname, objectname) \ 487 static char registerKokkosUserObject##classname() \ 489 using namespace Moose::Kokkos; \ 491 DispatcherRegistry::addDispatcher<classname::DefaultLoop, classname>(objectname); \ 492 DispatcherRegistry::addReducer<classname::ReducerLoop, classname>(objectname); \ 493 DispatcherRegistry::hasUserMethod<classname::DefaultLoop>( \ 494 objectname, &classname::execute<classname> != classname::defaultExecute<classname>()); \ 495 DispatcherRegistry::hasUserMethod<classname::ReducerLoop>( \ 496 objectname, &classname::reduce<classname> != classname::defaultReduce<classname>()); \ 501 static char combineNames(kokkos_dispatcher_userobject_##classname, __COUNTER__) = \ 502 registerKokkosUserObject##classname() 504 #define registerKokkosUserObject(app, classname) \ 505 registerMooseObject(app, classname); \ 506 callRegisterKokkosUserObjectFunction(classname, #classname) 508 #define registerKokkosUserObjectAliased(app, classname, alias) \ 509 registerMooseObjectAliased(app, classname, alias); \ 510 callRegisterKokkosUserObjectFunction(classname, alias) 514 #define registerKokkosAdditionalOperation(classname, operation) \ 515 static char registerKokkos##classname##operation() \ 517 using namespace Moose::Kokkos; \ 519 DispatcherRegistry::addDispatcher<classname::operation, classname>(#classname); \ 524 static char combineNames(kokkos_##classname##_##operation, __COUNTER__) = \ 525 registerKokkos##classname##operation() std::string name(const ElemQuality q)
KOKKOS_FUNCTION void join(value_type result, const value_type source) const
Functions required by the reducer concept of Kokkos.
std::unique_ptr< DispatcherBase > build(const void *object) const override final
Build a dispatcher for this operation and functor.
Class that dispatches a parallel loop 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...
Reducer(const void *object)
Constructor.
static void addDispatcher(const std::string &name)
Register a dispatcher of an operation of a functor.
std::unique_ptr< DispatcherBase > build(const void *object) const override final
Build a dispatcher for this operation and 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::View< Real * >::size_type size_type
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...
KOKKOS_FUNCTION void operator()(const ThreadID tid) const
The parallel computation entry function called by Kokkos::parallel_for.
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.
virtual void parallelFor(const Policy &)
Dispatch this functor with Kokkos parallel_for() given a Kokkos execution policy. ...
Class that stores the information of a dispatcher and builds it.
::Kokkos::RangePolicy< ExecSpace, ::Kokkos::IndexType< ThreadID > > Policy
Base class for dispatcher registry entry.
MOOSE_KOKKOS_INDEX_TYPE ThreadID
virtual ~DispatcherRegistryEntryBase()
virtual void parallelReduce(const Policy &, ::Kokkos::View< Real *, ::Kokkos::HostSpace > &)
Dispatch this functor with Kokkos parallel_reduce() given a Kokkos execution policy and result buffer...
static void addReducer(const std::string &name)
Register a reducer of an operation of a functor.
KOKKOS_FUNCTION void init(value_type result) const
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.
const Object _functor_device
Copy of the functor on device.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...
KOKKOS_FUNCTION void operator()(const ThreadID tid, value_type result) const
The parallel computation entry function called by Kokkos::parallel_reduce.
static void hasUserMethod(const std::string &name, const bool flag)
Set whether the user has overriden the hook method associated with an operation of a functor...
Class that registers dispatchers of all Kokkos functors.
Class that dispatches a parallel reduction operation of a Kokkos functor.
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.
const Object & _functor_host
Reference of the functor on host.
Reducer(const Reducer &functor)
Copy constructor for parallel dispatch.
Dispatcher(const Dispatcher &functor)
Copy constructor for parallel dispatch.
virtual ~DispatcherBase()