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

The Kokkos wrapper class that can hold the reference of an arithmetic scalar variable. More...

#include <KokkosScalar.h>

Inheritance diagram for Moose::Kokkos::Scalar< T, typename >:
[legend]

Public Types

using value_type = T
 

Public Member Functions

 Scalar (T &value)
 Constructor. More...
 
 Scalar (const Scalar &object)
 Copy constructor. More...
 
auto & operator= (const Scalar &value)
 Assign a scalar value to the underlying host reference. More...
 
template<typename U >
auto operator= (const U &value) -> decltype(std::declval< T &>()=value, std::declval< Scalar &>())
 Assign an arithmetic value to the underlying host reference. More...
 
KOKKOS_SCALAR_FUNCTION auto operator+ () const -> decltype(+std::declval< const T &>())
 Get the positive value of the scalar. More...
 
KOKKOS_SCALAR_FUNCTION auto operator- () const -> decltype(-std::declval< const T &>())
 Get the negated value of the scalar. More...
 
template<typename U >
auto operator+= (const U &value) -> decltype(std::declval< T &>()+=value, std::declval< Scalar &>())
 Add another value to the underlying host reference. More...
 
template<typename U >
auto operator-= (const U &value) -> decltype(std::declval< T &>() -=value, std::declval< Scalar &>())
 Subtract another value from the underlying host reference. More...
 
template<typename U >
auto operator*= (const U &value) -> decltype(std::declval< T &>() *=value, std::declval< Scalar &>())
 Multiply the underlying host reference by another value. More...
 
template<typename U >
auto operator/= (const U &value) -> decltype(std::declval< T &>()/=value, std::declval< Scalar &>())
 Divide the underlying host reference by another value. More...
 
template<typename U >
auto operator%= (const U &value) -> decltype(std::declval< T &>() %=value, std::declval< Scalar &>())
 Assign the remainder after division by another value to the underlying host reference. More...
 
template<typename U = T>
auto operator++ () -> decltype(++std::declval< U &>(), std::declval< Scalar &>())
 Prefix increment the underlying host reference. More...
 
template<typename U = T>
auto operator++ (int) -> decltype(std::declval< U &>()++)
 Postfix increment the underlying host reference. More...
 
template<typename U = T>
auto operator-- () -> decltype(--std::declval< U &>(), std::declval< Scalar &>())
 Prefix decrement the underlying host reference. More...
 
template<typename U = T>
auto operator-- (int) -> decltype(std::declval< U &>() --)
 Postfix decrement the underlying host reference. More...
 
template<typename U >
KOKKOS_SCALAR_FUNCTION auto operator+ (const U &value) const -> decltype(std::declval< const T &>()+value)
 Add another value to this scalar. More...
 
template<typename U >
KOKKOS_SCALAR_FUNCTION auto operator- (const U &value) const -> decltype(std::declval< const T &>() - value)
 Subtract another value from this scalar. More...
 
template<typename U >
KOKKOS_SCALAR_FUNCTION auto operator* (const U &value) const -> decltype(std::declval< const T &>() *value)
 Multiply this scalar by another value. More...
 
template<typename U >
KOKKOS_SCALAR_FUNCTION auto operator/ (const U &value) const -> decltype(std::declval< const T &>()/value)
 Divide this scalar by another value. More...
 
template<typename U >
KOKKOS_SCALAR_FUNCTION auto operator% (const U &value) const -> decltype(std::declval< const T &>() % value)
 Get the remainder after division by another value. More...
 
KOKKOS_FUNCTION operator const T & () const
 Get the const reference of the stored variable. More...
 
 operator const T & () const
 Get the const reference of the stored host reference. More...
 
KOKKOS_FUNCTION const T & operator* () const
 Get the const reference of the stored variable. More...
 
T & operator* ()
 Get the writeable reference of the stored host reference. More...
 
KOKKOS_FUNCTION const T * operator-> () const
 Get the const pointer to the stored variable. More...
 
const T * operator-> () const
 Get the const pointer of the stored host reference. More...
 
T * operator-> ()
 Get the writeable pointer of the stored host reference. 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...
 
template<typename... Args>
auto operator() (Args &&... args) const -> decltype(auto)
 Forward arguments to the stored host reference's const operator() More...
 
template<typename... Args>
auto operator() (Args &&... args) -> decltype(auto)
 Forward arguments to the stored host reference's operator() More...
 
 operator T& ()
 Get the writeable reference of the stored host reference. More...
 

Protected Attributes

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

Private Member Functions

KOKKOS_SCALAR_FUNCTION const T & value () const
 

Detailed Description

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
class Moose::Kokkos::Scalar< T, typename >

The Kokkos wrapper class that can hold the reference of an arithmetic scalar variable.

Definition at line 30 of file KokkosScalar.h.

Member Typedef Documentation

◆ value_type

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
using Moose::Kokkos::Scalar< T, typename >::value_type = T

Definition at line 33 of file KokkosScalar.h.

Constructor & Destructor Documentation

◆ Scalar() [1/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
Moose::Kokkos::Scalar< T, typename >::Scalar ( T &  value)
inline

Constructor.

Parameters
valueThe writeable reference of the arithmetic scalar variable to store

Definition at line 39 of file KokkosScalar.h.

39 : ReferenceWrapper<T>(value) {}
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ Scalar() [2/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
Moose::Kokkos::Scalar< T, typename >::Scalar ( const Scalar< T, typename > &  object)
inline

Copy constructor.

Definition at line 43 of file KokkosScalar.h.

43 : ReferenceWrapper<T>(object) {}

Member Function Documentation

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

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

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
inlineinherited

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 & ( )
inlineinherited

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%()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
KOKKOS_SCALAR_FUNCTION auto Moose::Kokkos::Scalar< T, typename >::operator% ( const U &  value) const -> decltype(std::declval<const T &>() % value)
inline

Get the remainder after division by another value.

Parameters
valueThe divisor value
Returns
The remainder

Definition at line 236 of file KokkosScalar.h.

238  {
239  return this->value() % value;
240  }
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator%=()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
auto Moose::Kokkos::Scalar< T, typename >::operator%= ( const U &  value) -> decltype(std::declval<T &>() %= value, std::declval<Scalar &>())
inline

Assign the remainder after division by another value to the underlying host reference.

Parameters
valueThe divisor value

Definition at line 137 of file KokkosScalar.h.

139  {
140  this->_reference %= value;
141 
142  return *this;
143  }
T & _reference
Writeable host reference of the variable.
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator()() [1/3]

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

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)
inlineinherited

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)
inlineinherited

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
inlineinherited

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>
T& Moose::Kokkos::ReferenceWrapper< T >::operator* ( )
inlineinherited

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*() [3/3]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
KOKKOS_SCALAR_FUNCTION auto Moose::Kokkos::Scalar< T, typename >::operator* ( const U &  value) const -> decltype(std::declval<const T &>() * value)
inline

Multiply this scalar by another value.

Parameters
valueThe value to multiply by
Returns
The product

Definition at line 214 of file KokkosScalar.h.

216  {
217  return this->value() * value;
218  }
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator*=()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
auto Moose::Kokkos::Scalar< T, typename >::operator*= ( const U &  value) -> decltype(std::declval<T &>() *= value, std::declval<Scalar &>())
inline

Multiply the underlying host reference by another value.

Parameters
valueThe value to multiply by

Definition at line 113 of file KokkosScalar.h.

115  {
116  this->_reference *= value;
117 
118  return *this;
119  }
T & _reference
Writeable host reference of the variable.
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator+() [1/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
KOKKOS_SCALAR_FUNCTION auto Moose::Kokkos::Scalar< T, typename >::operator+ ( ) const -> decltype(+std::declval<const T &>())
inline

Get the positive value of the scalar.

Returns
The positive scalar value

Definition at line 71 of file KokkosScalar.h.

72  {
73  return +value();
74  }
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator+() [2/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
KOKKOS_SCALAR_FUNCTION auto Moose::Kokkos::Scalar< T, typename >::operator+ ( const U &  value) const -> decltype(std::declval<const T &>() + value)
inline

Add another value to this scalar.

Parameters
valueThe value to add
Returns
The sum

Definition at line 192 of file KokkosScalar.h.

194  {
195  return this->value() + value;
196  }
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator++() [1/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U = T>
auto Moose::Kokkos::Scalar< T, typename >::operator++ ( ) -> decltype(++std::declval<U &>(), std::declval<Scalar &>())
inline

Prefix increment the underlying host reference.

Returns
This scalar wrapper

Definition at line 150 of file KokkosScalar.h.

151  {
152  ++this->_reference;
153 
154  return *this;
155  }
T & _reference
Writeable host reference of the variable.

◆ operator++() [2/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U = T>
auto Moose::Kokkos::Scalar< T, typename >::operator++ ( int  ) -> decltype(std::declval<U &>()++)
inline

Postfix increment the underlying host reference.

Returns
The previous scalar value

Definition at line 161 of file KokkosScalar.h.

162  {
163  return this->_reference++;
164  }
T & _reference
Writeable host reference of the variable.

◆ operator+=()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
auto Moose::Kokkos::Scalar< T, typename >::operator+= ( const U &  value) -> decltype(std::declval<T &>() += value, std::declval<Scalar &>())
inline

Add another value to the underlying host reference.

Parameters
valueThe value to add

Definition at line 89 of file KokkosScalar.h.

91  {
92  this->_reference += value;
93 
94  return *this;
95  }
T & _reference
Writeable host reference of the variable.
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator-() [1/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
KOKKOS_SCALAR_FUNCTION auto Moose::Kokkos::Scalar< T, typename >::operator- ( ) const -> decltype(-std::declval<const T &>())
inline

Get the negated value of the scalar.

Returns
The negated scalar value

Definition at line 79 of file KokkosScalar.h.

80  {
81  return -value();
82  }
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator-() [2/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
KOKKOS_SCALAR_FUNCTION auto Moose::Kokkos::Scalar< T, typename >::operator- ( const U &  value) const -> decltype(std::declval<const T &>() - value)
inline

Subtract another value from this scalar.

Parameters
valueThe value to subtract
Returns
The difference

Definition at line 203 of file KokkosScalar.h.

205  {
206  return this->value() - value;
207  }
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator--() [1/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U = T>
auto Moose::Kokkos::Scalar< T, typename >::operator-- ( ) -> decltype(--std::declval<U &>(), std::declval<Scalar &>())
inline

Prefix decrement the underlying host reference.

Returns
This scalar wrapper

Definition at line 170 of file KokkosScalar.h.

171  {
172  --this->_reference;
173 
174  return *this;
175  }
T & _reference
Writeable host reference of the variable.

◆ operator--() [2/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U = T>
auto Moose::Kokkos::Scalar< T, typename >::operator-- ( int  ) -> decltype(std::declval<U &>()--)
inline

Postfix decrement the underlying host reference.

Returns
The previous scalar value

Definition at line 181 of file KokkosScalar.h.

182  {
183  return this->_reference--;
184  }
T & _reference
Writeable host reference of the variable.

◆ operator-=()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
auto Moose::Kokkos::Scalar< T, typename >::operator-= ( const U &  value) -> decltype(std::declval<T &>() -= value, std::declval<Scalar &>())
inline

Subtract another value from the underlying host reference.

Parameters
valueThe value to subtract

Definition at line 101 of file KokkosScalar.h.

103  {
104  this->_reference -= value;
105 
106  return *this;
107  }
T & _reference
Writeable host reference of the variable.
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator->() [1/3]

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

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
inlineinherited

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-> ( )
inlineinherited

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.

◆ operator/()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
KOKKOS_SCALAR_FUNCTION auto Moose::Kokkos::Scalar< T, typename >::operator/ ( const U &  value) const -> decltype(std::declval<const T &>() / value)
inline

Divide this scalar by another value.

Parameters
valueThe value to divide by
Returns
The quotient

Definition at line 225 of file KokkosScalar.h.

227  {
228  return this->value() / value;
229  }
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator/=()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
auto Moose::Kokkos::Scalar< T, typename >::operator/= ( const U &  value) -> decltype(std::declval<T &>() /= value, std::declval<Scalar &>())
inline

Divide the underlying host reference by another value.

Parameters
valueThe value to divide by

Definition at line 125 of file KokkosScalar.h.

127  {
128  this->_reference /= value;
129 
130  return *this;
131  }
T & _reference
Writeable host reference of the variable.
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator=() [1/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
auto& Moose::Kokkos::Scalar< T, typename >::operator= ( const Scalar< T, typename > &  value)
inline

Assign a scalar value to the underlying host reference.

Parameters
valueThe scalar value to be assigned

Definition at line 49 of file KokkosScalar.h.

50  {
51  this->_reference = static_cast<const T &>(value);
52 
53  return *this;
54  }
T & _reference
Writeable host reference of the variable.
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ operator=() [2/2]

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
template<typename U >
auto Moose::Kokkos::Scalar< T, typename >::operator= ( const U &  value) -> decltype(std::declval<T &>() = value, std::declval<Scalar &>())
inline

Assign an arithmetic value to the underlying host reference.

Parameters
valueThe scalar value to be assigned

Definition at line 60 of file KokkosScalar.h.

61  {
62  this->_reference = value;
63 
64  return *this;
65  }
T & _reference
Writeable host reference of the variable.
KOKKOS_SCALAR_FUNCTION const T & value() const
Definition: KokkosScalar.h:243

◆ value()

template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
KOKKOS_SCALAR_FUNCTION const T& Moose::Kokkos::Scalar< T, typename >::value ( ) const
inlineprivate

Member Data Documentation

◆ _copy

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

◆ _reference

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

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