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>>
251 #define callRegisterKokkosResidualObjectFunction(classname, objectname) \ 252 static char registerKokkosResidualObject##classname() \ 254 using namespace Moose::Kokkos; \ 256 DispatcherRegistry::add<classname::ResidualLoop, classname>(objectname); \ 257 DispatcherRegistry::add<classname::JacobianLoop, classname>(objectname); \ 258 DispatcherRegistry::add<classname::OffDiagJacobianLoop, classname>(objectname); \ 259 DispatcherRegistry::hasUserMethod<classname::JacobianLoop>( \ 260 objectname, &classname::computeQpJacobian != classname::defaultJacobian()); \ 261 DispatcherRegistry::hasUserMethod<classname::OffDiagJacobianLoop>( \ 262 objectname, &classname::computeQpOffDiagJacobian != classname::defaultOffDiagJacobian()); \ 267 static char combineNames(kokkos_dispatcher_residual_object_##classname, __COUNTER__) = \ 268 registerKokkosResidualObject##classname() 270 #define registerKokkosResidualObject(app, classname) \ 271 registerMooseObject(app, classname); \ 272 callRegisterKokkosResidualObjectFunction(classname, #classname) 274 #define registerKokkosResidualObjectAliased(app, classname, alias) \ 275 registerMooseObjectAliased(app, classname, alias); \ 276 callRegisterKokkosResidualObjectFunction(classname, alias) 280 #define callRegisterKokkosMaterialFunction(classname, objectname) \ 281 static char registerKokkosMaterial##classname() \ 283 using namespace Moose::Kokkos; \ 285 DispatcherRegistry::add<classname::ElementInit, classname>(objectname); \ 286 DispatcherRegistry::add<classname::SideInit, classname>(objectname); \ 287 DispatcherRegistry::add<classname::NeighborInit, classname>(objectname); \ 288 DispatcherRegistry::add<classname::ElementCompute, classname>(objectname); \ 289 DispatcherRegistry::add<classname::SideCompute, classname>(objectname); \ 290 DispatcherRegistry::add<classname::NeighborCompute, classname>(objectname); \ 291 DispatcherRegistry::hasUserMethod<classname::ElementInit>( \ 292 objectname, &classname::initQpStatefulProperties != classname::defaultInitStateful()); \ 293 DispatcherRegistry::hasUserMethod<classname::SideInit>( \ 294 objectname, &classname::initQpStatefulProperties != classname::defaultInitStateful()); \ 295 DispatcherRegistry::hasUserMethod<classname::NeighborInit>( \ 296 objectname, &classname::initQpStatefulProperties != classname::defaultInitStateful()); \ 301 static char combineNames(kokkos_dispatcher_material_##classname, __COUNTER__) = \ 302 registerKokkosMaterial##classname() 304 #define registerKokkosMaterial(app, classname) \ 305 registerMooseObject(app, classname); \ 306 callRegisterKokkosMaterialFunction(classname, #classname) 308 #define registerKokkosMaterialAliased(app, classname, alias) \ 309 registerMooseObjectAliased(app, classname, alias); \ 310 callRegisterKokkosMaterialFunction(classname, alias) 314 #define callRegisterKokkosAuxKernelFunction(classname, objectname) \ 315 static char registerKokkosAuxKernel##classname() \ 317 using namespace Moose::Kokkos; \ 319 DispatcherRegistry::add<classname::ElementLoop, classname>(objectname); \ 320 DispatcherRegistry::add<classname::NodeLoop, classname>(objectname); \ 325 static char combineNames(kokkos_dispatcher_auxkernel_##classname, __COUNTER__) = \ 326 registerKokkosAuxKernel##classname() 328 #define registerKokkosAuxKernel(app, classname) \ 329 registerMooseObject(app, classname); \ 330 callRegisterKokkosAuxKernelFunction(classname, #classname) 332 #define registerKokkosAuxKernelAliased(app, classname, alias) \ 333 registerMooseObjectAliased(app, classname, alias); \ 334 callRegisterKokkosAuxKernelFunction(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()