2020-06-21 19:10:22 +00:00
|
|
|
/*!
|
|
|
|
* \file benchmark_detector.cc
|
|
|
|
* \brief Benchmark for preamble detection implementations
|
|
|
|
* \author Carles Fernandez-Prades, 2020. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2020-06-21 19:10:22 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2020-06-21 19:10:22 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2020 (see AUTHORS file for a list of contributors)
|
2020-06-21 19:10:22 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2020-06-21 19:10:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GPS_L1_CA.h"
|
|
|
|
#include <benchmark/benchmark.h>
|
2020-06-29 08:13:07 +00:00
|
|
|
#include <algorithm> // for std::generate
|
2020-06-21 19:10:22 +00:00
|
|
|
#include <array>
|
2020-06-29 08:13:07 +00:00
|
|
|
#include <cmath> // std::for signbit
|
2020-06-21 19:10:22 +00:00
|
|
|
#include <cstdint>
|
2020-06-29 08:13:07 +00:00
|
|
|
#include <functional> // for std::plus
|
|
|
|
#include <numeric> // for std::accumulate, std::inner_product
|
2020-06-21 19:10:22 +00:00
|
|
|
#include <random>
|
|
|
|
#include <vector>
|
2020-07-01 21:05:33 +00:00
|
|
|
#if COMPILER_HAS_STD_TRANSFORM_REDUCE_WITH_POLICY
|
|
|
|
#include <execution>
|
|
|
|
#endif
|
2020-06-21 19:10:22 +00:00
|
|
|
|
|
|
|
void bm_forloop(benchmark::State& state)
|
|
|
|
{
|
|
|
|
std::vector<float> d_symbol_history(GPS_CA_PREAMBLE_LENGTH_SYMBOLS, 0.0);
|
2020-06-29 08:13:07 +00:00
|
|
|
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
|
2020-06-21 19:10:22 +00:00
|
|
|
|
|
|
|
// fill the inputs
|
|
|
|
std::random_device rd;
|
|
|
|
std::default_random_engine e2(rd());
|
|
|
|
std::uniform_real_distribution<> dist(-1.0, 1.0);
|
|
|
|
std::generate(d_symbol_history.begin(), d_symbol_history.end(), [&dist, &e2]() { return dist(e2); });
|
|
|
|
|
2020-06-29 08:13:07 +00:00
|
|
|
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE_SYMBOLS_STR[n++] == '1' ? 1 : -1); });
|
2020-06-21 19:10:22 +00:00
|
|
|
|
2024-10-06 06:14:46 +00:00
|
|
|
int32_t corr_value = 0;
|
2020-06-21 19:10:22 +00:00
|
|
|
while (state.KeepRunning())
|
|
|
|
{
|
2020-06-29 08:13:07 +00:00
|
|
|
for (size_t i = 0; i < d_preamble_samples.size(); i++)
|
2020-06-21 19:10:22 +00:00
|
|
|
{
|
|
|
|
if (d_symbol_history[i] < 0.0)
|
|
|
|
{
|
|
|
|
corr_value -= d_preamble_samples[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
corr_value += d_preamble_samples[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-06 06:14:46 +00:00
|
|
|
if (corr_value)
|
|
|
|
{
|
|
|
|
// avoidl warning
|
|
|
|
};
|
2020-06-21 19:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-24 11:59:50 +00:00
|
|
|
void bm_accumulate(benchmark::State& state)
|
2020-06-21 19:10:22 +00:00
|
|
|
{
|
|
|
|
std::vector<float> d_symbol_history(GPS_CA_PREAMBLE_LENGTH_SYMBOLS, 0.0);
|
2020-06-29 08:13:07 +00:00
|
|
|
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
|
2020-06-21 19:10:22 +00:00
|
|
|
|
|
|
|
// fill the inputs
|
|
|
|
std::random_device rd;
|
|
|
|
std::default_random_engine e2(rd());
|
|
|
|
std::uniform_real_distribution<> dist(-1.0, 1.0);
|
|
|
|
std::generate(d_symbol_history.begin(), d_symbol_history.end(), [&dist, &e2]() { return dist(e2); });
|
|
|
|
|
2020-06-29 08:13:07 +00:00
|
|
|
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE_SYMBOLS_STR[n++] == '1' ? 1 : -1); });
|
2020-06-21 19:10:22 +00:00
|
|
|
|
2024-10-06 06:14:46 +00:00
|
|
|
int32_t corr_value = 0;
|
2020-06-21 19:10:22 +00:00
|
|
|
while (state.KeepRunning())
|
|
|
|
{
|
|
|
|
corr_value += std::accumulate(d_symbol_history.begin(),
|
2020-06-29 08:13:07 +00:00
|
|
|
d_symbol_history.end(),
|
2020-06-21 19:10:22 +00:00
|
|
|
0,
|
|
|
|
[&d_preamble_samples, n = 0](float a, float b) mutable { return (b > 0.0 ? a + d_preamble_samples[n++] : a - d_preamble_samples[n++]); });
|
|
|
|
}
|
2024-10-06 06:14:46 +00:00
|
|
|
if (corr_value)
|
|
|
|
{
|
|
|
|
// avoidl warning
|
|
|
|
};
|
2020-06-21 19:10:22 +00:00
|
|
|
}
|
|
|
|
|
2020-06-30 11:41:20 +00:00
|
|
|
|
2020-06-29 08:13:07 +00:00
|
|
|
void bm_inner_product(benchmark::State& state)
|
|
|
|
{
|
|
|
|
std::vector<float> d_symbol_history(GPS_CA_PREAMBLE_LENGTH_SYMBOLS, 0.0);
|
|
|
|
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
|
|
|
|
|
|
|
|
// fill the inputs
|
|
|
|
std::random_device rd;
|
|
|
|
std::default_random_engine e2(rd());
|
|
|
|
std::uniform_real_distribution<> dist(-1.0, 1.0);
|
|
|
|
std::generate(d_symbol_history.begin(), d_symbol_history.end(), [&dist, &e2]() { return dist(e2); });
|
|
|
|
|
|
|
|
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE_SYMBOLS_STR[n++] == '1' ? 1 : -1); });
|
|
|
|
|
2024-10-06 06:14:46 +00:00
|
|
|
int32_t corr_value = 0;
|
2020-06-29 08:13:07 +00:00
|
|
|
while (state.KeepRunning())
|
|
|
|
{
|
|
|
|
corr_value += std::inner_product(d_symbol_history.begin(),
|
|
|
|
d_symbol_history.end(),
|
|
|
|
d_preamble_samples.begin(),
|
|
|
|
0,
|
2020-06-30 11:41:20 +00:00
|
|
|
#if COMPILER_HAS_STD_PLUS_VOID
|
2020-06-29 08:13:07 +00:00
|
|
|
std::plus<>(),
|
2020-06-30 11:41:20 +00:00
|
|
|
#else
|
2020-06-30 13:29:30 +00:00
|
|
|
std::plus<int32_t>(),
|
2020-06-30 11:41:20 +00:00
|
|
|
#endif
|
2020-06-30 13:29:30 +00:00
|
|
|
[](float a, int32_t b) { return (std::signbit(a) ? -b : b); });
|
2020-06-29 08:13:07 +00:00
|
|
|
}
|
2024-10-06 06:14:46 +00:00
|
|
|
if (corr_value)
|
|
|
|
{
|
|
|
|
// avoidl warning
|
|
|
|
};
|
2020-06-29 08:13:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 21:05:33 +00:00
|
|
|
|
|
|
|
#if COMPILER_HAS_STD_TRANSFORM_REDUCE
|
|
|
|
void bm_transform_reduce(benchmark::State& state)
|
|
|
|
{
|
|
|
|
std::vector<float> d_symbol_history(GPS_CA_PREAMBLE_LENGTH_SYMBOLS, 0.0);
|
|
|
|
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
|
|
|
|
|
|
|
|
// fill the inputs
|
|
|
|
std::random_device rd;
|
|
|
|
std::default_random_engine e2(rd());
|
|
|
|
std::uniform_real_distribution<> dist(-1.0, 1.0);
|
|
|
|
std::generate(d_symbol_history.begin(), d_symbol_history.end(), [&dist, &e2]() { return dist(e2); });
|
|
|
|
|
|
|
|
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE_SYMBOLS_STR[n++] == '1' ? 1 : -1); });
|
|
|
|
|
2024-10-06 06:14:46 +00:00
|
|
|
int32_t corr_value = 0;
|
2020-07-01 21:05:33 +00:00
|
|
|
while (state.KeepRunning())
|
|
|
|
{
|
|
|
|
corr_value += std::transform_reduce(d_symbol_history.begin(),
|
|
|
|
d_symbol_history.end(),
|
|
|
|
d_preamble_samples.begin(),
|
|
|
|
0,
|
|
|
|
std::plus<>(),
|
|
|
|
[](auto a, auto b) { return (std::signbit(a) ? -b : b); });
|
|
|
|
}
|
2024-10-06 06:14:46 +00:00
|
|
|
if (corr_value)
|
|
|
|
{
|
|
|
|
// avoidl warning
|
|
|
|
};
|
2020-07-01 21:05:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if COMPILER_HAS_STD_TRANSFORM_REDUCE_WITH_POLICY
|
|
|
|
void bm_transform_reduce_policy(benchmark::State& state)
|
|
|
|
{
|
|
|
|
std::vector<float> d_symbol_history(GPS_CA_PREAMBLE_LENGTH_SYMBOLS, 0.0);
|
|
|
|
std::array<int32_t, GPS_CA_PREAMBLE_LENGTH_SYMBOLS> d_preamble_samples{};
|
|
|
|
|
|
|
|
// fill the inputs
|
|
|
|
std::random_device rd;
|
|
|
|
std::default_random_engine e2(rd());
|
|
|
|
std::uniform_real_distribution<> dist(-1.0, 1.0);
|
|
|
|
std::generate(d_symbol_history.begin(), d_symbol_history.end(), [&dist, &e2]() { return dist(e2); });
|
|
|
|
|
|
|
|
std::generate(d_preamble_samples.begin(), d_preamble_samples.end(), [n = 0]() mutable { return (GPS_CA_PREAMBLE_SYMBOLS_STR[n++] == '1' ? 1 : -1); });
|
|
|
|
|
2024-10-06 06:14:46 +00:00
|
|
|
int32_t corr_value = 0;
|
2020-07-01 21:05:33 +00:00
|
|
|
while (state.KeepRunning())
|
|
|
|
{
|
|
|
|
corr_value += std::transform_reduce(
|
|
|
|
std::execution::par,
|
|
|
|
d_symbol_history.begin(),
|
|
|
|
d_symbol_history.end(),
|
|
|
|
d_preamble_samples.begin(),
|
|
|
|
0,
|
|
|
|
std::plus<>(),
|
|
|
|
[](auto a, auto b) { return (std::signbit(a) ? -b : b); });
|
|
|
|
}
|
2024-10-06 06:14:46 +00:00
|
|
|
if (corr_value)
|
|
|
|
{
|
|
|
|
// avoidl warning
|
|
|
|
};
|
2020-07-01 21:05:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-06-21 19:10:22 +00:00
|
|
|
BENCHMARK(bm_forloop);
|
2020-06-24 11:59:50 +00:00
|
|
|
BENCHMARK(bm_accumulate);
|
2020-06-29 08:13:07 +00:00
|
|
|
BENCHMARK(bm_inner_product);
|
2020-07-01 21:05:33 +00:00
|
|
|
#if COMPILER_HAS_STD_TRANSFORM_REDUCE
|
|
|
|
BENCHMARK(bm_transform_reduce);
|
|
|
|
#endif
|
|
|
|
#if COMPILER_HAS_STD_TRANSFORM_REDUCE_WITH_POLICY
|
|
|
|
BENCHMARK(bm_transform_reduce_policy);
|
|
|
|
#endif
|
2020-06-21 19:10:22 +00:00
|
|
|
BENCHMARK_MAIN();
|