#include <deal.II/base/cuda.h>
#include <deal.II/base/exceptions.h>
+#include <functional>
#include <memory>
DEAL_II_NAMESPACE_OPEN
* Copy the active data (values for Host and values_dev for CUDA) to @p begin.
* If the data is on the device it is moved to the host.
*/
- void
+ virtual void
copy_to(Number *begin, std::size_t n_elements)
{
(void)begin;
* Copy the data in @p begin to the active data of the structure (values for
* Host and values_dev for CUDA). The pointer @p begin must be on the host.
*/
- void
+ virtual void
copy_from(Number *begin, std::size_t n_elements)
{
(void)begin;
/**
* Pointer to data on the host.
*/
- std::unique_ptr<Number[], decltype(&std::free)> values;
+ std::unique_ptr<Number[], std::function<void(Number *)>> values;
/**
* Pointer to data on the device.
: values(nullptr, &std::free)
{}
- void
+ virtual void
copy_to(Number *begin, std::size_t n_elements)
{
std::copy(values.get(), values.get() + n_elements, begin);
}
- void
+ virtual void
copy_from(Number *begin, std::size_t n_elements)
{
std::copy(begin, begin + n_elements, values.get());
}
- std::unique_ptr<Number[], decltype(&std::free)> values;
+ std::unique_ptr<Number[], std::function<void(Number *)>> values;
// This is not used but it allows to simplify the code until we start using
// CUDA-aware MPI.
, values_dev(nullptr, Utilities::CUDA::delete_device_data<Number>)
{}
- void
+ virtual void
copy_to(Number *begin, std::size_t n_elements)
{
const cudaError_t cuda_error_code =
AssertCuda(cuda_error_code);
}
- void
+ virtual void
copy_from(Number *begin, std::size_t n_elements)
{
const cudaError_t cuda_error_code =
AssertCuda(cuda_error_code);
}
- std::unique_ptr<Number[], decltype(&std::free)> values;
- std::unique_ptr<Number[], void (*)(Number *)> values_dev;
+ std::unique_ptr<Number[], std::function<void(Number *)>> values;
+ std::unique_ptr<Number[], void (*)(Number *)> values_dev;
};
reinterpret_cast<void **>(&new_val),
64,
sizeof(Number) * new_alloc_size);
- data.values.reset(new_val);
+ data.values = {new_val, [](Number *data) { std::free(data); }};
allocated_size = new_alloc_size;
}
64,
sizeof(Number) * allocated_size);
- data.values.reset(new_val);
+ data.values = {new_val, [](Number *data) { std::free(data); }};
cudaError_t cuda_error_code =
cudaMemcpy(data.values.get(),
64,
sizeof(Number) * allocated_size);
- data.values.reset(new_val);
+ data.values = {new_val, [](Number *data) { std::free(data); }};
cudaError_t cuda_error_code = cudaMemcpy(data.values.get(),
data.values_dev.get(),