]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix compiling with Sacado and CUDA
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 27 Feb 2019 10:45:57 +0000 (11:45 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 27 Feb 2019 21:38:37 +0000 (22:38 +0100)
include/deal.II/base/numbers.h
include/deal.II/differentiation/ad/sacado_number_types.h
source/base/tensor.cc

index 68bf74bef411a7306060130f29138d2640252ea6..fca6430fd267776f39a276b03a471d6aecaae3f2 100644 (file)
@@ -165,6 +165,15 @@ namespace numbers
    */
   static const double SQRT1_2 = 0.70710678118654752440;
 
+  /**
+   * Check whether the given type can be used in CUDA device code.
+   * If not, DEAL_II_CUDA_HOST_DEV needs to be disabled for functions
+   * that use this type.
+   */
+  template <typename Number, typename = void>
+  struct is_cuda_compatible : std::true_type
+  {};
+
   /**
    * Check whether a value is not a number.
    *
@@ -361,10 +370,21 @@ namespace numbers
      * general template is chosen for types not equal to std::complex, this
      * function simply returns the square of the given number.
      *
-     * @note This function can also be used in CUDA device code.
+     * @note If the template type can be used in CUDA device code, the same holds true
+     * for this function.
      */
-    static DEAL_II_CUDA_HOST_DEV real_type
-                                 abs_square(const number &x);
+    template <typename Dummy = number>
+    static DEAL_II_CUDA_HOST_DEV
+      typename std::enable_if<std::is_same<Dummy, number>::value &&
+                                is_cuda_compatible<Dummy>::value,
+                              real_type>::type
+      abs_square(const number &x);
+
+    template <typename Dummy = number>
+    static typename std::enable_if<std::is_same<Dummy, number>::value &&
+                                     !is_cuda_compatible<Dummy>::value,
+                                   real_type>::type
+    abs_square(const number &x);
 
     /**
      * Return the absolute value of a number.
@@ -423,12 +443,20 @@ namespace numbers
 
   // --------------- inline and template functions ---------------- //
 
+  template <typename Number>
+  struct is_cuda_compatible<std::complex<Number>, void> : std::false_type
+  {};
+
+
+
   inline bool
   is_nan(const double x)
   {
     return std::isnan(x);
   }
 
+
+
   inline bool
   is_finite(const double x)
   {
@@ -475,7 +503,23 @@ namespace numbers
 
 
   template <typename number>
-  DEAL_II_CUDA_HOST_DEV typename NumberTraits<number>::real_type
+  template <typename Dummy>
+  DEAL_II_CUDA_HOST_DEV
+    typename std::enable_if<std::is_same<Dummy, number>::value &&
+                              is_cuda_compatible<Dummy>::value,
+                            typename NumberTraits<number>::real_type>::type
+    NumberTraits<number>::abs_square(const number &x)
+  {
+    return x * x;
+  }
+
+
+
+  template <typename number>
+  template <typename Dummy>
+  typename std::enable_if<std::is_same<Dummy, number>::value &&
+                            !is_cuda_compatible<Dummy>::value,
+                          typename NumberTraits<number>::real_type>::type
   NumberTraits<number>::abs_square(const number &x)
   {
     return x * x;
index 8781865c5f40fa91bb325ab700e698c4a2b0bddf..907e830e1f0168eb782d04ce2f4d1c0d68b61f0f 100644 (file)
@@ -926,6 +926,17 @@ namespace Differentiation
   } // namespace AD
 } // namespace Differentiation
 
+
+namespace numbers
+{
+  template <typename NumberType>
+  struct is_cuda_compatible<
+    NumberType,
+    typename std::enable_if<dealii::Differentiation::AD::is_sacado_rad_number<
+      NumberType>::value>::type> : std::false_type
+  {};
+} // namespace numbers
+
 #  endif // DOXYGEN
 
 
index 15cb6f3b5dfec105e24c8a7e68c7d2ee3ff22877..43dabdad75c1dc583f6e9e8409d527a2bfb09e21 100644 (file)
@@ -19,6 +19,7 @@
 #include <deal.II/base/tensor.h>
 
 #include <deal.II/differentiation/ad/adolc_product_types.h>
+#include <deal.II/differentiation/ad/sacado_number_types.h>
 #include <deal.II/differentiation/ad/sacado_product_types.h>
 
 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.