https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Moose::Kokkos::DualReferenceWrapper< H, D > Class Template Reference

The Kokkos object that can hold a host reference and a device-compatible copy of a variable. More...

#include <KokkosReferenceWrapper.h>

Inheritance diagram for Moose::Kokkos::DualReferenceWrapper< H, D >:
[legend]

Public Member Functions

 DualReferenceWrapper (H &reference)
 Constructor.
 
 DualReferenceWrapper (const DualReferenceWrapper< H, D > &object)
 Copy constructor.
 
KOKKOS_FUNCTION const D & device () const
 Get the device copy.
 
H & host ()
 Get the host reference.
 
const H & host () const
 

Protected Attributes

H & _reference
 Writeable host reference of the variable.
 
const D _copy
 Device copy of the variable.
 

Detailed Description

template<typename H, typename D>
class Moose::Kokkos::DualReferenceWrapper< H, D >

The Kokkos object that can hold a host reference and a device-compatible copy of a variable.

Reference of a host variable is not accessible on device, so if there is a variable that should be stored as a reference but still needs to be accessed on device, define an instance of this class and construct it with the reference of the variable. This class holds the device copy as well as the host reference of the variable. The copy constructor of this object that copies the host reference to the device copy is invoked whenever a Kokkos functor containing this object is dispatched to device, so it is guaranteed that the device copy is always up-to-date with the host reference when it is used on device. Therefore, D must be constructible from H.

Template Parameters
HThe host reference type
DThe device copy type

Definition at line 33 of file KokkosReferenceWrapper.h.

Constructor & Destructor Documentation

◆ DualReferenceWrapper() [1/2]

template<typename H , typename D >
Moose::Kokkos::DualReferenceWrapper< H, D >::DualReferenceWrapper ( H &  reference)
inline

Constructor.

Parameters
referenceThe host reference of the variable to store

Definition at line 40 of file KokkosReferenceWrapper.h.

40: _reference(reference), _copy(reference) {}
const D _copy
Device copy of the variable.
H & _reference
Writeable host reference of the variable.

◆ DualReferenceWrapper() [2/2]

template<typename H , typename D >
Moose::Kokkos::DualReferenceWrapper< H, D >::DualReferenceWrapper ( const DualReferenceWrapper< H, D > &  object)
inline

Copy constructor.

Definition at line 44 of file KokkosReferenceWrapper.h.

45 : _reference(object._reference), _copy(object._reference)
46 {
47 }

Member Function Documentation

◆ device()

template<typename H , typename D >
KOKKOS_FUNCTION const D & Moose::Kokkos::DualReferenceWrapper< H, D >::device ( ) const
inline

Get the device copy.

Returns
The device copy

Definition at line 63 of file KokkosReferenceWrapper.h.

64 {
65 KOKKOS_IF_ON_HOST(
66 mooseError("Kokkos reference wrapper error: device() should not be called from host.");)
67
68 return _copy;
69 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311

◆ host() [1/2]

template<typename H , typename D >
H & Moose::Kokkos::DualReferenceWrapper< H, D >::host ( )
inline

Get the host reference.

Returns
The host reference

Definition at line 54 of file KokkosReferenceWrapper.h.

54{ return _reference; }

◆ host() [2/2]

template<typename H , typename D >
const H & Moose::Kokkos::DualReferenceWrapper< H, D >::host ( ) const
inline

Definition at line 55 of file KokkosReferenceWrapper.h.

55{ return _reference; }

Member Data Documentation

◆ _copy

template<typename H , typename D >
const D Moose::Kokkos::DualReferenceWrapper< H, D >::_copy
protected

Device copy of the variable.

Definition at line 80 of file KokkosReferenceWrapper.h.

Referenced by Moose::Kokkos::DualReferenceWrapper< H, D >::device().

◆ _reference

template<typename H , typename D >
H& Moose::Kokkos::DualReferenceWrapper< H, D >::_reference
protected

Writeable host reference of the variable.

Definition at line 76 of file KokkosReferenceWrapper.h.

Referenced by Moose::Kokkos::DualReferenceWrapper< H, D >::host(), and Moose::Kokkos::DualReferenceWrapper< H, D >::host().


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