From c0aaf795d8f486a7d46b23a64b36f6b01d924161 Mon Sep 17 00:00:00 2001 From: Yuan Zhao Date: Tue, 27 Aug 2019 13:56:02 -0500 Subject: [PATCH] Control heap size and alloc opt using env vars - TIDL_PARAM_HEAP_SIZE_EVE, TIDL_PARAM_HEAP_SIZE_DSP, TIDL_NETWORK_HEAP_SIZE_EVE, TIDL_NETWORK_HEAP_SIZE_DSP, TIDL_EXTMEM_ALLOC_OPT_EVE, TIDL_EXTMEM_ALLOC_OPT_DSP are provided to overwrite the heap sizes and heap allocation optimization level (1 or 2) that are specified by default or by application. - MCT-1215 --- docs/source/using_api.rst | 13 +++++++++++++ tidl_api/src/configuration.cpp | 4 ++-- tidl_api/src/executor.cpp | 29 +++++++++++++++++++++++++++-- tidl_api/src/executor_impl.h | 1 + tidl_api/src/parameters.h | 2 ++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/docs/source/using_api.rst b/docs/source/using_api.rst index 47c0d9c..80d8a74 100644 --- a/docs/source/using_api.rst +++ b/docs/source/using_api.rst @@ -280,7 +280,20 @@ and the ``configuration.showHeapStats = true`` line can be removed. The memory for parameter and network heaps is itself allocated from OpenCL global memory (CMEM). Refer :ref:`opencl-global-memory` for details. +In addition, the following environment variables are provided to overwrite +the heap sizes and heap allocation optimization level (1 or 2) that are +specified by default or by application. +.. code-block:: bash + + TIDL_PARAM_HEAP_SIZE_EVE + TIDL_PARAM_HEAP_SIZE_DSP + TIDL_NETWORK_HEAP_SIZE_EVE + TIDL_NETWORK_HEAP_SIZE_DSP + TIDL_EXTMEM_ALLOC_OPT_EVE + TIDL_EXTMEM_ALLOC_OPT_DSP + # # for example, + # TIDL_PARAM_HEAP_SIZE_EVE=3000000 TIDL_NETWORK_HEAP_SIZE_EVE=21000000 TIDL_PARAM_HEAP_SIZE_DSP=3000000 TIDL_NETWORK_HEAP_SIZE_DSP=2000000 ./tidl_classification -g 2 -d 1 -e 4 -l ./imagenet.txt -s ./classlist.txt -i ./clips/test10.mp4 -c ./stream_config_j11_v2.txt .. _network_layer_output: diff --git a/tidl_api/src/configuration.cpp b/tidl_api/src/configuration.cpp index 8f512e8..c67b22c 100644 --- a/tidl_api/src/configuration.cpp +++ b/tidl_api/src/configuration.cpp @@ -39,8 +39,8 @@ Configuration::Configuration(): numFrames(0), inHeight(0), inWidth(0), noZeroCoeffsPercentage(100), preProcType(0), runFullNet(false), - NETWORK_HEAP_SIZE(64 << 20), // 64MB for inceptionNetv1 - PARAM_HEAP_SIZE(9 << 20), // 9MB for mobileNet1 + NETWORK_HEAP_SIZE(internal::DEFAULT_NETWORK_HEAP_SIZE), + PARAM_HEAP_SIZE(internal::DEFAULT_PARAM_HEAP_SIZE), enableOutputTrace(false), enableApiTrace(false), showHeapStats(false), diff --git a/tidl_api/src/executor.cpp b/tidl_api/src/executor.cpp index 8020d4e..7a86040 100644 --- a/tidl_api/src/executor.cpp +++ b/tidl_api/src/executor.cpp @@ -27,6 +27,7 @@ *****************************************************************************/ #include +#include #include "executor.h" #include "executor_impl.h" #include "parameters.h" @@ -85,7 +86,8 @@ ExecutorImpl::ExecutorImpl(DeviceType core_type, const DeviceIds& ids, shared_networkparam_heap_m(nullptr, &__free_ddr), device_ids_m(ids), core_type_m(core_type), - layers_group_id_m(layers_group_id) + layers_group_id_m(layers_group_id), + extmem_alloc_opt_m(TIDL_optimiseExtMemL1) { std::string name = STRING(SETUP_KERNEL) ";" STRING(INIT_KERNEL) ";" STRING(PROCESS_KERNEL) ";" STRING(CLEANUP_KERNEL); @@ -107,6 +109,29 @@ bool ExecutorImpl::Initialize(const Configuration& configuration) { configuration_m = configuration; + // Env Vars: Overwrite default heap sizes and allocation optimization level + char *param_heap = nullptr; + char *network_heap = nullptr; + char *extmem_opt = nullptr; + if (core_type_m == DeviceType::DSP) + { + param_heap = getenv("TIDL_PARAM_HEAP_SIZE_DSP"); + network_heap = getenv("TIDL_NETWORK_HEAP_SIZE_DSP"); + extmem_opt = getenv("TIDL_EXTMEM_ALLOC_OPT_DSP"); + } + else + { + param_heap = getenv("TIDL_PARAM_HEAP_SIZE_EVE"); + network_heap = getenv("TIDL_NETWORK_HEAP_SIZE_EVE"); + extmem_opt = getenv("TIDL_EXTMEM_ALLOC_OPT_EVE"); + } + if (param_heap != nullptr) + configuration_m.PARAM_HEAP_SIZE = atoi(param_heap); + if (network_heap != nullptr) + configuration_m.NETWORK_HEAP_SIZE = atoi(network_heap); + if (extmem_opt != nullptr && *extmem_opt == '2') + extmem_alloc_opt_m = TIDL_optimiseExtMemL2; + // Allocate, initialize TIDL_CreateParams object up_malloc_ddr shared_createparam( malloc_ddr(), @@ -251,7 +276,7 @@ void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP, if (configuration_m.enableOutputTrace) CP->optimiseExtMem = TIDL_optimiseExtMemL0; else - CP->optimiseExtMem = TIDL_optimiseExtMemL1; + CP->optimiseExtMem = extmem_alloc_opt_m; } Exception::Exception(const std::string& error, const std::string& file, diff --git a/tidl_api/src/executor_impl.h b/tidl_api/src/executor_impl.h index bc6b187..8e79351 100644 --- a/tidl_api/src/executor_impl.h +++ b/tidl_api/src/executor_impl.h @@ -74,6 +74,7 @@ class ExecutorImpl DeviceIds device_ids_m; DeviceType core_type_m; int layers_group_id_m; + eTIDL_optimiseExtMem extmem_alloc_opt_m; }; } // namespace tidl diff --git a/tidl_api/src/parameters.h b/tidl_api/src/parameters.h index 6c66358..721feec 100644 --- a/tidl_api/src/parameters.h +++ b/tidl_api/src/parameters.h @@ -31,6 +31,8 @@ namespace tidl { namespace internal { +const size_t DEFAULT_PARAM_HEAP_SIZE = (9<<20); // 9MB for mobileNet1 +const size_t DEFAULT_NETWORK_HEAP_SIZE = (64<<20); // 64MB for inceptionNetv1 const size_t DMEM0_SIZE = 8*1024; const size_t DMEM1_SIZE = 128*1024; const size_t OCMC_SIZE = 320*1024; -- 2.39.2