[FIX/FPGA] Enable data manipulation in FPGA env.
authorDongju Chae <dongju.chae@samsung.com>
Thu, 27 May 2021 05:56:01 +0000 (14:56 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Thu, 27 May 2021 09:00:52 +0000 (18:00 +0900)
This patch enables data manipulation in FPGA env.
It also adds a test option to enabel TRIV2 data format.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/ne-handler.cc
tests/utils/ne_test_utils.cc
tests/utils/ne_test_utils.h

index 1cd9918..8a77b2e 100644 (file)
@@ -1063,23 +1063,34 @@ TrinityVision2::callback (Request *req, npuOutputNotify cb, void *cb_data) {
       output.bufs[idx].size = output_tensor_size;
       /** user needs to free this */
       output.bufs[idx].addr = calloc (1, output_tensor_size);
+      if (output.bufs[idx].addr == NULL) {
+        logerr (TAG, "Unable to allocate output buffer\n");
+        break;
+      }
 
-#ifdef __FPGA__
-      api_->fpga_memcpy (output_segment->getDmabuf (),
-                         segt->getOutputSegmentOffset (idx),
-                         output.bufs[idx].addr, output.bufs[idx].size);
-#else
       auto func = std::bind (TrinityVision2::manipulateData, model, idx, false,
                              std::placeholders::_1, std::placeholders::_2,
                              std::placeholders::_3);
-      int status =
-          comm_.insertGenericBuffer (segt->getOutputSegment (idx)->getData () +
-                                         segt->getOutputSegmentOffset (idx),
-                                     &output.bufs[idx], func);
-
+      void *dst;
+#ifdef __FPGA__
+      /* this is fpga workaround codes for syncing output data */
+      dst = calloc (1, output_tensor_size);
+      if (dst == NULL) {
+        logerr (TAG, "Unable to allocate FPGA temp buffer\n");
+        break;
+      }
+      api_->fpga_memcpy (output_segment->getDmabuf (),
+                         segt->getOutputSegmentOffset (idx), dst,
+                         output_tensor_size);
+#else
+      dst = output_segment->getData () + segt->getOutputSegmentOffset (idx);
+#endif
+      int status = comm_.insertGenericBuffer (dst, &output.bufs[idx], func);
       if (status != 0) {
         logerr (TAG, "Failed to return output buffer: %d\n", status);
       }
+#ifdef __FPGA__
+      free (dst);
 #endif
     }
   }
index a41b4b5..41d03b1 100644 (file)
@@ -217,6 +217,7 @@ UtilTrinity::UtilTrinity (dev_type type, bool need_model, bool verify) {
   need_model_ = need_model;
   verify_ = verify;
 
+  trinity_format_ = false;
   mute_ = false;
   sync_ = false;
   dump_ = false;
@@ -267,6 +268,7 @@ UtilTrinity::printUsage (const char *prog_name, const char *param_str) {
   std::cerr << "  -d <arg> \t Set a device node path (e.g., /dev/triv2-0)\n";
   std::cerr << "  -n <arg> \t Set output notimode [intr|polling]\n";
   std::cerr << "  -p <arg> \t Set profile level [visa|layer]\n";
+  std::cerr << "  -t \t\t Enable trinity data format\n";
   std::cerr << "  -m \t\t Mute stdout/stderr messages\n";
   std::cerr << "  -s \t\t Enable run sync mode\n";
   std::cerr << "  -o \t\t Enable output dump mode\n";
@@ -322,7 +324,7 @@ UtilTrinity::parseArgs (int argc, char **argv, char **param,
 
   optind = 0;
   opterr = 0;
-  while ((c = getopt (argc, argv, "d:n:p:msho")) != -1) {
+  while ((c = getopt (argc, argv, "d:n:p:tmsho")) != -1) {
     switch (c) {
       case 'd':
         setNodePath (optarg);
@@ -333,6 +335,9 @@ UtilTrinity::parseArgs (int argc, char **argv, char **param,
       case 'p':
         setProfLevel (optarg);
         break;
+      case 't':
+        setTrinityFormat ();
+        break;
       case 'm':
         setMute ();
         break;
@@ -680,13 +685,19 @@ UtilTRIV2::set_data_info (npubin_meta *meta, uint32_t model_id) {
    */
   info_in.num_info = meta->input_seg_num;
   for (uint32_t idx = 0; idx < info_in.num_info; idx++) {
-    info_in.info[idx].layout = DATA_LAYOUT_NHWC;
+    if (trinity_format_)
+      info_in.info[idx].layout = DATA_LAYOUT_TRIV2;
+    else
+      info_in.info[idx].layout = DATA_LAYOUT_NHWC;
     info_in.info[idx].type = DATA_TYPE_QASYMM8;
   }
 
   info_out.num_info = meta->output_seg_num;
   for (uint32_t idx = 0; idx < info_out.num_info; idx++) {
-    info_out.info[idx].layout = DATA_LAYOUT_NHWC;
+    if (trinity_format_)
+      info_out.info[idx].layout = DATA_LAYOUT_TRIV2;
+    else
+      info_out.info[idx].layout = DATA_LAYOUT_NHWC;
     info_out.info[idx].type = DATA_TYPE_QASYMM8;
   }
 
index eda61e2..7d5dc1b 100644 (file)
@@ -95,6 +95,7 @@ class UtilTrinity {
   npudev_h getDeviceHandle () { return dev_; }
 
   static void setDump () { dump_ = true; }
+  void setTrinityFormat () { trinity_format_ = true; }
   void setSync () { sync_ = true; }
   void setMute ();
   void setNotiMode (const std::string mode);
@@ -133,7 +134,7 @@ class UtilTrinity {
   npu_notimode noti_mode_;
   profile_level_type prof_level_;
   bool need_model_;
-
+  bool trinity_format_;
   bool mute_;
   bool sync_;
   bool verify_;