Initialize EO::current_frame_idx_m in constructor
authorAjay Jayaraj <ajayj@ti.com>
Thu, 15 Nov 2018 16:50:37 +0000 (10:50 -0600)
committerAjay Jayaraj <ajayj@ti.com>
Thu, 15 Nov 2018 16:50:37 +0000 (10:50 -0600)
Initialize ExecutionObject::current_frame_idx_m array to 0 in the
ExecutionObject constructor to prevent out of range entries when
recording trace data.

In a pipelined processing loop, the application executes
ExecutionObject::ProcessFrameWait() on the first frame before it calls
ExecutionObject::ProcessFrameStartAsync. The side effect is that the
current_frame_idx_m is not initialized. This can result in negative
frame indices when writing trace data using ReportTrace or UpdateTrace
leading to memory errors.

Setting ExecutionObject::current_frame_idx_m to 0 in the constructor
avoids this scenario.

(MCT-1085)

tidl_api/Makefile
tidl_api/src/execution_object.cpp
tidl_api/src/util.cpp

index ea6b9dcf451dc4b972df3e6ae0ae3e52f5e54991..abae078564733d1f36d547f274741a3a8566719c 100644 (file)
@@ -74,6 +74,10 @@ CXXFLAGS += -Isrc -Iinc
 CXXFLAGS += $(BUILD_ID)
 PY_INCLUDE = -I$(PYTHON_INCLUDE_DIR) -I$(PYBIND11_INC_DIR)
 
+# pybind11 recommends setting visibility to hidden to reduce code size and
+# prevent name clashed when multiple shared libraries use pybind11
+$(HOST_OBJ_PYBIND_FILES): CXXFLAGS += -fvisibility=hidden
+
 $(DSP_OUTFILE): $(DSP_SRCFILE)
        $(MAKE) -C dsp
 
index 20c423cceadc8adda668c621cf9ab0b879b42c75..285dfde60e7efbac6127fa458cb685c3a6f5f1eb 100644 (file)
@@ -180,6 +180,9 @@ ExecutionObject::Impl::Impl(Device* d, DeviceType t, uint8_t device_index,
         EnableOutputBufferTrace();
 
     SetupProcessKernel();
+
+    for (int i = 0; i < tidl::internal::NUM_CONTEXTS; i++)
+        current_frame_idx_m[i] = 0;
 }
 
 // Pointer to implementation idiom: https://herbsutter.com/gotw/_100/:
index b09533e66596dff9cf30707e76124fef42c747e1..8fac9d0bfec036e232a0e22a1df9c9463b625f17 100644 (file)
@@ -61,11 +61,15 @@ TimeStamp::TimeStamp(const std::string& file, int num_entries):
                         num_entries_m(num_entries), file_m(file)
 {
     entries_m = new Entry[num_entries_m];
-    std::memset(entries_m, 0, sizeof(Entry)*num_entries_m);
+    if (entries_m)
+        std::memset(entries_m, 0, sizeof(Entry)*num_entries_m);
 }
 
 void TimeStamp::Update(int frame_idx, EventKind k, int type, int id)
 {
+    if (!entries_m)
+        return;
+
     int idx = frame_idx % num_entries_m;
 
     entries_m[idx].frame_idx = frame_idx;
@@ -82,11 +86,13 @@ void TimeStamp::Update(int frame_idx, EventKind k, int type, int id)
         entries_m[idx].eo2_id   = id;
         entries_m[idx].eo2_type = type;
     }
-
 }
 
 void TimeStamp::Zero(int frame_idx, EventKind k)
 {
+    if (!entries_m)
+        return;
+
     int idx = frame_idx % num_entries_m;
 
     entries_m[idx].frame_idx    = frame_idx;
@@ -96,6 +102,9 @@ void TimeStamp::Zero(int frame_idx, EventKind k)
 
 TimeStamp::~TimeStamp()
 {
+    if (!entries_m)
+        return;
+
     std::ofstream ofs;
     ofs.open(file_m, std::ofstream::out);
 
@@ -143,7 +152,6 @@ TimeStamp::~TimeStamp()
             }
 
     ofs.close();
-
     delete [] entries_m;
 }