2017-10-17 12:17:11 +00:00
|
|
|
/*!
|
|
|
|
* \file fft_speed_test.cc
|
|
|
|
* \brief This file implements timing tests for the Armadillo
|
|
|
|
* and GNU Radio FFT implementations
|
|
|
|
* \author Antonio Ramos, 2017. antonio.ramos(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2017-10-17 12:17:11 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2017-10-17 12:17:11 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2017-10-17 12:17:11 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2017-10-17 12:17:11 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-15 12:39:26 +00:00
|
|
|
#include "gnss_sdr_fft.h"
|
2018-12-09 21:00:09 +00:00
|
|
|
#include <armadillo>
|
2022-06-13 19:05:29 +00:00
|
|
|
#include <algorithm>
|
2017-10-17 12:17:11 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
|
|
|
|
2024-04-29 06:27:33 +00:00
|
|
|
#if USE_GLOG_AND_GFLAGS
|
2017-10-18 10:30:42 +00:00
|
|
|
DEFINE_int32(fft_speed_iterations_test, 100, "Number of averaged iterations in FFT length timing test");
|
2024-04-29 06:27:33 +00:00
|
|
|
#else
|
|
|
|
ABSL_FLAG(int32_t, fft_speed_iterations_test, 100, "Number of averaged iterations in FFT length timing test");
|
|
|
|
#endif
|
2017-10-17 12:17:11 +00:00
|
|
|
|
|
|
|
TEST(FFTSpeedTest, ArmadilloVSGNURadioExecutionTime)
|
|
|
|
{
|
|
|
|
unsigned int d_fft_size;
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
std::chrono::duration<double> elapsed_seconds;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
unsigned int fft_sizes[19] = {16, 25, 32, 45, 64, 95, 128, 195, 256, 325, 512, 785, 1024, 1503, 2048, 3127, 4096, 6349, 8192};
|
2017-10-17 12:17:11 +00:00
|
|
|
double d_execution_time;
|
|
|
|
EXPECT_NO_THROW(
|
2019-02-11 14:33:24 +00:00
|
|
|
for (unsigned int fft_size
|
|
|
|
: fft_sizes) {
|
|
|
|
d_fft_size = fft_size;
|
2021-01-15 12:39:26 +00:00
|
|
|
auto d_gr_fft = gnss_fft_fwd_make_unique(d_fft_size);
|
2018-03-03 01:03:39 +00:00
|
|
|
arma::arma_rng::set_seed_random();
|
|
|
|
arma::cx_fvec d_arma_fft = arma::cx_fvec(d_fft_size).randn() + gr_complex(0.0, 1.0) * arma::cx_fvec(d_fft_size).randn();
|
|
|
|
arma::cx_fvec d_arma_fft_result(d_fft_size);
|
2022-06-13 19:05:29 +00:00
|
|
|
std::copy_n(d_arma_fft.memptr(), d_fft_size, d_gr_fft->get_inbuf());
|
2018-03-03 01:03:39 +00:00
|
|
|
|
|
|
|
start = std::chrono::system_clock::now();
|
2024-04-29 06:27:33 +00:00
|
|
|
#if USE_GLOG_AND_GFLAGS
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int k = 0; k < FLAGS_fft_speed_iterations_test; k++)
|
2024-04-29 06:27:33 +00:00
|
|
|
#else
|
|
|
|
for (int k = 0; k < absl::GetFlag(FLAGS_fft_speed_iterations_test); k++)
|
|
|
|
#endif
|
2017-10-17 12:17:11 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
d_gr_fft->execute();
|
|
|
|
}
|
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
elapsed_seconds = end - start;
|
2024-04-29 06:27:33 +00:00
|
|
|
#if USE_GLOG_AND_GFLAGS
|
2018-03-03 01:03:39 +00:00
|
|
|
d_execution_time = elapsed_seconds.count() / static_cast<double>(FLAGS_fft_speed_iterations_test);
|
2024-04-29 06:27:33 +00:00
|
|
|
#else
|
|
|
|
d_execution_time = elapsed_seconds.count() / static_cast<double>(absl::GetFlag(FLAGS_fft_speed_iterations_test));
|
|
|
|
#endif
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "GNU Radio FFT execution time for length = " << d_fft_size << " : " << d_execution_time * 1e6 << " [us]\n";
|
2017-10-18 09:04:17 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
start = std::chrono::system_clock::now();
|
2024-04-29 06:27:33 +00:00
|
|
|
#if USE_GLOG_AND_GFLAGS
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int k = 0; k < FLAGS_fft_speed_iterations_test; k++)
|
2024-04-29 06:27:33 +00:00
|
|
|
#else
|
|
|
|
for (int k = 0; k < absl::GetFlag(FLAGS_fft_speed_iterations_test); k++)
|
|
|
|
#endif
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
d_arma_fft_result = arma::fft(d_arma_fft);
|
2017-10-17 12:17:11 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
elapsed_seconds = end - start;
|
2024-04-29 06:27:33 +00:00
|
|
|
#if USE_GLOG_AND_GFLAGS
|
2018-03-03 01:03:39 +00:00
|
|
|
d_execution_time = elapsed_seconds.count() / static_cast<double>(FLAGS_fft_speed_iterations_test);
|
2024-04-29 06:27:33 +00:00
|
|
|
#else
|
|
|
|
d_execution_time = elapsed_seconds.count() / static_cast<double>(absl::GetFlag(FLAGS_fft_speed_iterations_test));
|
|
|
|
#endif
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "Armadillo FFT execution time for length = " << d_fft_size << " : " << d_execution_time * 1e6 << " [us]\n";
|
2018-03-03 01:03:39 +00:00
|
|
|
});
|
2017-10-17 12:17:11 +00:00
|
|
|
}
|