17 #ifndef dealii_memory_space_h 18 #define dealii_memory_space_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/cuda.h> 23 #include <deal.II/base/exceptions.h> 27 DEAL_II_NAMESPACE_OPEN
53 template <
typename Number,
typename MemorySpace>
58 static_assert(std::is_same<MemorySpace, Host>::value ||
59 std::is_same<MemorySpace, CUDA>::value,
60 "MemorySpace should be Host or CUDA");
68 copy_to(Number *begin, std::size_t n_elements)
88 std::unique_ptr<Number[], decltype(&free)>
values;
101 template <
typename Number,
typename MemorySpace>
106 static_assert(std::is_same<MemorySpace, Host>::value ||
107 std::is_same<MemorySpace, CUDA>::value,
108 "MemorySpace should be Host or CUDA");
113 template <
typename Number>
114 struct MemorySpaceData<Number, Host>
121 copy_to(Number *begin, std::size_t n_elements)
123 std::copy(
values.get(),
values.get() + n_elements, begin);
127 copy_from(Number *begin, std::size_t n_elements)
129 std::copy(begin, begin + n_elements,
values.get());
132 std::unique_ptr<Number[], decltype(&free)>
values;
141 template <
typename Number>
143 swap(MemorySpaceData<Number, Host> &u, MemorySpaceData<Number, Host> &v)
150 # ifdef DEAL_II_COMPILER_CUDA_AWARE 152 template <
typename Number>
153 struct MemorySpaceData<Number, CUDA>
161 copy_to(Number *begin, std::size_t n_elements)
163 const cudaError_t cuda_error_code =
166 n_elements *
sizeof(Number),
167 cudaMemcpyDeviceToHost);
172 copy_from(Number *begin, std::size_t n_elements)
174 const cudaError_t cuda_error_code =
177 n_elements *
sizeof(Number),
178 cudaMemcpyHostToDevice);
182 std::unique_ptr<Number[], decltype(&free)>
values;
183 std::unique_ptr<Number[], void (*)(Number *)>
values_dev;
188 template <
typename Number>
190 swap(MemorySpaceData<Number, CUDA> &u, MemorySpaceData<Number, CUDA> &v)
202 DEAL_II_NAMESPACE_CLOSE
void copy_from(Number *begin, std::size_t n_elements)
#define AssertCuda(error_code)
std::unique_ptr< Number[], decltype(&free)> values
void swap(Vector< Number > &u, Vector< Number > &v)
void delete_device_data(Number *device_ptr) noexcept
void copy_to(Number *begin, std::size_t n_elements)
std::unique_ptr< Number[]> values_dev