From: Daniel Arndt Date: Tue, 4 Sep 2018 00:19:27 +0000 (+0200) Subject: Add asserts and swap functions X-Git-Tag: v9.1.0-rc1~754^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00950189c5f9bda0d56203de33f7fee72095f228;p=dealii.git Add asserts and swap functions --- 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 }