17#ifndef dealii_memory_space_data_h
18#define dealii_memory_space_data_h
37 template <
typename Number,
typename MemorySpace>
42 static_assert(std::is_same<MemorySpace, Host>::value ||
43 std::is_same<MemorySpace, CUDA>::value,
44 "MemorySpace should be Host or CUDA");
52 copy_to(Number *begin, std::size_t n_elements)
72 std::unique_ptr<Number[], std::function<void(Number *)>>
values;
90 template <
typename Number,
typename MemorySpace>
95 static_assert(std::is_same<MemorySpace, Host>::value ||
96 std::is_same<MemorySpace, CUDA>::value,
97 "MemorySpace should be Host or CUDA");
102 template <
typename Number>
103 struct MemorySpaceData<Number, Host>
110 copy_to(Number *begin, std::size_t n_elements)
112 std::copy(
values.get(),
values.get() + n_elements, begin);
116 copy_from(Number *begin, std::size_t n_elements)
118 std::copy(begin, begin + n_elements,
values.get());
121 std::unique_ptr<Number[], std::function<void(Number *)>>
values;
127 std::vector<ArrayView<const Number>>
values_sm;
132 template <
typename Number>
134 swap(MemorySpaceData<Number, Host> &u, MemorySpaceData<Number, Host> &v)
136 std::swap(u.values, v.values);
141# ifdef DEAL_II_COMPILER_CUDA_AWARE
143 template <
typename Number>
144 struct MemorySpaceData<Number, CUDA>
152 copy_to(Number *begin, std::size_t n_elements)
154 const cudaError_t cuda_error_code =
157 n_elements *
sizeof(Number),
158 cudaMemcpyDeviceToHost);
163 copy_from(Number *begin, std::size_t n_elements)
165 const cudaError_t cuda_error_code =
168 n_elements *
sizeof(Number),
169 cudaMemcpyHostToDevice);
173 std::unique_ptr<Number[], std::function<void(Number *)>>
values;
174 std::unique_ptr<Number[], void (*)(Number *)>
values_dev;
179 std::vector<ArrayView<const Number>>
values_sm;
184 template <
typename Number>
186 swap(MemorySpaceData<Number, CUDA> &u, MemorySpaceData<Number, CUDA> &v)
188 std::swap(u.values, v.values);
189 std::swap(u.values_dev, v.values_dev);
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define AssertCuda(error_code)
void swap(MemorySpaceData< Number, MemorySpace > &, MemorySpaceData< Number, MemorySpace > &)
void delete_device_data(Number *device_ptr) noexcept
std::unique_ptr< Number[]> values_dev
std::unique_ptr< Number[], std::function< void(Number *)> > values
void copy_from(Number *begin, std::size_t n_elements)
void copy_to(Number *begin, std::size_t n_elements)
std::vector< ArrayView< const Number > > values_sm