From: Peter Munch Date: Tue, 1 Sep 2020 17:17:27 +0000 (+0200) Subject: Make MemorySpaceData virtual X-Git-Tag: v9.3.0-rc1~1148^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10873%2Fhead;p=dealii.git Make MemorySpaceData virtual --- diff --git a/include/deal.II/base/memory_space.h b/include/deal.II/base/memory_space.h index c4841e00b3..8a475d320c 100644 --- a/include/deal.II/base/memory_space.h +++ b/include/deal.II/base/memory_space.h @@ -22,6 +22,7 @@ #include #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -63,7 +64,7 @@ namespace MemorySpace * 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; @@ -74,7 +75,7 @@ namespace MemorySpace * 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; @@ -84,7 +85,7 @@ namespace MemorySpace /** * Pointer to data on the host. */ - std::unique_ptr values; + std::unique_ptr> values; /** * Pointer to data on the device. @@ -116,19 +117,19 @@ namespace MemorySpace : 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 values; + std::unique_ptr> values; // This is not used but it allows to simplify the code until we start using // CUDA-aware MPI. @@ -156,7 +157,7 @@ namespace MemorySpace , values_dev(nullptr, Utilities::CUDA::delete_device_data) {} - void + virtual void copy_to(Number *begin, std::size_t n_elements) { const cudaError_t cuda_error_code = @@ -167,7 +168,7 @@ namespace MemorySpace AssertCuda(cuda_error_code); } - void + virtual void copy_from(Number *begin, std::size_t n_elements) { const cudaError_t cuda_error_code = @@ -178,8 +179,8 @@ namespace MemorySpace AssertCuda(cuda_error_code); } - std::unique_ptr values; - std::unique_ptr values_dev; + std::unique_ptr> values; + std::unique_ptr values_dev; }; diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index e916e86fcd..d406a1610a 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -141,7 +141,7 @@ namespace LinearAlgebra reinterpret_cast(&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; } @@ -852,7 +852,7 @@ namespace LinearAlgebra 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(), @@ -1030,7 +1030,7 @@ namespace LinearAlgebra 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(),