From: peterrum Date: Sat, 20 Jul 2019 18:29:45 +0000 (+0200) Subject: Add new make_vectorized_array function X-Git-Tag: v9.2.0-rc1~1357^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc4042fd6eb33c20b3d33ea610fe9ea455dccfb9;p=dealii.git Add new make_vectorized_array function --- diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index 1e994fbd4a..c0406d6da5 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -521,6 +521,29 @@ inline DEAL_II_ALWAYS_INLINE VectorizedArray +/** + * Create a vectorized array of given type and broadcast the scalar value + * to all array elements. + * + * @relatesalso VectorizedArray + */ +template +inline DEAL_II_ALWAYS_INLINE VectorizedArrayType + make_vectorized_array(const typename VectorizedArrayType::value_type &u) +{ + static_assert( + std::is_same>::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 index 0000000000..9067b826ba --- /dev/null +++ b/tests/base/vectorization_make_vectorized_array_01.cc @@ -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 + +#include + +#include "../tests.h" + + +template +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 +struct Tester +{ + static void + test() + {} +}; + +template <> +struct Tester +{ + static void + test() + { + do_test(make_vectorized_array(2.0), 2.0); + +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__AVX512F__) + do_test(make_vectorized_array>(2.0), 2.0); +#endif + +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__AVX__) + do_test(make_vectorized_array>(2.0), 2.0); +#endif + +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__) + do_test(make_vectorized_array>(2.0), 2.0); +#endif + + do_test(make_vectorized_array>(2.0), 2.0); + } +}; + +template <> +struct Tester +{ + static void + test() + { + do_test(make_vectorized_array(2.0), 2.0); + +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__AVX512F__) + do_test(make_vectorized_array>(2.0), 2.0); +#endif + +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__AVX__) + do_test(make_vectorized_array>(2.0), 2.0); +#endif + +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__) + do_test(make_vectorized_array>(2.0), 2.0); +#endif + + do_test(make_vectorized_array>(2.0), 2.0); + } +}; + + +int +main() +{ + initlog(); + + deallog << "double:" << std::endl; + Tester::test(); + + deallog << "float:" << std::endl; + Tester::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 index 0000000000..bb0c0e3cbe --- /dev/null +++ b/tests/base/vectorization_make_vectorized_array_01.output @@ -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 index 0000000000..4951c758d0 --- /dev/null +++ b/tests/base/vectorization_make_vectorized_array_01.output.avx @@ -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 index 0000000000..225e32e773 --- /dev/null +++ b/tests/base/vectorization_make_vectorized_array_01.output.avx512 @@ -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 index 0000000000..fffb0c67e3 --- /dev/null +++ b/tests/base/vectorization_make_vectorized_array_01.output.sse2 @@ -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