Reduce complexity of ssd_multibox example
[tidl/tidl-api.git] / tinn_api / src / executor.cpp
index 6ca2d63f94e5fda6faff874cd1aa3dc186e6710e..e16f6d0eca7132a9828b13d9c2deeabef825ca23 100644 (file)
@@ -11,10 +11,10 @@ using namespace tinn;
 using std::unique_ptr;
 
 Executor::Executor(DeviceType core_type, const DeviceIds& ids,
 using std::unique_ptr;
 
 Executor::Executor(DeviceType core_type, const DeviceIds& ids,
-                   const Configuration& configuration)
+                   const Configuration& configuration, int layers_group_id)
 {
     pimpl_m = unique_ptr<ExecutorImpl>
 {
     pimpl_m = unique_ptr<ExecutorImpl>
-              { new ExecutorImpl(core_type, ids) };
+              { new ExecutorImpl(core_type, ids, layers_group_id) };
     pimpl_m->Initialize(configuration);
 }
 
     pimpl_m->Initialize(configuration);
 }
 
@@ -45,11 +45,13 @@ std::string Executor::GetAPIVersion()
 }
 
 
 }
 
 
-ExecutorImpl::ExecutorImpl(DeviceType core_type, const DeviceIds& ids):
+ExecutorImpl::ExecutorImpl(DeviceType core_type, const DeviceIds& ids,
+                           int layers_group_id):
     configuration_m(),
     shared_networkparam_heap_m(nullptr, &__free_ddr),
     device_ids_m(ids),
     configuration_m(),
     shared_networkparam_heap_m(nullptr, &__free_ddr),
     device_ids_m(ids),
-    core_type_m(core_type)
+    core_type_m(core_type),
+    layers_group_id_m(layers_group_id)
 {
     std::string name;
     if (core_type_m == DeviceType::DSP)
 {
     std::string name;
     if (core_type_m == DeviceType::DSP)
@@ -74,7 +76,7 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
     up_malloc_ddr<TIDL_CreateParams> shared_createparam(
                                             malloc_ddr<TIDL_CreateParams>(),
                                             &__free_ddr);
     up_malloc_ddr<TIDL_CreateParams> shared_createparam(
                                             malloc_ddr<TIDL_CreateParams>(),
                                             &__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;
 
     // Read network from file into network struct in TIDL_CreateParams
     sTIDL_Network_t *net = &(shared_createparam.get())->net;
@@ -87,6 +89,14 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
     //TODO: Why is this set here?
     net->interElementSize = 4;
 
     //TODO: Why is this set here?
     net->interElementSize = 4;
 
+    // Force to run full network if runFullNet is set
+    if (configuration.runFullNet)
+    {
+        for (int i = 0; i < net->numLayers; i++)
+            if (net->TIDLLayers[i].layerType != TIDL_DataLayer)
+                net->TIDLLayers[i].layersGroupId = layers_group_id_m;
+    }
+
     // Call a setup kernel to allocate and fill network parameters
     InitializeNetworkParams(shared_createparam.get());
 
     // Call a setup kernel to allocate and fill network parameters
     InitializeNetworkParams(shared_createparam.get());
 
@@ -101,7 +111,8 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
              unique_ptr<ExecutionObject>
              {new ExecutionObject(device_m.get(), index,
                                   create_arg, param_heap_arg,
              unique_ptr<ExecutionObject>
              {new ExecutionObject(device_m.get(), index,
                                   create_arg, param_heap_arg,
-                                  configuration_m.EXTMEM_HEAP_SIZE)} );
+                                  configuration_m.EXTMEM_HEAP_SIZE,
+                                  configuration_m.enableInternalInput)} );
     }
 
     for (auto &eo : execution_objects_m)
     }
 
     for (auto &eo : execution_objects_m)
@@ -176,10 +187,11 @@ void ExecutorImpl::Cleanup()
 }
 
 
 }
 
 
-void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP)
+void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP,
+                                          const Configuration& configuration)
 {
 {
-    CP->currCoreId           = tinn::internal::CURR_CORE_ID;
-    CP->currLayersGroupId    = tinn::internal::CURR_LAYERS_GROUP_ID;
+    CP->currCoreId           = layers_group_id_m;
+    CP->currLayersGroupId    = layers_group_id_m;
     CP->l1MemSize            = tinn::internal::DMEM0_SIZE;
     CP->l2MemSize            = tinn::internal::DMEM1_SIZE;
     CP->l3MemSize            = tinn::internal::OCMC_SIZE;
     CP->l1MemSize            = tinn::internal::DMEM0_SIZE;
     CP->l2MemSize            = tinn::internal::DMEM1_SIZE;
     CP->l3MemSize            = tinn::internal::OCMC_SIZE;