From 3b5bcc421f684c2e9ee75fdcb54ead6ec91cd236 Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Mon, 29 Jul 2019 07:44:23 +0200 Subject: [PATCH] CMSIS-NN:Added code to be able to benchmark arm_avgpool_s8. Benchmarking code added into CMSIS-DSP test framework. --- Testing/CMakeLists.txt | 1 + Testing/FrameworkSource/Timing.cpp | 4 + .../NN/Pooling/fullBenchmark.csv | 5 ++ .../FullBenchmark/NN/Pooling/regression.csv | 2 + Testing/GeneratedInclude/PoolingBench_decl.h | 13 +++ Testing/Include/PoolingBench.h | 37 ++++++++ Testing/Source/PoolingBench.cpp | 85 ++++++++++++++++++ Testing/addToDB.py | 2 +- Testing/bench.db | Bin 81920 -> 86016 bytes Testing/currentConfig.csv | 2 +- Testing/desc.txt | 33 ++++++- 11 files changed, 179 insertions(+), 5 deletions(-) create mode 100755 Testing/FullBenchmark/NN/Pooling/fullBenchmark.csv create mode 100755 Testing/FullBenchmark/NN/Pooling/regression.csv create mode 100755 Testing/GeneratedInclude/PoolingBench_decl.h create mode 100755 Testing/Include/PoolingBench.h create mode 100755 Testing/Source/PoolingBench.cpp diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index df2425ab..53396b6b 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -92,6 +92,7 @@ set(TESTSRC testmain.cpp Source/FullyConnected.cpp Source/FullyConnectedBench.cpp Source/Pooling.cpp + Source/PoolingBench.cpp GeneratedSource/TestDesc.cpp ) diff --git a/Testing/FrameworkSource/Timing.cpp b/Testing/FrameworkSource/Timing.cpp index 15c0cbd3..a5259dfc 100644 --- a/Testing/FrameworkSource/Timing.cpp +++ b/Testing/FrameworkSource/Timing.cpp @@ -104,7 +104,11 @@ void cycleMeasurementStart() SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk; + while(SysTick->VAL == 0); + startCycles = SysTick->VAL; + + #endif diff --git a/Testing/FullBenchmark/NN/Pooling/fullBenchmark.csv b/Testing/FullBenchmark/NN/Pooling/fullBenchmark.csv new file mode 100755 index 00000000..b112da81 --- /dev/null +++ b/Testing/FullBenchmark/NN/Pooling/fullBenchmark.csv @@ -0,0 +1,5 @@ +CATEGORY,NAME,ID,OLDID,NB,CYCLES,OPTIMIZED,HARDFP,FASTMATH,NEON,UNROLL,ROUNDING,PLATFORM,CORE,COMPILER,VERSION +"NN:Pooling","test_avgpool_s8",1,"",10,87558,1,1,1,0,1,0,FVP,ARMCM7_DP,AC6,6120001 +"NN:Pooling","test_avgpool_s8",1,"",20,177505,1,1,1,0,1,0,FVP,ARMCM7_DP,AC6,6120001 +"NN:Pooling","test_avgpool_s8",1,"",100,885034,1,1,1,0,1,0,FVP,ARMCM7_DP,AC6,6120001 +"NN:Pooling","test_avgpool_s8",1,"",200,1772498,1,1,1,0,1,0,FVP,ARMCM7_DP,AC6,6120001 diff --git a/Testing/FullBenchmark/NN/Pooling/regression.csv b/Testing/FullBenchmark/NN/Pooling/regression.csv new file mode 100755 index 00000000..64995dce --- /dev/null +++ b/Testing/FullBenchmark/NN/Pooling/regression.csv @@ -0,0 +1,2 @@ +"ID","OLDID","CATEGORY","NAME","OPTIMIZED","HARDFP","FASTMATH","NEON","UNROLL","ROUNDING","PLATFORM","CORE","COMPILER","VERSION","Regression","MAX" +1,"","NN:Pooling","test_avgpool_s8",1,1,1,0,1,0,"FVP","ARMCM7_DP","AC6",6120001,"-648.9462943071558 + NB * 8864.214500537057",1772498 diff --git a/Testing/GeneratedInclude/PoolingBench_decl.h b/Testing/GeneratedInclude/PoolingBench_decl.h new file mode 100755 index 00000000..f45b3898 --- /dev/null +++ b/Testing/GeneratedInclude/PoolingBench_decl.h @@ -0,0 +1,13 @@ +void test_avgpool_s8(); + +// Pattern IDs +static const int INPUT1_S8_ID=0; +static const int REF1_S8_ID=1; + +// Output IDs +static const int OUTPUT_S8_ID=0; +static const int TEMP_S8_ID=1; +static const int TEMPINPUT_S8_ID=2; + +// Test IDs +static const int TEST_AVGPOOL_S8_1=1; diff --git a/Testing/Include/PoolingBench.h b/Testing/Include/PoolingBench.h new file mode 100755 index 00000000..fb09a56d --- /dev/null +++ b/Testing/Include/PoolingBench.h @@ -0,0 +1,37 @@ +#include "Test.h" +#include "Pattern.h" +class PoolingBench:public Client::Suite + { + public: + PoolingBench(Testing::testID_t id); + void setUp(Testing::testID_t,std::vector& paramsArgs,Client::PatternMgr *mgr); + void tearDown(Testing::testID_t,Client::PatternMgr *mgr); + private: + #include "PoolingBench_decl.h" + + Client::Pattern input; + + Client::LocalPattern tmpInput; + Client::LocalPattern output; + Client::LocalPattern temp; + + // Reference patterns are not loaded when we are in dump mode + Client::RefPattern ref; + + int DIM_IN_X; + int DIM_IN_Y; + int DIM_OUT_X; + int DIM_OUT_Y; + int IN_CHANNEL; + int DIM_FILTER_X; + int DIM_FILTER_Y; + int PAD_WIDTH; + int PAD_HEIGHT; + int STRIDE_X; + int STRIDE_Y; + int ACT_MIN; + int ACT_MAX; + + int repeatNb; + + }; \ No newline at end of file diff --git a/Testing/Source/PoolingBench.cpp b/Testing/Source/PoolingBench.cpp new file mode 100755 index 00000000..9ef4dcea --- /dev/null +++ b/Testing/Source/PoolingBench.cpp @@ -0,0 +1,85 @@ +#include "PoolingBench.h" +#include "Error.h" +#include "arm_nnfunctions.h" +#include "Test.h" + +#include + + + void PoolingBench::test_avgpool_s8() + { + q7_t *tmpin = tmpInput.ptr(); + q7_t *outp = output.ptr(); + q15_t *tempp = temp.ptr(); + + for(int i=0; i < this->repeatNb; i++) + { + arm_avgpool_s8( + DIM_IN_Y, + DIM_IN_X, + DIM_OUT_Y, + DIM_OUT_X, + STRIDE_Y, + STRIDE_X, + DIM_FILTER_Y, + DIM_FILTER_X, + PAD_HEIGHT, + PAD_WIDTH, + ACT_MIN, + ACT_MAX, + IN_CHANNEL, + tmpin, + tempp, + outp); + + } + } + + + void PoolingBench::setUp(Testing::testID_t id,std::vector& paramsArgs,Client::PatternMgr *mgr) + { + + std::vector::iterator it = paramsArgs.begin(); + this->repeatNb = *it; + + switch(id) + { + case PoolingBench::TEST_AVGPOOL_S8_1: + input.reload(PoolingBench::INPUT1_S8_ID,mgr); + ref.reload(PoolingBench::REF1_S8_ID,mgr); + + this->DIM_IN_X= 4; + this->DIM_IN_Y= 2; + this->DIM_OUT_X= 2; + this->DIM_OUT_Y= 1; + this->IN_CHANNEL= 101; + this->DIM_FILTER_X= 2; + this->DIM_FILTER_Y= 2; + this->PAD_WIDTH= 0; + this->PAD_HEIGHT= 0; + this->STRIDE_X= 2; + this->STRIDE_Y= 2; + this->ACT_MIN= -128; + this->ACT_MAX= 127; + + break; + + + } + temp.create(this->DIM_OUT_X * this->IN_CHANNEL,PoolingBench::TEMP_S8_ID,mgr); + + output.create(ref.nbSamples(),PoolingBench::OUTPUT_S8_ID,mgr); + tmpInput.create(input.nbSamples(),PoolingBench::TEMPINPUT_S8_ID,mgr); + + q7_t *tmpin = tmpInput.ptr(); + const q7_t *inp = input.ptr(); + + memcpy(tmpin,inp,input.nbSamples()); + + + } + + void PoolingBench::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) + { + + } diff --git a/Testing/addToDB.py b/Testing/addToDB.py index ea4c9715..580e2139 100755 --- a/Testing/addToDB.py +++ b/Testing/addToDB.py @@ -275,7 +275,7 @@ parser = argparse.ArgumentParser(description='Generate summary benchmarks') parser.add_argument('-f', nargs='?',type = str, default=None, help="Test description file path") parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path") -parser.add_argument('-e', action='store_true', help="Embedded test") +#parser.add_argument('-e', action='store_true', help="Embedded test") parser.add_argument('-o', nargs='?',type = str, default="bench.db", help="Benchmark database") parser.add_argument('others', nargs=argparse.REMAINDER) diff --git a/Testing/bench.db b/Testing/bench.db index 25570985b60f136c4d16a24b9e0c4640ed4e969b..ddbeba1b2fcd68dc0ade87196f9ff89967d70322 100755 GIT binary patch delta 815 zcmZo@U~O2yIzd{{mVtpm6o_F!XrhiWqwU6oCF=#)_#+tj@AL2DpUYp%pUxk#SbX4EzuH=kf37uj9|)j|8f8<>%*PR%ApdWZRr^ zeog`p3u_JouMgK8_AjhCn-v9OSp8dBh1kVaRT(>dOA?cEQlaKLrRF7PAhSiCgIpa$ zTopnboqSvskYyA!ka?2@dBwJ$6<}0h+Wys?k()z;7w9z(-g^xEd-yB(P59pPt>#PT zQ|7$~wEY-wy)%ap0~4b*Co?A}CkGHRayl|HoM0qEK4r{`ZB)QLYn&$tC4}B zrLKXwu92mJfw`5DrImrPo|%D#rKLH$6T1)tBbp&8=w|RXYGImDk7NiNrXeEehA?eS z#54rS3|34txX{gD3}b_vQIEwp&MagGiHVh|iJpm}F)&ovotQCQf+a}mF~S7J5GG7R ahzSxDGZ-<=Km>^zG=h=C1R5mBh5!Jxp}8{v delta 106 zcmZozz}nEjIzd{{l7WFi1c+fkaH5VeqvghgCF}WE`O_Kr@AL2DpUYp%pT1epAe4V{ z`u@2<@eBt32mJH+_w(2BX8^^+_%~;qpOe7F%>IRe*N1Bk` PARAM1_ID } } + + suite Pooling Benchmarks { + class = PoolingBench + folder = Pooling + + ParamList { + NB + Summary NB + Names "Repetition" + Formula "NB" + } + + Pattern INPUT1_S8_ID : Input1.txt + Pattern REF1_S8_ID : Ref1.txt + + Output OUTPUT_S8_ID : Output + Output TEMP_S8_ID : Temp + Output TEMPINPUT_S8_ID : TempInput + + Params PARAM1_ID = { + NB = [10,20,100,200] + } + + Functions { + arm_avgpool_s8 Test 1:test_avgpool_s8 -> PARAM1_ID + } + } } }