https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Moose::Kokkos::FunctorWrapperHost< Object > Class Template Reference

Host functor wrapper class that allocates a functor on device and creates its device wrapper. More...

#include <KokkosFunctorWrapper.h>

Inheritance diagram for Moose::Kokkos::FunctorWrapperHost< Object >:
[legend]

Public Member Functions

 FunctorWrapperHost (const void *functor)
 Constructor.
 
 ~FunctorWrapperHost ()
 Desturctor.
 
FunctorWrapperDeviceBaseallocate () override final
 Allocate device functor and wrapper.
 
void copyFunctor () override final
 Copy functor to device.
 
void freeFunctor () override final
 Free host and device copies of functor.
 

Private Attributes

const Object & _functor_host
 Reference of the functor on host.
 
std::unique_ptr< Object > _functor_copy
 Copy of the functor on host.
 
Object * _functor_device = nullptr
 Copy of the functor on device.
 

Detailed Description

template<typename Object>
class Moose::Kokkos::FunctorWrapperHost< Object >

Host functor wrapper class that allocates a functor on device and creates its device wrapper.

This class holds the actual device instance of the functor and manages its allocation and deallocation, and the device wrapper simply keeps a pointer to it.

Template Parameters
ObjectThe functor class type

Definition at line 93 of file KokkosFunctorWrapper.h.

Constructor & Destructor Documentation

◆ FunctorWrapperHost()

template<typename Object >
Moose::Kokkos::FunctorWrapperHost< Object >::FunctorWrapperHost ( const void *  functor)
inline

Constructor.

Parameters
functorPointer to the functor

Definition at line 100 of file KokkosFunctorWrapper.h.

100: _functor_host(*static_cast<const Object *>(functor)) {}
const Object & _functor_host
Reference of the functor on host.

◆ ~FunctorWrapperHost()

template<typename Object >
Moose::Kokkos::FunctorWrapperHost< Object >::~FunctorWrapperHost ( )

Desturctor.

Definition at line 168 of file KokkosFunctorWrapper.h.

169{
170 ::Kokkos::kokkos_free<ExecSpace::memory_space>(_functor_device);
171}
Object * _functor_device
Copy of the functor on device.

Member Function Documentation

◆ allocate()

template<typename Object >
FunctorWrapperDeviceBase * Moose::Kokkos::FunctorWrapperHost< Object >::allocate ( )
finaloverridevirtual

Allocate device functor and wrapper.

Returns
The pointer to the device wrapper

Implements Moose::Kokkos::FunctorWrapperHostBase.

Definition at line 127 of file KokkosFunctorWrapper.h.

128{
129 // Allocate storage for device wrapper on device
130 auto wrapper_device = static_cast<FunctorWrapperDevice<Object> *>(
131 ::Kokkos::kokkos_malloc<ExecSpace::memory_space>(sizeof(FunctorWrapperDevice<Object>)));
132
133 // Allocate device wrapper on device using placement new to populate vtable with device pointers
134 ::Kokkos::parallel_for(
135 1, KOKKOS_LAMBDA(const int) { new (wrapper_device) FunctorWrapperDevice<Object>(); });
136
137 // Allocate storage for functor on device
139 static_cast<Object *>(::Kokkos::kokkos_malloc<ExecSpace::memory_space>(sizeof(Object)));
140
141 // Let device wrapper point to the copy
142 ::Kokkos::Impl::DeepCopy<MemSpace, ::Kokkos::HostSpace>(
143 &(wrapper_device->_functor), &_functor_device, sizeof(Object *));
144
145 return wrapper_device;
146}

◆ copyFunctor()

template<typename Object >
void Moose::Kokkos::FunctorWrapperHost< Object >::copyFunctor ( )
finaloverridevirtual

Copy functor to device.

Implements Moose::Kokkos::FunctorWrapperHostBase.

Definition at line 150 of file KokkosFunctorWrapper.h.

151{
152 // Make a copy of functor on host to trigger copy constructor
153 _functor_copy = std::make_unique<Object>(_functor_host);
154
155 // Copy functor to device
156 ::Kokkos::Impl::DeepCopy<MemSpace, ::Kokkos::HostSpace>(
157 _functor_device, _functor_copy.get(), sizeof(Object));
158}
std::unique_ptr< Object > _functor_copy
Copy of the functor on host.

◆ freeFunctor()

template<typename Object >
void Moose::Kokkos::FunctorWrapperHost< Object >::freeFunctor ( )
finaloverridevirtual

Free host and device copies of functor.

Implements Moose::Kokkos::FunctorWrapperHostBase.

Definition at line 162 of file KokkosFunctorWrapper.h.

163{
164 _functor_copy.reset();
165}

Member Data Documentation

◆ _functor_copy

template<typename Object >
std::unique_ptr<Object> Moose::Kokkos::FunctorWrapperHost< Object >::_functor_copy
private

◆ _functor_device

template<typename Object >
Object* Moose::Kokkos::FunctorWrapperHost< Object >::_functor_device = nullptr
private

◆ _functor_host

template<typename Object >
const Object& Moose::Kokkos::FunctorWrapperHost< Object >::_functor_host
private

Reference of the functor on host.

Definition at line 114 of file KokkosFunctorWrapper.h.

Referenced by Moose::Kokkos::FunctorWrapperHost< Object >::copyFunctor().


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