Vector Optimized Library of Kernels  3.2.0
Architecture-tuned implementations of math kernels
volk_test.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2022 Johannes Demel
4  *
5  * This file is part of VOLK
6  *
7  * SPDX-License-Identifier: LGPL-3.0-or-later
8  */
9 
10 #include <fmt/core.h>
11 #include <fmt/ranges.h>
12 #include <gtest/gtest.h>
13 #include <volk/volk.h>
14 #include <array>
15 #include <tuple>
16 
17 static constexpr std::array<size_t, 5> default_vector_sizes{ 7, 32, 128, 1023, 131071 };
18 
19 std::vector<std::string> get_kernel_implementation_name_list(const volk_func_desc_t desc);
20 
21 bool is_aligned_implementation_name(const std::string& name);
22 
23 std::tuple<std::vector<std::string>, std::vector<std::string>>
24 separate_implementations_by_alignment(const std::vector<std::string>& names);
25 
26 std::vector<std::string>
28 std::vector<std::string>
30 
32  template <class ParamType>
33  std::string operator()(const ::testing::TestParamInfo<ParamType>& info) const
34  {
35  return fmt::format("{}_{}", std::get<0>(info.param), std::get<1>(info.param));
36  }
37 };
38 
39 class VolkTest : public ::testing::TestWithParam<std::tuple<std::string, size_t>>
40 {
41 protected:
42  void initialize_test(const std::tuple<std::string, size_t>& param)
43  {
44  std::tie(implementation_name, vector_length) = param;
46  }
47 
48  std::string implementation_name;
50  size_t vector_length;
51 };
52 
53 
54 template <class T>
55 ::testing::AssertionResult AreComplexFloatingPointArraysAlmostEqual(const T& expected,
56  const T& actual)
57 {
58  ::testing::AssertionResult result = ::testing::AssertionFailure();
59  if (expected.size() != actual.size()) {
60  return result << "expected result size=" << expected.size()
61  << " differs from actual size=" << actual.size();
62  }
63  const unsigned long length = expected.size();
64 
65  int errorsFound = 0;
66  const char* separator = " ";
67  for (unsigned long index = 0; index < length; index++) {
68  auto expected_real = ::testing::internal::FloatingPoint(expected[index].real());
69  auto expected_imag = ::testing::internal::FloatingPoint(expected[index].imag());
70  auto actual_real = ::testing::internal::FloatingPoint(actual[index].real());
71  auto actual_imag = ::testing::internal::FloatingPoint(actual[index].imag());
72  if (not expected_real.AlmostEquals(actual_real) or
73  not expected_imag.AlmostEquals(actual_imag))
74 
75  {
76  if (errorsFound == 0) {
77  result << "Differences found:";
78  }
79  if (errorsFound < 3) {
80  result << separator << expected[index] << " != " << actual[index] << " @ "
81  << index;
82  separator = ",\n";
83  }
84  errorsFound++;
85  }
86  }
87  if (errorsFound > 0) {
88  result << separator << errorsFound << " differences in total";
89  return result;
90  }
91  return ::testing::AssertionSuccess();
92 }
Definition: volk_test.h:40
void initialize_test(const std::tuple< std::string, size_t > &param)
Definition: volk_test.h:42
std::string implementation_name
Definition: volk_test.h:48
bool is_aligned_implementation
Definition: volk_test.h:49
size_t vector_length
Definition: volk_test.h:50
name
Definition: volk_arch_defs.py:56
Definition: volk_test.h:31
std::string operator()(const ::testing::TestParamInfo< ParamType > &info) const
Definition: volk_test.h:33
__VOLK_DECL_BEGIN struct volk_func_desc volk_func_desc_t
Get description parameters for this kernel.
Definition: volk.tmpl.h:91
std::vector< std::string > get_unaligned_kernel_implementation_names(const volk_func_desc_t desc)
Definition: volk_test.cc:97
bool is_aligned_implementation_name(const std::string &name)
Definition: volk_test.cc:68
::testing::AssertionResult AreComplexFloatingPointArraysAlmostEqual(const T &expected, const T &actual)
Definition: volk_test.h:55
std::vector< std::string > get_kernel_implementation_name_list(const volk_func_desc_t desc)
Definition: volk_test.cc:58
static constexpr std::array< size_t, 5 > default_vector_sizes
Definition: volk_test.h:17
std::tuple< std::vector< std::string >, std::vector< std::string > > separate_implementations_by_alignment(const std::vector< std::string > &names)
Definition: volk_test.cc:74
std::vector< std::string > get_aligned_kernel_implementation_names(const volk_func_desc_t desc)
Definition: volk_test.cc:89