https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosReferenceWrapper.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "KokkosArray.h"
13
14#include "MooseTypes.h"
15
16namespace Moose::Kokkos
17{
18
30template <typename T>
32{
33public:
38 ReferenceWrapper(T & reference) : _reference(reference), _copy(reference) {}
43 : _reference(object._reference), _copy(object._reference)
44 {
45 }
46
47#ifdef MOOSE_KOKKOS_SCOPE
53 KOKKOS_FUNCTION operator const T &() const
54 {
55 KOKKOS_IF_ON_HOST(return _reference;)
56
57 return _copy;
58 }
64 KOKKOS_FUNCTION const T & operator*() const
65 {
66 KOKKOS_IF_ON_HOST(return _reference;)
67
68 return _copy;
69 }
75 KOKKOS_FUNCTION const T * operator->() const
76 {
77 KOKKOS_IF_ON_HOST(return &_reference;)
78
79 return &_copy;
80 }
86 template <typename... Args>
87 KOKKOS_FUNCTION auto operator()(Args &&... args) const -> decltype(auto)
88 {
89 KOKKOS_IF_ON_HOST(return _reference(std::forward<Args>(args)...);)
90
91 return _copy(std::forward<Args>(args)...);
92 }
93#else
98 operator const T &() const { return _reference; }
103 const T & operator*() const { return _reference; }
108 const T * operator->() const { return &_reference; }
113 template <typename... Args>
114 auto operator()(Args &&... args) const -> decltype(auto)
115 {
116 return _reference(std::forward<Args>(args)...);
117 }
118#endif
123 operator T &() { return _reference; }
128 T & operator*() { return _reference; }
133 T * operator->() { return &_reference; }
138 template <typename... Args>
139 auto operator()(Args &&... args) -> decltype(auto)
140 {
141 return _reference(std::forward<Args>(args)...);
142 }
143
144protected:
152 const T _copy;
153};
154
155template <typename T>
157{
158 static constexpr bool value = true;
159};
160
161} // namespace Moose::Kokkos
The Kokkos object that can hold the reference of a variable.
KOKKOS_FUNCTION const T * operator->() const
Get the const pointer to the stored variable.
const T _copy
Device copy of the variable.
ReferenceWrapper(T &reference)
Constructor.
T * operator->()
Get the writeable pointer of the stored host reference.
ReferenceWrapper(const ReferenceWrapper< T > &object)
Copy constructor.
const T * operator->() const
Get the const pointer of the stored host reference.
T & _reference
Writeable host reference of the variable.
KOKKOS_FUNCTION const T & operator*() const
Get the const reference of the stored variable.
KOKKOS_FUNCTION auto operator()(Args &&... args) const -> decltype(auto)
Forward arguments to the stored variable's const operator() depending on the architecture this functi...
auto operator()(Args &&... args) const -> decltype(auto)
Forward arguments to the stored host reference's const operator()
const T & operator*() const
Get the const reference of the stored host reference.
T & operator*()
Get the writeable reference of the stored host reference.
auto operator()(Args &&... args) -> decltype(auto)
Forward arguments to the stored host reference's operator()
The type trait that determines the default behavior of copy constructor and deepCopy() If this type t...
Definition KokkosArray.h:92
static constexpr bool value
Definition KokkosArray.h:93