From 00950189c5f9bda0d56203de33f7fee72095f228 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 4 Sep 2018 02:19:27 +0200 Subject: [PATCH] Add asserts and swap functions --- include/deal.II/base/cuda.h | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/include/deal.II/base/cuda.h b/include/deal.II/base/cuda.h index e701af54e4..51b60e7a3b 100644 --- a/include/deal.II/base/cuda.h +++ b/include/deal.II/base/cuda.h @@ -104,35 +104,41 @@ namespace Utilities } /** - * Deleter to be used for `std::unique_ptr` pointing to device memory. + * Allocator to be used for `std::unique_ptr` pointing to device memory. */ template - void - delete_device_data(Number *device_ptr) noexcept + Number * + allocate_device_data(const std::size_t size) { #ifdef DEAL_II_COMPILER_CUDA_AWARE - const cudaError_t error_code = cudaFree(device_ptr); - (void)error_code; - AssertNothrow(error_code == cudaSuccess, - dealii::ExcCudaError(cudaGetErrorString(error_code))); + Number *device_ptr; + Utilities::CUDA::malloc(device_ptr, size); + return device_ptr; #else - (void)device_ptr; + (void)size; + Assert( + false, + ExcMessage( + "This function can only be used if deal.II is built with CUDA support!")); #endif } /** - * Allocator to be used for `std::unique_ptr` pointing to device memory. + * Deleter to be used for `std::unique_ptr` pointing to device memory. */ template - Number * - allocate_device_data(const std::size_t size) + void + delete_device_data(Number *device_ptr) noexcept { #ifdef DEAL_II_COMPILER_CUDA_AWARE - Number *device_ptr; - Utilities::CUDA::malloc(device_ptr, size); - return device_ptr; + const cudaError_t error_code = cudaFree(device_ptr); + AssertNothrowCuda(error_code); #else - (void)size; + (void)device_ptr; + AssertNothrow( + false, + ExcMessage( + "This function can only be used if deal.II is built with CUDA support!")); #endif } -- 2.39.5