]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Only use Kokkos::Array with Kokkos 3.7 or newer
authorBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 25 Oct 2024 19:46:46 +0000 (15:46 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 25 Oct 2024 19:55:15 +0000 (15:55 -0400)
cmake/modules/FindDEAL_II_KOKKOS.cmake
include/deal.II/base/tensor.h

index 02de0a98c16487b1e489e02a3690ed2f0d36dd94..e639a8b25c21f74551e0e0e2f4d9821e11379c0b 100644 (file)
@@ -47,6 +47,15 @@ endif()
 
 
 if(Kokkos_FOUND)
+  if (Kokkos_ENABLE_CUDA OR Kokkos_ENABLE_HIP)
+    # In version older than 3.7.0, Kokkos::Array::operator[] is not constexpr,
+    # so we use std::array instead.
+    if (KOKKOS_VERSION VERSION_LESS 3.7.0)
+      # We are using std::array in device code which calls the host-only function
+      # __glibcxx_requires_subscript when defining _GLIBCXX_ASSERTIONS 
+      list(REMOVE_ITEM DEAL_II_DEFINITIONS_DEBUG "_GLIBCXX_ASSERTIONS")
+    endif()
+  endif()
   if(Kokkos_ENABLE_CUDA)
     # We need to disable SIMD vectorization for CUDA device code.
     # Otherwise, nvcc compilers from version 9 on will emit an error message like:
@@ -60,10 +69,6 @@ if(Kokkos_FOUND)
     # __host__ constexpr functions in device code
     KOKKOS_CHECK(OPTIONS CUDA_LAMBDA CUDA_CONSTEXPR)
 
-    # We are using std::array in device code which calls the host-only function
-    # __glibcxx_requires_subscript when defining _GLIBCXX_ASSERTIONS 
-    list(REMOVE_ITEM DEAL_II_DEFINITIONS_DEBUG "_GLIBCXX_ASSERTIONS")
-
     # Disable a bunch of annoying warnings generated by boost, template code,
     # and in other random places:
     #
index cd0b06b7ed64c693a7ec48ef23931033cdb4ae43..40ba24ba1c48f1e1aedf62d29771f0f58d3383e5 100644 (file)
@@ -24,7 +24,7 @@
 #include <deal.II/base/template_constraints.h>
 #include <deal.II/base/tensor_accessors.h>
 
-#include <Kokkos_Core.hpp>
+#include <Kokkos_Array.hpp>
 
 #ifdef DEAL_II_WITH_ADOLC
 #  include <adolc/adouble.h> // Taped double
@@ -839,9 +839,15 @@ private:
    * a rank-1 tensor, then we simply need an array of scalars.
    * Otherwise, it is an array of tensors one rank lower.
    */
+#if KOKKOS_VERSION >= 30700
   std::conditional_t<rank_ == 1,
                      Kokkos::Array<Number, dim>,
                      Kokkos::Array<Tensor<rank_ - 1, dim, Number>, dim>>
+#else
+  std::conditional_t<rank_ == 1,
+                     std::array<Number, dim>,
+                     std::array<Tensor<rank_ - 1, dim, Number>, dim>>
+#endif
     values;
 
   /**
@@ -1257,7 +1263,7 @@ Tensor<rank_, dim, Number>::Tensor()
       // brace-enclosed list of length 'dim'. There is no way in C++ to create
       // such a list in-place, but we can come up with a lambda function that
       // expands such a list via template-pack expansion, and then uses this
-      // list to initialize a Kokkos:Array which it then returns.
+      // list to initialize a Kokkos::Array which it then returns.
       //
       // The trick to come up with such a lambda function is to have a function
       // that takes an argument that depends on a template-pack of integers.
@@ -1319,7 +1325,11 @@ namespace internal
   namespace TensorInitialization
   {
     template <int rank, int dim, typename Number, std::size_t... I>
+#    if KOKKOS_VERSION >= 30700
     constexpr Kokkos::Array<typename Tensor<rank, dim, Number>::value_type, dim>
+#    else
+    constexpr std::array<typename Tensor<rank, dim, Number>::value_type, dim>
+#    endif
     make_zero_array(const std::index_sequence<I...> &)
     {
       static_assert(sizeof...(I) == dim, "This is bad.");

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.