16#ifndef dealii_memory_space_data_h
17#define dealii_memory_space_data_h
25#include <Kokkos_Core.hpp>
43 template <
typename T,
typename MemorySpace>
53 copy_to(T *begin,
const std::size_t n_elements);
60 copy_from(
const T *begin,
const std::size_t n_elements);
66#if KOKKOS_VERSION < 40000
75 Kokkos::View<T *, typename MemorySpace::kokkos_space>
values;
100 template <
typename T,
typename MemorySpace>
108 template <
typename T,
typename MemorySpace>
110 : values_host_buffer(
111 (::
internal::ensure_kokkos_initialized(),
112# if KOKKOS_VERSION < 40000
113 Kokkos::View<T *,
Kokkos::HostSpace>(
"host buffer", 0)))
115 Kokkos::View<T *,
Kokkos::SharedHostPinnedSpace>(
"host pinned buffer",
125 template <
typename T,
typename MemorySpace>
127 MemorySpaceData<T, MemorySpace>::copy_to(T *begin,
128 const std::size_t n_elements)
130 Assert(n_elements <= values.extent(0),
132 "n_elements is greater than the size of MemorySpaceData."));
133 using ExecutionSpace =
typename MemorySpace::kokkos_space::execution_space;
135 View<T *, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
136 begin_view(begin, n_elements);
140 Kokkos::subview(values, Kokkos::make_pair(std::size_t(0), n_elements)));
141 ExecutionSpace{}.fence();
146 template <
typename T,
typename MemorySpace>
148 MemorySpaceData<T, MemorySpace>::copy_from(
const T *begin,
149 const std::size_t n_elements)
151 Assert(n_elements <= values.extent(0),
153 "n_elements is greater than the size of MemorySpaceData."));
154 using ExecutionSpace =
typename MemorySpace::kokkos_space::execution_space;
155 Kokkos::View<
const T *,
157 Kokkos::MemoryTraits<Kokkos::Unmanaged>>
158 begin_view(begin, n_elements);
161 Kokkos::subview(values, Kokkos::make_pair(std::size_t(0), n_elements)),
163 ExecutionSpace{}.fence();
171 template <
typename T,
typename MemorySpace>
173 swap(MemorySpaceData<T, MemorySpace> &u,
174 MemorySpaceData<T, MemorySpace> &v)
noexcept
176 std::swap(u.values_host_buffer, v.values_host_buffer);
177 std::swap(u.values, v.values);
178 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(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)