Control heap size and alloc opt using env vars
authorYuan Zhao <yuanzhao@ti.com>
Tue, 27 Aug 2019 18:56:02 +0000 (13:56 -0500)
committerYuan Zhao <yuanzhao@ti.com>
Tue, 27 Aug 2019 18:57:26 +0000 (13:57 -0500)
- 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
tidl_api/src/configuration.cpp
tidl_api/src/executor.cpp
tidl_api/src/executor_impl.h
tidl_api/src/parameters.h

index 47c0d9c6db38636089083b1d80d5d7c2e3f721f0..80d8a7490ba99f7be077b89b60b81d3fe377c098 100644 (file)
@@ -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:
 
index 8f512e8654d9d8fdce08732eaf093597e1628df3..c67b22c75afc4cece552315fd242c248e3253e06 100644 (file)
@@ -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),
index 8020d4e104f4fb1444582e635b718d1c40cab1e3..7a860408ef4c678d0a2c098e71c07ef602e0cf60 100644 (file)
@@ -27,6 +27,7 @@
  *****************************************************************************/
 
 #include <assert.h>
+#include <cstdlib>
 #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<TIDL_CreateParams> shared_createparam(
                                             malloc_ddr<TIDL_CreateParams>(),
@@ -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,
index bc6b187668714039e48ce9bfdb600ee019f705c6..8e7935105556c09bbc2704ac5938df2c4e40c1b6 100644 (file)
@@ -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
index 6c6635830e4489f5ef338cc442318a387c3a5e3e..721feec802c2d3196c8165bc1180ac5b165b8040 100644 (file)
@@ -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;