]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Better guard CUDA code 7057/head
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 13 Aug 2018 14:41:30 +0000 (14:41 +0000)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 13 Aug 2018 18:01:02 +0000 (18:01 +0000)
Use __CUDACC__ guard around CUDA to make sure that the CUDA code is only sent to
nvcc and not the host compiler when CUDA support is enable.

14 files changed:
include/deal.II/base/cuda.h
include/deal.II/base/numbers.h
include/deal.II/lac/cuda_atomic.h
include/deal.II/lac/cuda_kernels.h
include/deal.II/lac/cuda_kernels.templates.h
include/deal.II/lac/cuda_solver_direct.h
include/deal.II/lac/cuda_sparse_matrix.h
include/deal.II/lac/read_write_vector.templates.h
include/deal.II/matrix_free/cuda_fe_evaluation.h
include/deal.II/matrix_free/cuda_hanging_nodes_internal.h
include/deal.II/matrix_free/cuda_matrix_free.h
include/deal.II/matrix_free/cuda_matrix_free.templates.h
include/deal.II/matrix_free/cuda_tensor_product_kernels.h
tests/all-headers/CMakeLists.txt

index 7f9ad5f759bf67946c1db45288cf481777eef856..fa26cacf2add0087c4fbe89ae7b2722f6060d033 100644 (file)
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_WITH_CUDA
-
-#  include <deal.II/base/exceptions.h>
+#include <deal.II/base/exceptions.h>
 
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 #  include <cusolverDn.h>
 #  include <cusolverSp.h>
 #  include <cusparse.h>
+#endif
 
-#  include <vector>
+#include <vector>
 
 DEAL_II_NAMESPACE_OPEN
 namespace Utilities
@@ -58,6 +58,7 @@ namespace Utilities
        */
       ~Handle();
 
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
       cusolverDnHandle_t cusolver_dn_handle;
 
       cusolverSpHandle_t cusolver_sp_handle;
@@ -66,6 +67,7 @@ namespace Utilities
        * Handle to the cuSPARSE library.
        */
       cusparseHandle_t cusparse_handle;
+#endif
     };
 
     /**
@@ -75,9 +77,14 @@ namespace Utilities
     inline void
     malloc(T *&pointer, const unsigned int n_elements)
     {
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
       cudaError_t cuda_error_code =
         cudaMalloc(&pointer, n_elements * sizeof(T));
       AssertCuda(cuda_error_code);
+#else
+      (void)pointer;
+      (void)n_elements;
+#endif
     }
 
     /**
@@ -87,9 +94,13 @@ namespace Utilities
     inline void
     free(T *&pointer)
     {
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
       cudaError_t cuda_error_code = cudaFree(pointer);
       AssertCuda(cuda_error_code);
       pointer = nullptr;
+#else
+      (void)pointer;
+#endif
     }
 
     /**
@@ -99,11 +110,16 @@ namespace Utilities
     inline void
     copy_to_host(const T *pointer_dev, std::vector<T> &vector_host)
     {
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
       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
     }
 
     /**
@@ -114,11 +130,16 @@ namespace Utilities
     inline void
     copy_to_dev(const std::vector<T> &vector_host, T *pointer_dev)
     {
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
       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
@@ -126,5 +147,3 @@ namespace Utilities
 DEAL_II_NAMESPACE_CLOSE
 
 #endif
-
-#endif
index 5123c9ed127470d18d6582420bf36caaf90a5f2f..1bc05e63452f1625ca50ce948128beb9b30d8194 100644 (file)
@@ -25,8 +25,7 @@
 #include <complex>
 #include <cstdlib>
 
-#ifdef DEAL_II_WITH_CUDA
-#  include <cuda_runtime_api.h>
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 #  define DEAL_II_CUDA_HOST_DEV __host__ __device__
 #else
 #  define DEAL_II_CUDA_HOST_DEV
index f018365923347b84e1151a755421141c13a215ee..e717b633b915ecf708d46f0c88215c8e3ec40628 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 
 DEAL_II_NAMESPACE_OPEN
 
index 2e29e06b39ffef556820f04a714b0d3267f1b5df..367df1c0815242865ac7f079d2174e3934b9ab0c 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 
 
 #  include <deal.II/base/cuda_size.h>
index 8ae0e51ab7b09aa18b31af7748a07e2dfc076961..81d8ef9bcf7208534cda830a948e5f7543be345d 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <deal.II/lac/cuda_kernels.h>
 
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
+
 DEAL_II_NAMESPACE_OPEN
 
 namespace LinearAlgebra
@@ -573,3 +575,5 @@ namespace LinearAlgebra
 DEAL_II_NAMESPACE_CLOSE
 
 #endif
+
+#endif
index 2a4956918caaaa54537e1385af99cf1d7926e61f..493a70e9f11628a3377dbe603a792f30687b940a 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 #  include <deal.II/base/cuda.h>
 
 #  include <deal.II/lac/cuda_sparse_matrix.h>
index 60ff84d7d2d4f514908e1e48ffe88ecfd7280578..0be2bf0e8285e7fed00e2054bfc261014973d7be 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <deal.II/base/subscriptor.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 #  include <deal.II/base/cuda.h>
 
 #  include <deal.II/lac/cuda_vector.h>
index c5792d876d0c6ca3b57f5530ca5c7eb2001e1afb..0b6f003b21360bc76f39f642ebc80728c29dbbfa 100644 (file)
@@ -40,7 +40,7 @@
 #  include <Epetra_Import.h>
 #endif
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA)
 #  include <deal.II/lac/cuda_vector.h>
 
 #  include <cuda_runtime_api.h>
@@ -568,7 +568,7 @@ namespace LinearAlgebra
 
 
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA)
   template <typename Number>
   void
   ReadWriteVector<Number>::import(
index 08d6e1c83fdbb49e8da4f2c39012250cf56ca5a4..2f7c46a76657016c39858a42d836e0a58b573e8c 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 
 #  include <deal.II/base/tensor.h>
 #  include <deal.II/base/utilities.h>
index 39a8589535e00ef7a9ebab71e9829dc40e232c6e..f9ee32cc690bb60f5ca666e733cd4b5167c03e7f 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 
 #  include <deal.II/base/utilities.h>
 
index c790337846fb995d34139ad7d1b4ea13eb7ce159..0bc0dacf570a737927cc9ee8c2af229d5aa9a106 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <deal.II/base/config.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 
 #  include <deal.II/base/quadrature.h>
 #  include <deal.II/base/tensor.h>
@@ -33,8 +33,6 @@
 #  include <deal.II/lac/affine_constraints.h>
 #  include <deal.II/lac/cuda_vector.h>
 
-#  include <cuda_runtime_api.h>
-
 
 DEAL_II_NAMESPACE_OPEN
 
index c9615aef3eabd129c2b126ec40d58a3a427b7d88..a227dff179960b0b299f1e88e2df076d57ad16ff 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <deal.II/matrix_free/cuda_matrix_free.h>
 
-#ifdef DEAL_II_WITH_CUDA
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 
 #  include <deal.II/base/cuda_size.h>
 #  include <deal.II/base/graph_coloring.h>
index ef39036149606e568a894efe185087d7eb4d0585..e1232ad56d8bc833713d46b4f775375697dfb932 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <deal.II/base/config.h>
 
+#if defined(DEAL_II_WITH_CUDA) && defined(__CUDACC__)
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -439,3 +440,5 @@ namespace CUDAWrappers
 DEAL_II_NAMESPACE_CLOSE
 
 #endif
+
+#endif
index 3b5e51b6e0c88dc97ba4dc08a91922e8b7d60147..68cb3c16091578767cad7802a22013124e3bf94f 100644 (file)
@@ -45,17 +45,6 @@ FILE(GLOB_RECURSE _headers RELATIVE ${_include_dir}/deal.II
   ${_include_dir}/deal.II/*.h
   )
 
-#
-# Files that contain CUDA code cannot be sent to the host compiler so we removed
-# them from the list
-#
-LIST(REMOVE_ITEM _headers "lac/cuda_atomic.h"
-  "lac/cuda_kernels.h"
-  "lac/cuda_kernels.templates.h"
-  "matrix_free/cuda_fe_evaluation.h"
-  "matrix_free/cuda_hanging_nodes_internal.h"
-  "matrix_free/cuda_matrix_free.templates.h"
-  "matrix_free/cuda_tensor_product_kernels.h")
 
 # Do not test bundled headers to avoid issues when tests are run
 # for an already installed library

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.