From b702d0c0525ddbef7e9971ca9611c05eedd7d4af Mon Sep 17 00:00:00 2001 From: Ajay Jayaraj Date: Mon, 15 Oct 2018 11:49:01 -0500 Subject: [PATCH] Quantization history configuration parameters Added the following parameters to Configuration: * quantHistoryParam1 * quantHistoryParam2 * quantMargin These parameters can be specified in the configuration file or set directly in the code. (MCT-1062) --- tidl_api/inc/configuration.h | 4 ++++ tidl_api/src/configuration.cpp | 5 ++++- tidl_api/src/configuration_parser.cpp | 7 ++++++- tidl_api/src/executor.cpp | 11 ++++++----- tidl_api/src/executor_impl.h | 3 ++- tidl_api/src/parameters.h | 3 --- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tidl_api/inc/configuration.h b/tidl_api/inc/configuration.h index a26fbb9..913272a 100644 --- a/tidl_api/inc/configuration.h +++ b/tidl_api/inc/configuration.h @@ -121,6 +121,10 @@ class Configuration //! size. bool showHeapStats; + int quantHistoryParam1; + int quantHistoryParam2; + int quantMargin; + //! Default constructor. Configuration(); diff --git a/tidl_api/src/configuration.cpp b/tidl_api/src/configuration.cpp index 7896387..8f512e8 100644 --- a/tidl_api/src/configuration.cpp +++ b/tidl_api/src/configuration.cpp @@ -43,7 +43,10 @@ Configuration::Configuration(): numFrames(0), inHeight(0), inWidth(0), PARAM_HEAP_SIZE(9 << 20), // 9MB for mobileNet1 enableOutputTrace(false), enableApiTrace(false), - showHeapStats(false) + showHeapStats(false), + quantHistoryParam1(20), + quantHistoryParam2(5), + quantMargin(0) { } diff --git a/tidl_api/src/configuration_parser.cpp b/tidl_api/src/configuration_parser.cpp index 5871e71..f457560 100644 --- a/tidl_api/src/configuration_parser.cpp +++ b/tidl_api/src/configuration_parser.cpp @@ -80,7 +80,12 @@ struct ConfigParser : qi::grammar lit("outData") >> '=' >> q_path[ph::ref(x.outData) = _1] | lit("netBinFile") >> '=' >> q_path[ph::ref(x.netBinFile) = _1] | lit("paramsBinFile") >> '=' >> q_path[ph::ref(x.paramsBinFile) = _1] | - lit("enableTrace") >> '=' >> bool_[ph::ref(x.enableOutputTrace)= _1] + lit("enableTrace") >> '=' >> bool_[ph::ref(x.enableOutputTrace)= _1] | + lit("quantHistoryParam1") >> '=' >> + int_[ph::ref(x.quantHistoryParam1)= _1] | + lit("quantHistoryParam2") >> '=' >> + int_[ph::ref(x.quantHistoryParam2)= _1] | + lit("quantMargin") >> '=' >> int_[ph::ref(x.quantMargin)= _1] ; } diff --git a/tidl_api/src/executor.cpp b/tidl_api/src/executor.cpp index 9bd3a6e..2535f90 100644 --- a/tidl_api/src/executor.cpp +++ b/tidl_api/src/executor.cpp @@ -115,7 +115,7 @@ bool ExecutorImpl::Initialize(const Configuration& configuration) up_malloc_ddr shared_createparam( malloc_ddr(), &__free_ddr); - InitializeNetworkCreateParam(shared_createparam.get()); + InitializeNetworkCreateParam(shared_createparam.get(), configuration); // Read network from file into network struct in TIDL_CreateParams sTIDL_Network_t *net = &(shared_createparam.get())->net; @@ -237,7 +237,8 @@ void ExecutorImpl::Cleanup() } -void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP) +void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP, + const Configuration& c) { CP->currCoreId = layers_group_id_m; CP->currLayersGroupId = layers_group_id_m; @@ -245,9 +246,9 @@ void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP) CP->l2MemSize = tidl::internal::DMEM1_SIZE; CP->l3MemSize = tidl::internal::OCMC_SIZE; - CP->quantHistoryParam1 = tidl::internal::QUANT_HISTORY_PARAM1; - CP->quantHistoryParam2 = tidl::internal::QUANT_HISTORY_PARAM2; - CP->quantMargin = tidl::internal::QUANT_MARGIN; + CP->quantHistoryParam1 = c.quantHistoryParam1; + CP->quantHistoryParam2 = c.quantHistoryParam2; + CP->quantMargin = c.quantMargin; // If trace is enabled, setup the device TIDL library to allocate separate // output buffers for each layer. This makes it possible for the host diff --git a/tidl_api/src/executor_impl.h b/tidl_api/src/executor_impl.h index a6a8421..bc6b187 100644 --- a/tidl_api/src/executor_impl.h +++ b/tidl_api/src/executor_impl.h @@ -63,7 +63,8 @@ class ExecutorImpl ExecutionObjects execution_objects_m; private: - void InitializeNetworkCreateParam(TIDL_CreateParams *cp); + void InitializeNetworkCreateParam(TIDL_CreateParams *cp, + const Configuration& c); bool InitializeNetworkParams(TIDL_CreateParams *cp); void Cleanup(); diff --git a/tidl_api/src/parameters.h b/tidl_api/src/parameters.h index eb93fd2..3ea047e 100644 --- a/tidl_api/src/parameters.h +++ b/tidl_api/src/parameters.h @@ -34,9 +34,6 @@ namespace internal { const size_t DMEM0_SIZE = 8*1024; const size_t DMEM1_SIZE = 128*1024; const size_t OCMC_SIZE = 320*1024; -const int QUANT_HISTORY_PARAM1 = 20; -const int QUANT_HISTORY_PARAM2 = 5; -const int QUANT_MARGIN = 0; const int CURR_LAYERS_GROUP_ID = 1; const int CURR_CORE_ID = 1; -- 2.39.2