File: volk_test.cc

package info (click to toggle)
volk 3.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,916 kB
  • sloc: ansic: 40,447; cpp: 2,005; asm: 918; python: 897; xml: 375; sh: 157; makefile: 14
file content (102 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* -*- c++ -*- */
/*
 * Copyright 2022 Johannes Demel
 *
 * This file is part of VOLK
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <fmt/core.h>
#include <fmt/ranges.h>
#include <gtest/gtest.h>
#include <volk/volk.h>
#include <algorithm>
#include <tuple>


template <class T>
::testing::AssertionResult AreComplexFloatingPointArraysAlmostEqual(const T& expected,
                                                                    const T& actual)
{
    ::testing::AssertionResult result = ::testing::AssertionFailure();
    if (expected.size() != actual.size()) {
        return result << "expected result size=" << expected.size()
                      << " differs from actual size=" << actual.size();
    }
    const unsigned long length = expected.size();

    int errorsFound = 0;
    const char* separator = " ";
    for (unsigned long index = 0; index < length; index++) {
        auto expected_real = ::testing::internal::FloatingPoint(expected[index].real());
        auto expected_imag = ::testing::internal::FloatingPoint(expected[index].imag());
        auto actual_real = ::testing::internal::FloatingPoint(actual[index].real());
        auto actual_imag = ::testing::internal::FloatingPoint(actual[index].imag());
        if (not expected_real.AlmostEquals(actual_real) or
            not expected_imag.AlmostEquals(actual_imag))

        {
            if (errorsFound == 0) {
                result << "Differences found:";
            }
            if (errorsFound < 3) {
                result << separator << expected[index] << " != " << actual[index] << " @ "
                       << index;
                separator = ",\n";
            }
            errorsFound++;
        }
    }
    if (errorsFound > 0) {
        result << separator << errorsFound << " differences in total";
        return result;
    }
    return ::testing::AssertionSuccess();
}

std::vector<std::string> get_kernel_implementation_name_list(const volk_func_desc_t desc)
{
    std::vector<std::string> names;
    for (size_t i = 0; i < desc.n_impls; i++) {
        names.push_back(std::string(desc.impl_names[i]));
    }
    std::sort(names.begin(), names.end());
    return names;
}

bool is_aligned_implementation_name(const std::string& name)
{
    return name.rfind("a_", 0) == 0;
}

std::tuple<std::vector<std::string>, std::vector<std::string>>
separate_implementations_by_alignment(const std::vector<std::string>& names)
{
    std::vector<std::string> aligned;
    std::vector<std::string> unaligned;
    for (auto name : names) {
        if (is_aligned_implementation_name(name)) {
            aligned.push_back(name);
        } else {
            unaligned.push_back(name);
        }
    }
    return { aligned, unaligned };
}

std::vector<std::string>
get_aligned_kernel_implementation_names(const volk_func_desc_t desc)
{
    auto impls = get_kernel_implementation_name_list(desc);
    auto [aligned, unaligned] = separate_implementations_by_alignment(impls);
    return aligned;
}

std::vector<std::string>
get_unaligned_kernel_implementation_names(const volk_func_desc_t desc)
{
    auto impls = get_kernel_implementation_name_list(desc);
    auto [aligned, unaligned] = separate_implementations_by_alignment(impls);
    return unaligned;
}