]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add new make_vectorized_array function 8400/head
authorpeterrum <peterrmuench@gmail.com>
Sat, 20 Jul 2019 18:29:45 +0000 (20:29 +0200)
committerpeterrum <peterrmuench@gmail.com>
Tue, 23 Jul 2019 19:01:54 +0000 (21:01 +0200)
include/deal.II/base/vectorization.h
tests/base/vectorization_make_vectorized_array_01.cc [new file with mode: 0644]
tests/base/vectorization_make_vectorized_array_01.output [new file with mode: 0644]
tests/base/vectorization_make_vectorized_array_01.output.avx [new file with mode: 0644]
tests/base/vectorization_make_vectorized_array_01.output.avx512 [new file with mode: 0644]
tests/base/vectorization_make_vectorized_array_01.output.sse2 [new file with mode: 0644]

index 1e994fbd4add49a96f17dc9c1ae4673298e9a5af..c0406d6da522d4bc376bca0157be5e09ce6fcb6c 100644 (file)
@@ -521,6 +521,29 @@ inline DEAL_II_ALWAYS_INLINE VectorizedArray<Number, width>
 
 
 
+/**
+ * Create a vectorized array of given type and broadcast the scalar value
+ * to all array elements.
+ *
+ *  @relatesalso VectorizedArray
+ */
+template <typename VectorizedArrayType>
+inline DEAL_II_ALWAYS_INLINE VectorizedArrayType
+                             make_vectorized_array(const typename VectorizedArrayType::value_type &u)
+{
+  static_assert(
+    std::is_same<VectorizedArrayType,
+                 VectorizedArray<typename VectorizedArrayType::value_type,
+                                 VectorizedArrayType::n_array_elements>>::value,
+    "VectorizedArrayType is not a VectorizedArray.");
+
+  VectorizedArrayType result;
+  result = u;
+  return result;
+}
+
+
+
 /**
  * This method loads VectorizedArray::n_array_elements data streams from the
  * given array @p in. The offsets to the input array are given by the array @p
diff --git a/tests/base/vectorization_make_vectorized_array_01.cc b/tests/base/vectorization_make_vectorized_array_01.cc
new file mode 100644 (file)
index 0000000..9067b82
--- /dev/null
@@ -0,0 +1,107 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 - 2019 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// test make_vectorized_array function for all possible value_types and vector
+// lengths
+
+#include <deal.II/base/vectorization.h>
+
+#include <limits>
+
+#include "../tests.h"
+
+
+template <typename VectorizedArrayType>
+void
+do_test(const VectorizedArrayType                      array,
+        const typename VectorizedArrayType::value_type number)
+{
+  deallog << "  test " << VectorizedArrayType::n_array_elements
+          << " array elements" << std::endl;
+  for (unsigned int i = 0; i < VectorizedArrayType::n_array_elements; i++)
+    if (array[i] != number)
+      deallog << "  problem in element " << i << std::endl;
+}
+
+
+template <typename Number>
+struct Tester
+{
+  static void
+  test()
+  {}
+};
+
+template <>
+struct Tester<double>
+{
+  static void
+  test()
+  {
+    do_test(make_vectorized_array<double>(2.0), 2.0);
+
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__AVX512F__)
+    do_test(make_vectorized_array<VectorizedArray<double, 8>>(2.0), 2.0);
+#endif
+
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__AVX__)
+    do_test(make_vectorized_array<VectorizedArray<double, 4>>(2.0), 2.0);
+#endif
+
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__)
+    do_test(make_vectorized_array<VectorizedArray<double, 2>>(2.0), 2.0);
+#endif
+
+    do_test(make_vectorized_array<VectorizedArray<double, 1>>(2.0), 2.0);
+  }
+};
+
+template <>
+struct Tester<float>
+{
+  static void
+  test()
+  {
+    do_test(make_vectorized_array<float>(2.0), 2.0);
+
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__AVX512F__)
+    do_test(make_vectorized_array<VectorizedArray<float, 16>>(2.0), 2.0);
+#endif
+
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__AVX__)
+    do_test(make_vectorized_array<VectorizedArray<float, 8>>(2.0), 2.0);
+#endif
+
+#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__)
+    do_test(make_vectorized_array<VectorizedArray<float, 4>>(2.0), 2.0);
+#endif
+
+    do_test(make_vectorized_array<VectorizedArray<float, 1>>(2.0), 2.0);
+  }
+};
+
+
+int
+main()
+{
+  initlog();
+
+  deallog << "double:" << std::endl;
+  Tester<double>::test();
+
+  deallog << "float:" << std::endl;
+  Tester<float>::test();
+}
diff --git a/tests/base/vectorization_make_vectorized_array_01.output b/tests/base/vectorization_make_vectorized_array_01.output
new file mode 100644 (file)
index 0000000..bb0c0e3
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::double:
+DEAL::  test 1 array elements
+DEAL::  test 1 array elements
+DEAL::float:
+DEAL::  test 1 array elements
+DEAL::  test 1 array elements
diff --git a/tests/base/vectorization_make_vectorized_array_01.output.avx b/tests/base/vectorization_make_vectorized_array_01.output.avx
new file mode 100644 (file)
index 0000000..4951c75
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL::double:
+DEAL::  test 4 array elements
+DEAL::  test 4 array elements
+DEAL::  test 2 array elements
+DEAL::  test 1 array elements
+DEAL::float:
+DEAL::  test 8 array elements
+DEAL::  test 8 array elements
+DEAL::  test 4 array elements
+DEAL::  test 1 array elements
diff --git a/tests/base/vectorization_make_vectorized_array_01.output.avx512 b/tests/base/vectorization_make_vectorized_array_01.output.avx512
new file mode 100644 (file)
index 0000000..225e32e
--- /dev/null
@@ -0,0 +1,13 @@
+
+DEAL::double:
+DEAL::  test 8 array elements
+DEAL::  test 8 array elements
+DEAL::  test 4 array elements
+DEAL::  test 2 array elements
+DEAL::  test 1 array elements
+DEAL::float:
+DEAL::  test 16 array elements
+DEAL::  test 16 array elements
+DEAL::  test 8 array elements
+DEAL::  test 4 array elements
+DEAL::  test 1 array elements
diff --git a/tests/base/vectorization_make_vectorized_array_01.output.sse2 b/tests/base/vectorization_make_vectorized_array_01.output.sse2
new file mode 100644 (file)
index 0000000..fffb0c6
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::double:
+DEAL::  test 2 array elements
+DEAL::  test 2 array elements
+DEAL::  test 1 array elements
+DEAL::float:
+DEAL::  test 4 array elements
+DEAL::  test 4 array elements
+DEAL::  test 1 array elements

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.