Reduce complexity of ssd_multibox example
[tidl/tidl-api.git] / tinn_api / src / executor.cpp
index fcba2e4ea52838cfc0d509f0324e46c7a32fe64e..e16f6d0eca7132a9828b13d9c2deeabef825ca23 100644 (file)
@@ -6,15 +6,15 @@
 #include "trace.h"
 
 
-using namespace tidl;
+using namespace tinn;
 
 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>
-              { new ExecutorImpl(core_type, ids) };
+              { new ExecutorImpl(core_type, ids, layers_group_id) };
     pimpl_m->Initialize(configuration);
 }
 
@@ -29,25 +29,37 @@ Executor::Executor(DeviceType core_type, const DeviceIds& ids,
 // on demand in the caller’s code where impl is not defined.
 Executor::~Executor() = default;
 
-uint32_t Executor::GetNumDevicesSupportingTIDL(DeviceType device_type)
+uint32_t Executor::GetNumDevices(DeviceType device_type)
 {
-    return Device::GetNumDevicesSupportingTIDL(device_type);
+    return Device::GetNumDevices(device_type);
 }
 
-ExecutorImpl::ExecutorImpl(DeviceType core_type, const DeviceIds& ids):
+#define STRING(S)  XSTRING(S)
+#define XSTRING(S) #S
+std::string Executor::GetAPIVersion()
+{
+    static std::string version = STRING(_BUILD_VER);
+    version += ".";
+    version += STRING(_BUILD_SHA);
+    return version;
+}
+
+
+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),
-    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)
-        name  = "ocl_wrapper.out";
+        name  = "";
     else if (core_type_m == DeviceType::DLA)
         name = STRING(SETUP_KERNEL) ";" STRING(INIT_KERNEL) ";" STRING(PROCESS_KERNEL) ";" STRING(CLEANUP_KERNEL);
 
     device_m = Device::Create(core_type_m, ids, name);
-
 }
 
 
@@ -64,7 +76,7 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
     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;
@@ -77,6 +89,14 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
     //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());
 
@@ -91,7 +111,8 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
              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)
@@ -166,17 +187,18 @@ void ExecutorImpl::Cleanup()
 }
 
 
-void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP)
+void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP,
+                                          const Configuration& configuration)
 {
-    CP->currCoreId           = tidl::internal::CURR_CORE_ID;
-    CP->currLayersGroupId    = tidl::internal::CURR_LAYERS_GROUP_ID;
-    CP->l1MemSize            = tidl::internal::DMEM0_SIZE;
-    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->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->quantHistoryParam1   = tinn::internal::QUANT_HISTORY_PARAM1;
+    CP->quantHistoryParam2   = tinn::internal::QUANT_HISTORY_PARAM2;
+    CP->quantMargin          = tinn::internal::QUANT_MARGIN;
     CP->optimiseExtMem       = TIDL_optimiseExtMemL1;
 }