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 31 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 38 of file KokkosReferenceWrapper.h.

38 : _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 42 of file KokkosReferenceWrapper.h.

43  : _reference(object._reference), _copy(object._reference)
44  {
45  }
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 53 of file KokkosReferenceWrapper.h.

54  {
55  KOKKOS_IF_ON_HOST(return _reference;)
56 
57  return _copy;
58  }
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 98 of file KokkosReferenceWrapper.h.

98 { 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 123 of file KokkosReferenceWrapper.h.

123 { 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 87 of file KokkosReferenceWrapper.h.

88  {
89  KOKKOS_IF_ON_HOST(return _reference(std::forward<Args>(args)...);)
90 
91  return _copy(std::forward<Args>(args)...);
92  }
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 114 of file KokkosReferenceWrapper.h.

115  {
116  return _reference(std::forward<Args>(args)...);
117  }
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 139 of file KokkosReferenceWrapper.h.

140  {
141  return _reference(std::forward<Args>(args)...);
142  }
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 64 of file KokkosReferenceWrapper.h.

65  {
66  KOKKOS_IF_ON_HOST(return _reference;)
67 
68  return _copy;
69  }
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 103 of file KokkosReferenceWrapper.h.

103 { 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 128 of file KokkosReferenceWrapper.h.

128 { 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 75 of file KokkosReferenceWrapper.h.

76  {
77  KOKKOS_IF_ON_HOST(return &_reference;)
78 
79  return &_copy;
80  }
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 108 of file KokkosReferenceWrapper.h.

108 { 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 133 of file KokkosReferenceWrapper.h.

133 { 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: