]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add asserts and swap functions
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 4 Sep 2018 00:19:27 +0000 (02:19 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 4 Sep 2018 13:51:30 +0000 (15:51 +0200)
include/deal.II/base/cuda.h

index e701af54e4d602968a5e82254af375f764269ac9..51b60e7a3bb8bd17ad26b069733c6d5b41ebb1e0 100644 (file)
@@ -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 <typename Number>
-    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 <typename Number>
-    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
     }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.