17#ifndef dealii_memory_space_data_h
18#define dealii_memory_space_data_h
26#include <Kokkos_Core.hpp>
44 template <
typename T,
typename MemorySpace>
54 copy_to(T *begin,
const std::size_t n_elements);
61 copy_from(
const T *begin,
const std::size_t n_elements);
72 Kokkos::View<T *, typename MemorySpace::kokkos_space>
values;
97 template <
typename T,
typename MemorySpace>
104 template <
typename T,
typename MemorySpace>
106 : values_host_buffer(
107 (::
internal::ensure_kokkos_initialized(),
108 Kokkos::View<T *, Kokkos::HostSpace>(
"host buffer", 0)))
109 , values(Kokkos::View<T *, typename
MemorySpace::kokkos_space>(
116 template <
typename T,
typename MemorySpace>
118 MemorySpaceData<T, MemorySpace>::copy_to(T * begin,
119 const std::size_t n_elements)
121 Assert(n_elements <= values.extent(0),
123 "n_elements is greater than the size of MemorySpaceData."));
124 using ExecutionSpace =
typename MemorySpace::kokkos_space::execution_space;
126 View<T *, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
127 begin_view(begin, n_elements);
131 Kokkos::subview(values, Kokkos::make_pair(std::size_t(0), n_elements)));
132 ExecutionSpace{}.fence();
137 template <
typename T,
typename MemorySpace>
139 MemorySpaceData<T, MemorySpace>::copy_from(
const T * begin,
140 const std::size_t n_elements)
144 "n_elements is greater than the size of MemorySpaceData."));
145 using ExecutionSpace =
typename MemorySpace::kokkos_space::execution_space;
146 Kokkos::View<
const T *,
148 Kokkos::MemoryTraits<Kokkos::Unmanaged>>
149 begin_view(begin, n_elements);
152 Kokkos::subview(values, Kokkos::make_pair(std::size_t(0), n_elements)),
154 ExecutionSpace{}.fence();
162 template <
typename T,
typename MemorySpace>
164 swap(MemorySpaceData<T, MemorySpace> &u, MemorySpaceData<T, MemorySpace> &v)
166 std::swap(u.values_host_buffer, v.values_host_buffer);
167 std::swap(u.values, v.values);
168 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)
void swap(SmartPointer< T, P > &t1, SmartPointer< 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)