]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid DEAL_II_COMPILER_CUDA_AWARE inside objects 7353/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 15 Oct 2018 21:13:40 +0000 (23:13 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 15 Oct 2018 21:13:40 +0000 (23:13 +0200)
include/deal.II/base/cuda.h
include/deal.II/base/memory_space.h
include/deal.II/lac/cuda_precondition.h

index 51b60e7a3bb8bd17ad26b069733c6d5b41ebb1e0..ad74e992849dbb461ee541ad330cba319f3d7076 100644 (file)
@@ -24,9 +24,8 @@
 #  include <cusolverDn.h>
 #  include <cusolverSp.h>
 #  include <cusparse.h>
-#endif
 
-#include <vector>
+#  include <vector>
 
 DEAL_II_NAMESPACE_OPEN
 namespace Utilities
@@ -58,7 +57,6 @@ namespace Utilities
        */
       ~Handle();
 
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
       cusolverDnHandle_t cusolver_dn_handle;
 
       cusolverSpHandle_t cusolver_sp_handle;
@@ -67,7 +65,6 @@ namespace Utilities
        * Handle to the cuSPARSE library.
        */
       cusparseHandle_t cusparse_handle;
-#endif
     };
 
     /**
@@ -77,14 +74,9 @@ namespace Utilities
     inline void
     malloc(T *&pointer, const unsigned int n_elements)
     {
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
       cudaError_t cuda_error_code =
         cudaMalloc(&pointer, n_elements * sizeof(T));
       AssertCuda(cuda_error_code);
-#else
-      (void)pointer;
-      (void)n_elements;
-#endif
     }
 
     /**
@@ -94,13 +86,9 @@ namespace Utilities
     inline void
     free(T *&pointer)
     {
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
       cudaError_t cuda_error_code = cudaFree(pointer);
       AssertCuda(cuda_error_code);
       pointer = nullptr;
-#else
-      (void)pointer;
-#endif
     }
 
     /**
@@ -110,17 +98,9 @@ namespace Utilities
     Number *
     allocate_device_data(const std::size_t size)
     {
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
       Number *device_ptr;
       Utilities::CUDA::malloc(device_ptr, size);
       return device_ptr;
-#else
-      (void)size;
-      Assert(
-        false,
-        ExcMessage(
-          "This function can only be used if deal.II is built with CUDA support!"));
-#endif
     }
 
     /**
@@ -130,16 +110,8 @@ namespace Utilities
     void
     delete_device_data(Number *device_ptr) noexcept
     {
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
       const cudaError_t error_code = cudaFree(device_ptr);
       AssertNothrowCuda(error_code);
-#else
-      (void)device_ptr;
-      AssertNothrow(
-        false,
-        ExcMessage(
-          "This function can only be used if deal.II is built with CUDA support!"));
-#endif
     }
 
     /**
@@ -149,16 +121,11 @@ namespace Utilities
     inline void
     copy_to_host(const T *pointer_dev, std::vector<T> &vector_host)
     {
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
       cudaError_t cuda_error_code = cudaMemcpy(vector_host.data(),
                                                pointer_dev,
                                                vector_host.size() * sizeof(T),
                                                cudaMemcpyDeviceToHost);
       AssertCuda(cuda_error_code);
-#else
-      (void)pointer_dev;
-      (void)vector_host;
-#endif
     }
 
     /**
@@ -169,20 +136,15 @@ namespace Utilities
     inline void
     copy_to_dev(const std::vector<T> &vector_host, T *pointer_dev)
     {
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
       cudaError_t cuda_error_code = cudaMemcpy(pointer_dev,
                                                vector_host.data(),
                                                vector_host.size() * sizeof(T),
                                                cudaMemcpyHostToDevice);
       AssertCuda(cuda_error_code);
-#else
-      (void)vector_host;
-      (void)pointer_dev;
-#endif
     }
   } // namespace CUDA
 } // namespace Utilities
 
 DEAL_II_NAMESPACE_CLOSE
-
+#endif
 #endif
index f67b50cf5c5c08b895360e3049876e3c0e24c829..7cc0a7fe932d7ae795255e4ab3881b7b7671f6da 100644 (file)
@@ -47,24 +47,6 @@ namespace MemorySpace
 
 
 
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
-  /**
-   * Deleter for unique/shared pointer pointing to an array allocated on the
-   * device.
-   */
-  template <typename Number>
-  void
-  deleter_device_array(Number *ptr) noexcept
-  {
-    const cudaError_t cuda_error_code = cudaFree(ptr);
-    (void)cuda_error_code;
-    AssertNothrow(cuda_error_code == cudaSuccess,
-                  ExcCudaError(cudaGetErrorString(cuda_error_code)));
-  }
-#endif
-
-
-
   /**
    * Data structure
    */
@@ -172,7 +154,7 @@ namespace MemorySpace
   {
     MemorySpaceData()
       : values(nullptr, &free)
-      , values_dev(nullptr, deleter_device_array<Number>)
+      , values_dev(nullptr, Utilities::CUDA::delete_device_data<Number>)
     {}
 
     void
index 3854535270df145b9e71d3755821a47e3ddef4f3..480188bae8d9008fe05bd2ec5a9da0670895cf0f 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <memory>
 
-#ifdef DEAL_II_WITH_CUDA
+#ifdef DEAL_II_COMPILER_CUDA_AWARE
 
 DEAL_II_NAMESPACE_OPEN
 

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.