1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

Benchmarking: implemented decimator float to int test

This commit is contained in:
f4exb 2018-04-25 01:44:54 +02:00
parent 698f5bd172
commit b03e9c59cb
9 changed files with 158 additions and 65 deletions

View File

@ -17,13 +17,13 @@
#ifndef INCLUDE_AIRSPYHFTHREAD_H
#define INCLUDE_AIRSPYHFTHREAD_H
#include <dsp/decimatorsfi.h>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <libairspyhf/airspyhf.h>
#include "dsp/samplesinkfifo.h"
#include "dsp/decimatorsf.h"
#define AIRSPYHF_BLOCKSIZE (1<<17)
@ -53,7 +53,7 @@ private:
unsigned int m_log2Decim;
static AirspyHFThread *m_this;
DecimatorsF m_decimators;
DecimatorsFI m_decimators;
void run();
void callback(const float* buf, qint32 len);

View File

@ -21,7 +21,7 @@ set(sdrbase_SOURCES
dsp/ctcssdetector.cpp
dsp/cwkeyer.cpp
dsp/cwkeyersettings.cpp
dsp/decimatorsf.cpp
dsp/decimatorsfi.cpp
dsp/dspcommands.cpp
dsp/dspengine.cpp
dsp/dspdevicesourceengine.cpp
@ -104,7 +104,7 @@ set(sdrbase_HEADERS
dsp/cwkeyer.h
dsp/cwkeyersettings.h
dsp/decimators.h
dsp/decimatorsf.h
dsp/decimatorsfi.h
dsp/decimatorsu.h
dsp/interpolators.h
dsp/dspcommands.h

View File

@ -282,6 +282,7 @@ struct TripleByteLE<qint64>
} __attribute__((__packed__));
/** Decimators with integer input and integer output */
template<typename AccuType, typename T, uint SdrBits, uint InputBits>
class Decimators
{

View File

@ -14,9 +14,9 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "decimatorsf.h"
#include <dsp/decimatorsfi.h>
void DecimatorsF::decimate1(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate1(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
float xreal, yimag;
@ -30,7 +30,7 @@ void DecimatorsF::decimate1(SampleVector::iterator* it, const float* buf, qint32
}
}
void DecimatorsF::decimate2_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate2_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double intbuf[2];
@ -52,7 +52,7 @@ void DecimatorsF::decimate2_cen(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate2_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate2_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal, yimag;
@ -72,7 +72,7 @@ void DecimatorsF::decimate2_inf(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate2_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate2_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal, yimag;
@ -92,7 +92,7 @@ void DecimatorsF::decimate2_sup(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate4_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate4_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal, yimag;
@ -108,7 +108,7 @@ void DecimatorsF::decimate4_inf(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate4_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate4_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
// Sup (USB):
// x y x y x y x y / x -> 1,-2,-5,6 / y -> -0,-3,4,7
@ -130,7 +130,7 @@ void DecimatorsF::decimate4_sup(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate8_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate8_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal[2], yimag[2];
@ -152,7 +152,7 @@ void DecimatorsF::decimate8_inf(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate8_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate8_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal[2], yimag[2];
@ -174,7 +174,7 @@ void DecimatorsF::decimate8_sup(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate16_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate16_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
// Offset tuning: 4x downsample and rotate, then
// downsample 4x more. [ rotate: 0, 1, -3, 2, -4, -5, 7, -6]
@ -201,7 +201,7 @@ void DecimatorsF::decimate16_inf(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate16_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate16_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
// Offset tuning: 4x downsample and rotate, then
// downsample 4x more. [ rotate: 1, 0, -2, 3, -5, -4, 6, -7]
@ -228,7 +228,7 @@ void DecimatorsF::decimate16_sup(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate32_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate32_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal[8], yimag[8];
@ -258,7 +258,7 @@ void DecimatorsF::decimate32_inf(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate32_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate32_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal[8], yimag[8];
@ -288,7 +288,7 @@ void DecimatorsF::decimate32_sup(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate64_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate64_inf(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal[16], yimag[16];
@ -327,7 +327,7 @@ void DecimatorsF::decimate64_inf(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate64_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate64_sup(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double xreal[16], yimag[16];
@ -366,7 +366,7 @@ void DecimatorsF::decimate64_sup(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate4_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate4_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double intbuf[4];
@ -400,7 +400,7 @@ void DecimatorsF::decimate4_cen(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate8_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate8_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double intbuf[8];
@ -459,7 +459,7 @@ void DecimatorsF::decimate8_cen(SampleVector::iterator* it, const float* buf, qi
}
}
void DecimatorsF::decimate16_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate16_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double intbuf[16];
@ -567,7 +567,7 @@ void DecimatorsF::decimate16_cen(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate32_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate32_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double intbuf[32];
@ -772,7 +772,7 @@ void DecimatorsF::decimate32_cen(SampleVector::iterator* it, const float* buf, q
}
}
void DecimatorsF::decimate64_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
void DecimatorsFI::decimate64_cen(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ)
{
double intbuf[64];

View File

@ -14,15 +14,16 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_DSP_DECIMATORSF_H_
#define SDRBASE_DSP_DECIMATORSF_H_
#ifndef SDRBASE_DSP_DECIMATORSFI_H_
#define SDRBASE_DSP_DECIMATORSFI_H_
#include "dsp/inthalfbandfilterdbf.h"
#include "export.h"
#define DECIMATORSF_HB_FILTER_ORDER 64
class SDRBASE_API DecimatorsF
/** Decimators with float input and integer output */
class SDRBASE_API DecimatorsFI
{
public:
void decimate1(SampleVector::iterator* it, const float* buf, qint32 nbIAndQ);
@ -55,4 +56,4 @@ public:
#endif /* SDRBASE_DSP_DECIMATORSF_H_ */
#endif /* SDRBASE_DSP_DECIMATORSFI_H_ */

View File

@ -38,69 +38,140 @@ MainBench::~MainBench()
void MainBench::run()
{
QElapsedTimer timer;
qint64 nsecs;
qDebug() << "MainBench::run: parameters:"
<< " test: " << m_parser.getTest()
qDebug() << "MainBench::run: parameters:"
<< " testStr: " << m_parser.getTestStr()
<< " testType: " << (int) m_parser.getTestType()
<< " nsamples: " << m_parser.getNbSamples()
<< " repet: " << m_parser.getRepetition()
<< " log2f: " << m_parser.getLog2Factor();
qDebug() << "MainBench::run: create test data";
m_buf = new qint16[m_parser.getNbSamples()*2];
if (m_parser.getTestType() == ParserBench::TestDecimatorsII) {
testDecimateII();
} else if (m_parser.getTestType() == ParserBench::TestDecimatorsFI) {
testDecimateFI();
}
emit finished();
}
void MainBench::testDecimateII()
{
QElapsedTimer timer;
qint64 nsecs;
qDebug() << "MainBench::testDecimateII: create test data";
qint16 *buf = new qint16[m_parser.getNbSamples()*2];
m_convertBuffer.resize(m_parser.getNbSamples()/(1<<m_parser.getLog2Factor()));
qDebug() << "MainBench::run: run test";
qDebug() << "MainBench::testDecimateII: run test";
timer.start();
for (uint32_t i = 0; i < m_parser.getRepetition(); i++)
{
decimate(m_buf, m_parser.getNbSamples()*2);
decimateII(buf, m_parser.getNbSamples()*2);
}
nsecs = timer.nsecsElapsed();
QDebug debug = qDebug();
debug.noquote();
debug << tr("MainBench::run: ran test in %L1 ns").arg(nsecs);
debug << tr("MainBench::testDecimateII: ran test in %L1 ns").arg(nsecs);
qDebug() << "MainBench::run: cleanup test data";
qDebug() << "MainBench::testDecimateII: cleanup test data";
delete[] m_buf;
emit finished();
delete[] buf;
}
void MainBench::decimate(const qint16* buf, int len)
void MainBench::testDecimateFI()
{
QElapsedTimer timer;
qint64 nsecs;
qDebug() << "MainBench::testDecimateFI: create test data";
float *buf = new float[m_parser.getNbSamples()*2];
m_convertBuffer.resize(m_parser.getNbSamples()/(1<<m_parser.getLog2Factor()));
qDebug() << "MainBench::testDecimateFI: run test";
timer.start();
for (uint32_t i = 0; i < m_parser.getRepetition(); i++)
{
decimateFI(buf, m_parser.getNbSamples()*2);
}
nsecs = timer.nsecsElapsed();
QDebug debug = qDebug();
debug.noquote();
debug << tr("MainBench::testDecimateFI: ran test in %L1 ns").arg(nsecs);
qDebug() << "MainBench::testDecimateFI: cleanup test data";
delete[] buf;
}
void MainBench::decimateII(const qint16* buf, int len)
{
SampleVector::iterator it = m_convertBuffer.begin();
switch (m_parser.getLog2Factor())
{
case 0:
m_decimators.decimate1(&it, buf, len);
m_decimatorsII.decimate1(&it, buf, len);
break;
case 1:
m_decimators.decimate2_cen(&it, buf, len);
m_decimatorsII.decimate2_cen(&it, buf, len);
break;
case 2:
m_decimators.decimate4_cen(&it, buf, len);
m_decimatorsII.decimate4_cen(&it, buf, len);
break;
case 3:
m_decimators.decimate8_cen(&it, buf, len);
m_decimatorsII.decimate8_cen(&it, buf, len);
break;
case 4:
m_decimators.decimate16_cen(&it, buf, len);
m_decimatorsII.decimate16_cen(&it, buf, len);
break;
case 5:
m_decimators.decimate32_cen(&it, buf, len);
m_decimatorsII.decimate32_cen(&it, buf, len);
break;
case 6:
m_decimators.decimate64_cen(&it, buf, len);
m_decimatorsII.decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
}
}
void MainBench::decimateFI(const float *buf, int len)
{
SampleVector::iterator it = m_convertBuffer.begin();
switch (m_parser.getLog2Factor())
{
case 0:
m_decimatorsFI.decimate1(&it, buf, len);
break;
case 1:
m_decimatorsFI.decimate2_cen(&it, buf, len);
break;
case 2:
m_decimatorsFI.decimate4_cen(&it, buf, len);
break;
case 3:
m_decimatorsFI.decimate8_cen(&it, buf, len);
break;
case 4:
m_decimatorsFI.decimate16_cen(&it, buf, len);
break;
case 5:
m_decimatorsFI.decimate32_cen(&it, buf, len);
break;
case 6:
m_decimatorsFI.decimate64_cen(&it, buf, len);
break;
default:
break;
}
}

View File

@ -22,6 +22,7 @@
#include <QObject>
#include "dsp/decimators.h"
#include "dsp/decimatorsfi.h"
#include "parserbench.h"
namespace qtwebapp {
@ -42,19 +43,22 @@ signals:
void finished();
private:
void decimate(const qint16 *buf, int len);
void testDecimateII();
void testDecimateFI();
void decimateII(const qint16 *buf, int len);
void decimateFI(const float *buf, int len);
static MainBench *m_instance;
qtwebapp::LoggerWithFile *m_logger;
const ParserBench& m_parser;
#ifdef SDR_RX_SAMPLE_24BIT
Decimators<qint64, qint16, SDR_RX_SAMP_SZ, 12> m_decimators;
Decimators<qint64, qint16, SDR_RX_SAMP_SZ, 12> m_decimatorsII;
#else
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimators;
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimatorsII;
#endif
qint16 *m_buf;
DecimatorsFI m_decimatorsFI;
SampleVector m_convertBuffer;
};

View File

@ -25,7 +25,7 @@ ParserBench::ParserBench() :
m_testOption(QStringList() << "t" << "test",
"Test type.",
"test",
"decimate"),
"decimateii"),
m_nbSamplesOption(QStringList() << "n" << "nb-samples",
"Number of sample to deal with.",
"samples",
@ -39,7 +39,7 @@ ParserBench::ParserBench() :
"log2",
"2")
{
m_test = "decimate";
m_testStr = "decimateii";
m_nbSamples = 1048576;
m_repetition = 1;
m_log2Factor = 4;
@ -68,14 +68,14 @@ void ParserBench::parse(const QCoreApplication& app)
QString test = m_parser.value(m_testOption);
QString testStr = "(decimate)";
QString testStr = "([a-z]+)";
QRegExp ipRegex ("^" + testStr + "$");
QRegExpValidator ipValidator(ipRegex);
if (ipValidator.validate(test, pos) == QValidator::Acceptable) {
m_test = test;
m_testStr = test;
} else {
qWarning() << "ParserBench::parse: test type invalid. Defaulting to " << m_test;
qWarning() << "ParserBench::parse: test string invalid. Defaulting to " << m_testStr;
}
// number of samples
@ -111,3 +111,12 @@ void ParserBench::parse(const QCoreApplication& app)
qWarning() << "ParserBench::parse: repetilog2 factortion invalid. Defaulting to " << m_log2Factor;
}
}
ParserBench::TestType ParserBench::getTestType() const
{
if (m_testStr == "decimatefi") {
return TestDecimatorsFI;
} else {
return TestDecimatorsII;
}
}

View File

@ -24,18 +24,25 @@
class ParserBench
{
public:
typedef enum
{
TestDecimatorsII,
TestDecimatorsFI
} TestType;
ParserBench();
~ParserBench();
void parse(const QCoreApplication& app);
const QString& getTest() const { return m_test; }
const QString& getTestStr() const { return m_testStr; }
TestType getTestType() const;
uint32_t getNbSamples() const { return m_nbSamples; }
uint32_t getRepetition() const { return m_repetition; }
uint32_t getLog2Factor() const { return m_log2Factor; }
private:
QString m_test;
QString m_testStr;
uint32_t m_nbSamples;
uint32_t m_repetition;
uint32_t m_log2Factor;