]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blobdiff - tidl_api/src/executor.cpp
ExecutionObjectPipeline for executing layersGroups
[tidl/tidl-api.git] / tidl_api / src / executor.cpp
index 6283a98406e27d19c1f99a93781ecc7b5b7d06f2..914c78ab58104eeba379db5ae8305e45537d007e 100644 (file)
@@ -96,6 +96,12 @@ const ExecutionObjects& Executor::GetExecutionObjects() const
     return pimpl_m->execution_objects_m;
 }
 
+ExecutionObject* Executor::operator[](uint32_t index) const
+{
+    assert(index < pimpl_m->execution_objects_m.size());
+    return pimpl_m->execution_objects_m[index].get();
+}
+
 bool ExecutorImpl::Initialize(const Configuration& configuration)
 {
     configuration_m = configuration;
@@ -104,7 +110,7 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
     up_malloc_ddr<TIDL_CreateParams> shared_createparam(
                                             malloc_ddr<TIDL_CreateParams>(),
                                             &__free_ddr);
-    InitializeNetworkCreateParam(shared_createparam.get(), configuration);
+    InitializeNetworkCreateParam(shared_createparam.get());
 
     // Read network from file into network struct in TIDL_CreateParams
     sTIDL_Network_t *net = &(shared_createparam.get())->net;
@@ -114,9 +120,6 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
                              sizeof(sTIDL_Network_t));
     assert(status != false);
 
-    //TODO: Why is this set here?
-    net->interElementSize = 4;
-
     // Force to run full network if runFullNet is set
     if (configuration.runFullNet)
     {
@@ -125,6 +128,14 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
                 net->TIDLLayers[i].layersGroupId = layers_group_id_m;
     }
 
+    // If the user has specified an override mapping, apply it
+    else if (!configuration.layerIndex2LayerGroupId.empty())
+    {
+        for (const auto &item : configuration.layerIndex2LayerGroupId)
+            if (item.first < net->numLayers)
+                net->TIDLLayers[item.first].layersGroupId = item.second;
+    }
+
     // Call a setup kernel to allocate and fill network parameters
     InitializeNetworkParams(shared_createparam.get());
 
@@ -140,6 +151,8 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
              {new ExecutionObject(device_m.get(), index,
                                   create_arg, param_heap_arg,
                                   configuration_m.EXTMEM_HEAP_SIZE,
+                                  layers_group_id_m,
+                                  configuration_m.enableOutputTrace,
                                   configuration_m.enableInternalInput)} );
     }
 
@@ -183,12 +196,16 @@ bool ExecutorImpl::InitializeNetworkParams(TIDL_CreateParams *cp)
     // kernel to allocate and initialize network parameters for the layers
     shared_networkparam_heap_m.reset(malloc_ddr<char>(setupParams->networkParamHeapSize));
 
-    KernelArgs args = { ArgInfo(cp, sizeof(TIDL_CreateParams)),
-                        ArgInfo(networkparam.get(), networkparam_size),
-                        ArgInfo(shared_networkparam_heap_m.get(),
-                                setupParams->networkParamHeapSize),
-                        ArgInfo(setupParams.get(),
-                                sizeof(OCL_TIDL_SetupParams)) };
+    KernelArgs args = { DeviceArgInfo(cp, sizeof(TIDL_CreateParams),
+                                      DeviceArgInfo::Kind::BUFFER),
+                        DeviceArgInfo(networkparam.get(), networkparam_size,
+                                      DeviceArgInfo::Kind::BUFFER),
+                        DeviceArgInfo(shared_networkparam_heap_m.get(),
+                                      setupParams->networkParamHeapSize,
+                                      DeviceArgInfo::Kind::BUFFER),
+                        DeviceArgInfo(setupParams.get(),
+                                      sizeof(OCL_TIDL_SetupParams),
+                                      DeviceArgInfo::Kind::BUFFER) };
 
     // Execute kernel on first available device in the Executor
     uint8_t id = static_cast<uint8_t>(*(device_ids_m.cbegin()));
@@ -215,8 +232,7 @@ void ExecutorImpl::Cleanup()
 }
 
 
-void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP,
-                                          const Configuration& configuration)
+void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP)
 {
     CP->currCoreId           = layers_group_id_m;
     CP->currLayersGroupId    = layers_group_id_m;
@@ -227,7 +243,14 @@ void ExecutorImpl::InitializeNetworkCreateParam(TIDL_CreateParams *CP,
     CP->quantHistoryParam1   = tidl::internal::QUANT_HISTORY_PARAM1;
     CP->quantHistoryParam2   = tidl::internal::QUANT_HISTORY_PARAM2;
     CP->quantMargin          = tidl::internal::QUANT_MARGIN;
-    CP->optimiseExtMem       = TIDL_optimiseExtMemL1;
+
+    // If trace is enabled, setup the device TIDL library to allocate separate
+    // output buffers for each layer. This makes it possible for the host
+    // to access the output of each layer after a frame is processed.
+    if (configuration_m.enableOutputTrace)
+        CP->optimiseExtMem       = TIDL_optimiseExtMemL0;
+    else
+        CP->optimiseExtMem       = TIDL_optimiseExtMemL1;
 }
 
 Exception::Exception(const std::string& error, const std::string& file,
@@ -275,4 +298,3 @@ const char* Exception::what() const noexcept
 {
     return message_m.c_str();
 }
-