From 69f0f0f7bcd01b486d98430d7661134cbc3a5f7b Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Fri, 9 Aug 2019 10:17:03 +0100 Subject: [PATCH] CMSIS-DSP: Testing framework Added some calibration to remove overhead in the benchmark measurement process. Reorganized one test to move some initialization code outside of the test. --- Testing/CMakeLists.txt | 1 + Testing/FrameworkInclude/Calibrate.h | 10 ++++++ Testing/FrameworkInclude/IORunner.h | 2 ++ Testing/FrameworkSource/Calibrate.cpp | 20 +++++++++++ Testing/FrameworkSource/IORunner.cpp | 33 ++++++++++++++++++- .../Benchmarks/BasicMathsBenchmarksF32.h | 4 +++ .../Benchmarks/BasicMathsBenchmarksF32.cpp | 22 +++++++++---- Testing/processResult.py | 7 +++- 8 files changed, 90 insertions(+), 9 deletions(-) create mode 100755 Testing/FrameworkInclude/Calibrate.h create mode 100755 Testing/FrameworkSource/Calibrate.cpp diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 365075b9..087cd9c6 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -134,6 +134,7 @@ set(FRAMEWORKSRC FrameworkSource/FPGA.cpp FrameworkSource/Timing.cpp FrameworkSource/Generators.cpp + FrameworkSource/Calibrate.cpp ) # Change behavior of configBoot for scatter file # We use the linker files from older test framework because bigger sections are needed. diff --git a/Testing/FrameworkInclude/Calibrate.h b/Testing/FrameworkInclude/Calibrate.h new file mode 100755 index 00000000..8747446f --- /dev/null +++ b/Testing/FrameworkInclude/Calibrate.h @@ -0,0 +1,10 @@ +#include "Test.h" +#include "Pattern.h" +class Calibrate:public Client::Suite + { + public: + Calibrate(Testing::testID_t id); + void empty(); + void setUp(Testing::testID_t,std::vector& params,Client::PatternMgr *mgr); + void tearDown(Testing::testID_t,Client::PatternMgr *mgr); + }; diff --git a/Testing/FrameworkInclude/IORunner.h b/Testing/FrameworkInclude/IORunner.h index c275ef97..ced71890 100644 --- a/Testing/FrameworkInclude/IORunner.h +++ b/Testing/FrameworkInclude/IORunner.h @@ -44,6 +44,8 @@ namespace Client IO *m_io; PatternMgr *m_mgr; Testing::RunningMode m_runningMode; + + Testing::cycles_t calibration = 0; }; } diff --git a/Testing/FrameworkSource/Calibrate.cpp b/Testing/FrameworkSource/Calibrate.cpp new file mode 100755 index 00000000..86edd963 --- /dev/null +++ b/Testing/FrameworkSource/Calibrate.cpp @@ -0,0 +1,20 @@ +#include "Calibrate.h" + +Calibrate::Calibrate(Testing::testID_t id):Client::Suite(id) +{ + +} + +void Calibrate::empty() +{ +} + +void Calibrate::setUp(Testing::testID_t,std::vector& params,Client::PatternMgr *mgr) +{ + +} + +void Calibrate::tearDown(Testing::testID_t,Client::PatternMgr *mgr) +{ + +} diff --git a/Testing/FrameworkSource/IORunner.cpp b/Testing/FrameworkSource/IORunner.cpp index 9ef7ab54..47ce6db9 100644 --- a/Testing/FrameworkSource/IORunner.cpp +++ b/Testing/FrameworkSource/IORunner.cpp @@ -36,6 +36,7 @@ #include "Error.h" #include "Timing.h" #include "arm_math.h" +#include "Calibrate.h" namespace Client { @@ -54,6 +55,36 @@ namespace Client } initCycleMeasurement(); + +/* + +For calibration : + +Calibration means, in this context, removing the overhad of calling +a C++ function pointer from the cycle measurements. + + +*/ + Calibrate c((Testing::testID_t)0); + Client::Suite *s=(Client::Suite *)&c; + Client::test t = (Client::test)&Calibrate::empty; + + cycleMeasurementStart(); +#ifdef EXTBENCH + startSection(); +#endif + for(int i=0;i < 20;i++) + { + (s->*t)(); + } +#ifdef EXTBENCH + stopSection(); +#endif +#ifndef EXTBENCH + calibration=getCycles() / 20; +#endif + cycleMeasurementStop(); + } // Testing. @@ -152,7 +183,7 @@ namespace Client stopSection(); #endif #ifndef EXTBENCH - cycles=getCycles(); + cycles=getCycles()-calibration; #endif cycleMeasurementStop(); } diff --git a/Testing/Include/Benchmarks/BasicMathsBenchmarksF32.h b/Testing/Include/Benchmarks/BasicMathsBenchmarksF32.h index fe48c778..db406d40 100644 --- a/Testing/Include/Benchmarks/BasicMathsBenchmarksF32.h +++ b/Testing/Include/Benchmarks/BasicMathsBenchmarksF32.h @@ -13,5 +13,9 @@ class BasicMathsBenchmarksF32:public Client::Suite Client::LocalPattern output; int nb; + + float32_t *inp1; + float32_t *inp2; + float32_t *outp; }; \ No newline at end of file diff --git a/Testing/Source/Benchmarks/BasicMathsBenchmarksF32.cpp b/Testing/Source/Benchmarks/BasicMathsBenchmarksF32.cpp index 1d2a6590..71cdc23e 100644 --- a/Testing/Source/Benchmarks/BasicMathsBenchmarksF32.cpp +++ b/Testing/Source/Benchmarks/BasicMathsBenchmarksF32.cpp @@ -3,14 +3,9 @@ void BasicMathsBenchmarksF32::vec_mult_f32() - { - - float32_t *inp1=input1.ptr(); - float32_t *inp2=input2.ptr(); - float32_t *outp=output.ptr(); - + { - arm_mult_f32(inp1,inp2,outp,this->nb); + arm_mult_f32(this->inp1,this->inp2,this->outp,this->nb); } @@ -111,6 +106,19 @@ output.create(this->nb,BasicMathsBenchmarksF32::OUT_SAMPLES_F32_ID,mgr); + + switch(id) + { + case BasicMathsBenchmarksF32::VEC_MULT_F32_1: + /* This an overhead doing this because ptr() function is doing lot of checks + to ensure patterns are fresh. + So for small benchmark lengths it is better doing it in the setUp function + */ + this->inp1=input1.ptr(); + this->inp2=input2.ptr(); + this->outp=output.ptr(); + break; + } } diff --git a/Testing/processResult.py b/Testing/processResult.py index 43b85f4c..f2b26bab 100644 --- a/Testing/processResult.py +++ b/Testing/processResult.py @@ -235,6 +235,11 @@ def getCyclesFromTrace(trace): return(TestScripts.ParseTrace.getCycles(trace)) def analyseResult(root,results,embedded,benchmark,trace,formatter): + calibration = 0 + if trace: + # First cycle in the trace is the calibration data + # The noramlisation factor must be coherent with the C code one. + calibration = int(getCyclesFromTrace(trace) / 20) formatter.start() path = [] state = NORMAL @@ -348,7 +353,7 @@ def analyseResult(root,results,embedded,benchmark,trace,formatter): maybeCycles = m.group(4) if maybeCycles == "t": - cycles = getCyclesFromTrace(trace) + cycles = getCyclesFromTrace(trace) - calibration else: cycles = int(maybeCycles)