https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | List of all members
Moose::Kokkos::ReferenceWrapper< T > Class Template Reference

The Kokkos object that can hold the reference of a variable. More...

#include <KokkosReferenceWrapper.h>

Inheritance diagram for Moose::Kokkos::ReferenceWrapper< T >:
[legend]

Public Member Functions

 ReferenceWrapper (T &reference)
 Constructor. More...
 
 ReferenceWrapper (const ReferenceWrapper< T > &object)
 Copy constructor. More...
 
KOKKOS_FUNCTION operator const T & () const
 Get the const reference of the stored variable. More...
 
KOKKOS_FUNCTION const T & operator* () const
 Get the const reference of the stored variable. More...
 
KOKKOS_FUNCTION const T * operator-> () const
 Get the const pointer to the stored variable. More...
 
template<typename... Args>
KOKKOS_FUNCTION auto operator() (Args &&... args) const -> decltype(auto)
 Forward arguments to the stored variable's const operator() depending on the architecture this function is being called on. More...
 
 operator const T & () const
 Get the const reference of the stored host reference. More...
 
const T & operator* () const
 Get the const reference of the stored host reference. More...
 
const T * operator-> () const
 Get the const pointer of the stored host reference. More...
 
template<typename... Args>
auto operator() (Args &&... args) const -> decltype(auto)
 Forward arguments to the stored host reference's const operator() More...
 
 operator T& ()
 Get the writeable reference of the stored host reference. More...
 
T & operator* ()
 Get the writeable reference of the stored host reference. More...
 
T * operator-> ()
 Get the writeable pointer of the stored host reference. More...
 
template<typename... Args>
auto operator() (Args &&... args) -> decltype(auto)
 Forward arguments to the stored host reference's operator() More...
 

Protected Attributes

T & _reference
 Writeable host reference of the variable. More...
 
const T _copy
 Device copy of the variable. More...
 

Detailed Description

template<typename T>
class Moose::Kokkos::ReferenceWrapper< T >

The Kokkos object that can hold the reference 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, the variable must be copy constructible.

Definition at line 35 of file KokkosReferenceWrapper.h.

Constructor & Destructor Documentation

◆ ReferenceWrapper() [1/2]

template<typename T>
Moose::Kokkos::ReferenceWrapper< T >::ReferenceWrapper ( T &  reference)
inline

Constructor.

Parameters
referenceThe writeable reference of the variable to store

Definition at line 42 of file KokkosReferenceWrapper.h.

42 : _reference(reference), _copy(reference) {}
T & _reference
Writeable host reference of the variable.
const T _copy
Device copy of the variable.

◆ ReferenceWrapper() [2/2]

template<typename T>
Moose::Kokkos::ReferenceWrapper< T >::ReferenceWrapper ( const ReferenceWrapper< T > &  object)
inline

Copy constructor.

Definition at line 46 of file KokkosReferenceWrapper.h.

47  : _reference(object._reference), _copy(object._reference)
48  {
49  }
T & _reference
Writeable host reference of the variable.
const T _copy
Device copy of the variable.

Member Function Documentation

◆ operator const T &() [1/2]

template<typename T>
KOKKOS_FUNCTION Moose::Kokkos::ReferenceWrapper< T >::operator const T & ( ) const
inline

Get the const reference of the stored variable.

Returns
The const reference of the stored variable depending on the architecture this function is being called on

Definition at line 57 of file KokkosReferenceWrapper.h.

58  {
59  KOKKOS_IF_ON_HOST(return _reference;)
60 
61  return _copy;
62  }
T & _reference
Writeable host reference of the variable.
const T _copy
Device copy of the variable.

◆ operator const T &() [2/2]

template<typename T>
Moose::Kokkos::ReferenceWrapper< T >::operator const T & ( ) const
inline

Get the const reference of the stored host reference.

Returns
The const reference of the stored host reference

Definition at line 102 of file KokkosReferenceWrapper.h.

102 { return _reference; }
T & _reference
Writeable host reference of the variable.

◆ operator T&()

template<typename T>
Moose::Kokkos::ReferenceWrapper< T >::operator T & ( )
inline

Get the writeable reference of the stored host reference.

Returns
The writeable reference of the stored host reference

Definition at line 127 of file KokkosReferenceWrapper.h.

127 { return _reference; }
T & _reference
Writeable host reference of the variable.

◆ operator()() [1/3]

template<typename T>
template<typename... Args>
KOKKOS_FUNCTION auto Moose::Kokkos::ReferenceWrapper< T >::operator() ( Args &&...  args) const -> decltype(auto)
inline

Forward arguments to the stored variable's const operator() depending on the architecture this function is being called on.

Parameters
argsThe variadic arguments to be forwarded

Definition at line 91 of file KokkosReferenceWrapper.h.

92  {
93  KOKKOS_IF_ON_HOST(return _reference(std::forward<Args>(args)...);)
94 
95  return _copy(std::forward<Args>(args)...);
96  }
T & _reference
Writeable host reference of the variable.
const T _copy
Device copy of the variable.

◆ operator()() [2/3]

template<typename T>
template<typename... Args>
auto Moose::Kokkos::ReferenceWrapper< T >::operator() ( Args &&...  args) const -> decltype(auto)
inline

Forward arguments to the stored host reference's const operator()

Parameters
argsThe variadic arguments to be forwarded

Definition at line 118 of file KokkosReferenceWrapper.h.

119  {
120  return _reference(std::forward<Args>(args)...);
121  }
T & _reference
Writeable host reference of the variable.

◆ operator()() [3/3]

template<typename T>
template<typename... Args>
auto Moose::Kokkos::ReferenceWrapper< T >::operator() ( Args &&...  args) -> decltype(auto)
inline

Forward arguments to the stored host reference's operator()

Parameters
argsThe variadic arguments to be forwarded

Definition at line 143 of file KokkosReferenceWrapper.h.

144  {
145  return _reference(std::forward<Args>(args)...);
146  }
T & _reference
Writeable host reference of the variable.

◆ operator*() [1/3]

template<typename T>
KOKKOS_FUNCTION const T& Moose::Kokkos::ReferenceWrapper< T >::operator* ( ) const
inline

Get the const reference of the stored variable.

Returns
The const reference of the stored variable depending on the architecture this function is being called on

Definition at line 68 of file KokkosReferenceWrapper.h.

69  {
70  KOKKOS_IF_ON_HOST(return _reference;)
71 
72  return _copy;
73  }
T & _reference
Writeable host reference of the variable.
const T _copy
Device copy of the variable.

◆ operator*() [2/3]

template<typename T>
const T& Moose::Kokkos::ReferenceWrapper< T >::operator* ( ) const
inline

Get the const reference of the stored host reference.

Returns
The const reference of the stored host reference

Definition at line 107 of file KokkosReferenceWrapper.h.

107 { return _reference; }
T & _reference
Writeable host reference of the variable.

◆ operator*() [3/3]

template<typename T>
T& Moose::Kokkos::ReferenceWrapper< T >::operator* ( )
inline

Get the writeable reference of the stored host reference.

Returns
The writeable reference of the stored host reference

Definition at line 132 of file KokkosReferenceWrapper.h.

132 { return _reference; }
T & _reference
Writeable host reference of the variable.

◆ operator->() [1/3]

template<typename T>
KOKKOS_FUNCTION const T* Moose::Kokkos::ReferenceWrapper< T >::operator-> ( ) const
inline

Get the const pointer to the stored variable.

Returns
The const pointer to the stored variable depending on the architecture this function is being called on

Definition at line 79 of file KokkosReferenceWrapper.h.

80  {
81  KOKKOS_IF_ON_HOST(return &_reference;)
82 
83  return &_copy;
84  }
T & _reference
Writeable host reference of the variable.
const T _copy
Device copy of the variable.

◆ operator->() [2/3]

template<typename T>
const T* Moose::Kokkos::ReferenceWrapper< T >::operator-> ( ) const
inline

Get the const pointer of the stored host reference.

Returns
The const pointer to the stored host reference

Definition at line 112 of file KokkosReferenceWrapper.h.

112 { return &_reference; }
T & _reference
Writeable host reference of the variable.

◆ operator->() [3/3]

template<typename T>
T* Moose::Kokkos::ReferenceWrapper< T >::operator-> ( )
inline

Get the writeable pointer of the stored host reference.

Returns
The writeable pointer to the stored host reference

Definition at line 137 of file KokkosReferenceWrapper.h.

137 { return &_reference; }
T & _reference
Writeable host reference of the variable.

Member Data Documentation

◆ _copy

template<typename T>
const T Moose::Kokkos::ReferenceWrapper< T >::_copy
protected

◆ _reference

template<typename T>
T& Moose::Kokkos::ReferenceWrapper< T >::_reference
protected

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