[FIX/RUN_SYNC] Fix the timing issue due to early inference completion
authorDongju Chae <dongju.chae@samsung.com>
Tue, 26 Nov 2019 11:07:28 +0000 (20:07 +0900)
committer송욱/On-Device Lab(SR)/Staff Engineer/삼성전자 <wook16.song@samsung.com>
Thu, 28 Nov 2019 00:46:18 +0000 (09:46 +0900)
This commit fixes the timing issue caused when `run_sync()`'s inference is finished too
early. This patch introduces an extra variable to check whether the callback is
called or not.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/ip/plugin-comm-ip.c

index d7e8eb1..bcd3e66 100644 (file)
@@ -943,6 +943,7 @@ out:
 typedef struct {
   npu_device *npu_dev;
   output_buffer *user_output;
+  bool handled;
 } sync_cb_data;
 
 /**
@@ -969,6 +970,7 @@ static void sync_callback (output_buffer *output, uint64_t sequence,
   if (err < 0) {
     logerr (TAG, "Error setting output buffer, errno: %d\n", err);
   }
+  cb_data->handled = true;
 
   /** wake the sync process up, if any */
   DEVICE_WAKEUP();
@@ -997,6 +999,7 @@ int runNPU_sync(npudev_h dev, uint32_t modelid, const input_buffers *input,
   sync_cb_data cb_data = {
     .npu_dev = dev,
     .user_output = output,
+    .handled = false,
   };
 
   npu_dev = dev;
@@ -1015,7 +1018,8 @@ int runNPU_sync(npudev_h dev, uint32_t modelid, const input_buffers *input,
 
   /** wait until the internal callback is finished */
   DEVICE_LOCK();
-  DEVICE_WAIT();
+  if (!cb_data.handled)
+    DEVICE_WAIT();
   DEVICE_UNLOCK();
 
   return 0;