1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-05 23:10:34 +00:00

Merge branch 'atan2-benchmark' into next

This commit is contained in:
Carles Fernandez 2022-02-10 20:36:01 +01:00
commit cc8ee5ab97
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 71 additions and 3 deletions

View File

@ -78,7 +78,7 @@ else()
add_library(tracking_libs ${TRACKING_LIB_SOURCES} ${TRACKING_LIB_HEADERS}) add_library(tracking_libs ${TRACKING_LIB_SOURCES} ${TRACKING_LIB_HEADERS})
endif() endif()
target_link_libraries(tracking_libs target_link_libraries(tracking_libs
PUBLIC PUBLIC
Armadillo::armadillo Armadillo::armadillo
Boost::headers Boost::headers
@ -89,6 +89,7 @@ target_link_libraries(tracking_libs
PRIVATE PRIVATE
gnss_sdr_flags gnss_sdr_flags
Glog::glog Glog::glog
Gnuradio::runtime
) )
if(ENABLE_CUDA) if(ENABLE_CUDA)

View File

@ -20,6 +20,7 @@
#include "tracking_discriminators.h" #include "tracking_discriminators.h"
#include "MATH_CONSTANTS.h" #include "MATH_CONSTANTS.h"
#include <gnuradio/math.h>
// All the outputs are in RADIANS // All the outputs are in RADIANS
@ -53,7 +54,7 @@ double fll_four_quadrant_atan(gr_complex prompt_s1, gr_complex prompt_s2, double
{ {
const float dot = prompt_s1.real() * prompt_s2.real() + prompt_s1.imag() * prompt_s2.imag(); const float dot = prompt_s1.real() * prompt_s2.real() + prompt_s1.imag() * prompt_s2.imag();
const float cross = prompt_s1.real() * prompt_s2.imag() - prompt_s2.real() * prompt_s1.imag(); const float cross = prompt_s1.real() * prompt_s2.imag() - prompt_s2.real() * prompt_s1.imag();
return std::atan2(cross, dot) / (t2 - t1); return static_cast<double>(gr::fast_atan2f(cross, dot) / (t2 - t1));
} }
@ -84,7 +85,7 @@ double fll_diff_atan(gr_complex prompt_s1, gr_complex prompt_s2, double t1, doub
*/ */
double pll_four_quadrant_atan(gr_complex prompt_s1) double pll_four_quadrant_atan(gr_complex prompt_s1)
{ {
return static_cast<double>(std::atan2(prompt_s1.imag(), prompt_s1.real())); return static_cast<double>(gr::fast_atan2f(prompt_s1.imag(), prompt_s1.real()));
} }

View File

@ -102,6 +102,7 @@ add_benchmark(benchmark_copy)
add_benchmark(benchmark_preamble core_system_parameters) add_benchmark(benchmark_preamble core_system_parameters)
add_benchmark(benchmark_detector core_system_parameters) add_benchmark(benchmark_detector core_system_parameters)
add_benchmark(benchmark_reed_solomon core_system_parameters) add_benchmark(benchmark_reed_solomon core_system_parameters)
add_benchmark(benchmark_atan2 Gnuradio::runtime)
if(has_std_plus_void) if(has_std_plus_void)
target_compile_definitions(benchmark_detector PRIVATE -DCOMPILER_HAS_STD_PLUS_VOID=1) target_compile_definitions(benchmark_detector PRIVATE -DCOMPILER_HAS_STD_PLUS_VOID=1)

View File

@ -0,0 +1,65 @@
/*!
* \file benchmark_atan2.cc
* \brief Benchmark for atan2 implementations
* \author Carles Fernandez-Prades, 2022. cfernandez(at)cttc.es
*
*
* -----------------------------------------------------------------------------
*
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2022 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
*/
#include <benchmark/benchmark.h>
#include <gnuradio/math.h>
#include <cmath>
#include <random>
void bm_std_atan2(benchmark::State& state)
{
std::random_device rd;
std::default_random_engine e2(rd());
std::uniform_real_distribution<> dist(-1.0, 1.0);
float a = dist(e2);
float b = dist(e2);
float c;
while (state.KeepRunning())
{
c = std::atan2(a, b);
}
if (c > 1.0)
{
// Avoid unused-but-set-variable warning
}
}
void bm_gr_fast_atan2f(benchmark::State& state)
{
std::random_device rd;
std::default_random_engine e2(rd());
std::uniform_real_distribution<> dist(-1.0, 1.0);
float a = dist(e2);
float b = dist(e2);
float c;
while (state.KeepRunning())
{
c = gr::fast_atan2f(a, b);
}
if (c > 1.0)
{
// Avoid unused-but-set-variable warning
}
}
BENCHMARK(bm_std_atan2);
BENCHMARK(bm_gr_fast_atan2f);
BENCHMARK_MAIN();