]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add configure check for altivec and enable it in vectorization.h
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 5 Oct 2018 16:22:17 +0000 (18:22 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 8 Oct 2018 06:30:56 +0000 (08:30 +0200)
cmake/checks/check_01_cpu_features.cmake
include/deal.II/base/vectorization.h

index 23793d3c77943e0a8fc5687478c7b6b60afdfa0f..5404df016c8c1540bfcee7070b60ec3bd53dfa1b 100644 (file)
@@ -27,6 +27,7 @@
 #   DEAL_II_HAVE_SSE2                    *)
 #   DEAL_II_HAVE_AVX                     *)
 #   DEAL_II_HAVE_AVX512                  *)
+#   DEAL_II_HAVE_ALTIVEC                 *)
 #   DEAL_II_COMPILER_VECTORIZATION_LEVEL
 #   DEAL_II_HAVE_OPENMP_SIMD             *)
 #   DEAL_II_OPENMP_SIMD_PRAGMA
@@ -72,7 +73,7 @@ IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
   # CMAKE_REQUIRED_FLAGS changes..
   #
   UNSET_IF_CHANGED(CHECK_CPU_FEATURES_FLAGS_SAVED "${CMAKE_REQUIRED_FLAGS}"
-    DEAL_II_HAVE_SSE2 DEAL_II_HAVE_AVX DEAL_II_HAVE_AVX512
+    DEAL_II_HAVE_SSE2 DEAL_II_HAVE_AVX DEAL_II_HAVE_AVX512 DEAL_II_HAVE_ALTIVEC
     )
 
   CHECK_CXX_SOURCE_RUNS(
@@ -202,6 +203,48 @@ IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
     }
     "
     DEAL_II_HAVE_AVX512)
+
+  CHECK_CXX_SOURCE_RUNS(
+    "
+    #ifndef __ALTIVEC__
+    #error \"__ALTIVEC__ flag not set, no support for Altivec\"
+    #endif
+    #include <altivec.h>
+    #undef vector
+    #undef pixel
+    #undef bool
+    int main()
+    {
+    __vector double a, b, data1, data2;
+    const int n_vectors = sizeof(a)/sizeof(double);
+    double * ptr = reinterpret_cast<double*>(&a);
+    ptr[0] = (volatile double)(1.0);
+    for (int i=1; i<n_vectors; ++i)
+      ptr[i] = 0.0;
+    b = vec_splats ((volatile double)(2.25));
+    data1 = vec_add (a, b);
+    data2 = vec_mul (b, data1);
+    ptr = reinterpret_cast<double*>(&data2);
+    unsigned int return_value = 0;
+    if (ptr[0] != 7.3125)
+      return_value += 1;
+    for (int i=1; i<n_vectors; ++i)
+      if (ptr[i] != 5.0625)
+        return_value += 2;
+    b = vec_splats ((volatile double)(-1.0));
+    data1 = vec_abs(vec_mul (b, data2));
+    vec_vsx_st(data1, 0, ptr);
+    b = vec_vsx_ld(0, ptr);
+    ptr = reinterpret_cast<double*>(&b);
+    if (ptr[0] != 7.3125)
+      return_value += 4;
+    for (int i=1; i<n_vectors; ++i)
+      if (ptr[i] != 5.0625)
+        return_value += 8;
+    return return_value;
+    }
+    "
+    DEAL_II_HAVE_ALTIVEC)
 ENDIF()
 
 IF(DEAL_II_HAVE_AVX512)
@@ -214,6 +257,10 @@ ELSE()
   SET(DEAL_II_COMPILER_VECTORIZATION_LEVEL 0)
 ENDIF()
 
+IF(DEAL_II_HAVE_ALTIVEC)
+  SET(DEAL_II_COMPILER_VECTORIZATION_LEVEL 1)
+ENDIF()
+
 
 #
 # OpenMP 4.0 can be used for vectorization. Only the vectorization
index 3780a9f3e06a1fa8c198e636bee4f57957ca3bc1..0da1de39bb3a12c099b94ad99eb065014eb66080 100644 (file)
 // 'check_01_cpu_features.cmake', ensures that these feature are not only
 // present in the compilation unit but also working properly.
 
-#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && !defined(__AVX__)
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__SSE2__) && \
+  !defined(__AVX__)
 #  error \
     "Mismatch in vectorization capabilities: AVX was detected during configuration of deal.II and switched on, but it is apparently not available for the file you are trying to compile at the moment. Check compilation flags controlling the instruction set, such as -march=native."
 #endif
-#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && !defined(__AVX512F__)
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__SSE2__) && \
+  !defined(__AVX512F__)
 #  error \
     "Mismatch in vectorization capabilities: AVX-512F was detected during configuration of deal.II and switched on, but it is apparently not available for the file you are trying to compile at the moment. Check compilation flags controlling the instruction set, such as -march=native."
 #endif
@@ -56,7 +58,7 @@
 #endif
 
 
-#ifdef __ALTIVEC__
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__ALTIVEC__)
 #  include <altivec.h>
 
 // altivec.h defines vector, pixel, bool, but we do not use them, so undefine
@@ -2190,10 +2192,7 @@ vectorized_transpose_and_store(const bool                    add_into,
 
 
 
-// for safety, also check that __SSE2__ is defined in case the user manually
-// set some conflicting compile flags which prevent compilation
-
-#elif DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1
+#elif DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__)
 
 /**
  * Specialization for double and SSE2.
@@ -2890,10 +2889,10 @@ vectorized_transpose_and_store(const bool                    add_into,
 
 
 
-#endif // if DEAL_II_COMPILER_VECTORIZATION_LEVEL > 0
+#endif // if DEAL_II_COMPILER_VECTORIZATION_LEVEL > 0 && defined(__SSE2__)
 
 
-#if defined(__ALTIVEC__) && defined(__VSX__)
+#if DEAL_II_VECTORIZATION_LEVEL >= 1 && defined(__ALTIVEC__) && defined(__VSX__)
 
 template <>
 class VectorizedArray<double>
@@ -3319,7 +3318,8 @@ private:
   std::min(const VectorizedArray<Number2> &, const VectorizedArray<Number2> &);
 };
 
-#endif // ALTIVEC && VSX
+#endif // if DEAL_II_VECTORIZATION_LEVEL >=1 && defined(__ALTIVEC__) &&
+       // defined(__VSX__)
 
 
 

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.