16#ifndef dealii_memory_space_data_h
17#define dealii_memory_space_data_h
25#include <Kokkos_Core.hpp>
42 template <
typename T,
typename MemorySpace>
52 copy_to(T *begin,
const std::size_t n_elements);
59 copy_from(
const T *begin,
const std::size_t n_elements);
65#if KOKKOS_VERSION < 40000
74 Kokkos::View<T *, typename MemorySpace::kokkos_space>
values;
99 template <
typename T,
typename MemorySpace>
107 template <
typename T,
typename MemorySpace>
109 : values_host_buffer(
110 (::
internal::ensure_kokkos_initialized(),
111# if KOKKOS_VERSION < 40000
112 Kokkos::View<T *,
Kokkos::HostSpace>(
"host buffer", 0)))
114 Kokkos::View<T *,
Kokkos::SharedHostPinnedSpace>(
"host pinned buffer",
124 template <
typename T,
typename MemorySpace>
126 MemorySpaceData<T, MemorySpace>::copy_to(T *begin,
127 const std::size_t n_elements)
129 Assert(n_elements <= values.extent(0),
131 "n_elements is greater than the size of MemorySpaceData."));
132 using ExecutionSpace =
typename MemorySpace::kokkos_space::execution_space;
134 View<T *, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
135 begin_view(begin, n_elements);
139 Kokkos::subview(values, Kokkos::make_pair(std::size_t(0), n_elements)));
140 ExecutionSpace{}.fence();
145 template <
typename T,
typename MemorySpace>
147 MemorySpaceData<T, MemorySpace>::copy_from(
const T *begin,
148 const std::size_t n_elements)
152 "n_elements is greater than the size of MemorySpaceData."));
153 using ExecutionSpace =
typename MemorySpace::kokkos_space::execution_space;
154 Kokkos::View<
const T *,
156 Kokkos::MemoryTraits<Kokkos::Unmanaged>>
157 begin_view(begin, n_elements);
160 Kokkos::subview(values, Kokkos::make_pair(std::size_t(0), n_elements)),
162 ExecutionSpace{}.fence();
170 template <
typename T,
typename MemorySpace>
172 swap(MemorySpaceData<T, MemorySpace> &u,
173 MemorySpaceData<T, MemorySpace> &v)
noexcept
175 std::swap(u.values_host_buffer, v.values_host_buffer);
176 std::swap(u.values, v.values);
177 std::swap(u.values_sm_ptr, v.values_sm_ptr);
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
void swap(MemorySpaceData< T, MemorySpace > &u, MemorySpaceData< T, MemorySpace > &v) noexcept
void swap(ObserverPointer< T, P > &t1, ObserverPointer< T, Q > &t2)
Kokkos::View< T *, Kokkos::HostSpace > values_host_buffer
Kokkos::View< T *, typename MemorySpace::kokkos_space > values
std::vector< ArrayView< const T > > values_sm
std::shared_ptr< T > values_sm_ptr
void copy_to(T *begin, const std::size_t n_elements)
void copy_from(const T *begin, const std::size_t n_elements)