[FPGA] Fix logic to compare output data
authorDongju Chae <dongju.chae@samsung.com>
Tue, 27 Jul 2021 08:18:54 +0000 (17:18 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Wed, 28 Jul 2021 08:07:28 +0000 (17:07 +0900)
This patch fixes logic to compare output data.
Also, don't use output buffers allocated by a NPU driver in FPGA.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
tests/utils/ne_test_utils.cc
tests/utils/ne_test_utils_common.cc

index 0722608862c12904d70e01f8d5f52a004b9f0479..767878e9c721ec435f2baf58cd78ed5ba67c88be 100644 (file)
@@ -792,6 +792,9 @@ UtilTRIV2::prepare_model (UtilModel *model) {
     input->bufs[idx].type = BUFFER_FILE;
   }
 
+#ifdef __FPGA__
+  return 0;
+#else
   output->num_buffers = meta->output_seg_num;
 
   for (uint32_t idx = 0; idx < meta->output_seg_num; idx++) {
@@ -802,4 +805,5 @@ UtilTRIV2::prepare_model (UtilModel *model) {
   }
 
   return allocNPU_genericBuffers (dev_, output);
+#endif
 }
index ba651906df998239f4b32c020cb2e5243600477c..544c502709ddc2aaf25530cc09b46c0fc34947c0 100644 (file)
@@ -19,11 +19,16 @@ using namespace std;
 #include <fstream>
 #include <iomanip>
 
+#include <iterator>
+#include <vector>
+#include <algorithm>
+
 #include <errno.h>
 #include <sys/stat.h>
 #include <inttypes.h>
 
-#define HEX(val) hex << setfill ('0') << setw (2) << (0xff & ((uint8_t) val))
+#define HEX32(val) hex << (0xffffffff & ((uint32_t) val))
+#define HEX8(val) hex << setfill ('0') << setw (2) << (0xff & ((uint8_t) val))
 
 /**
  * @brief get the size of file
@@ -65,22 +70,31 @@ compare_data (const char *golden_path, const char *output_data,
     return -ERANGE;
   }
 
-  off_t idx = 0;
-  char byte;
-  int err = 0;
-
   ios_base::fmtflags flags (cerr.flags ());
   ifs.seekg (0, ios::beg);
 
-  while (ifs.read ((char *) &byte, 1)) {
-    if (byte != output_data[idx]) {
-      cerr << "Hex diff at " << idx << " (0x" << HEX (byte);
-      cerr << " vs. 0x" << HEX (output_data[idx]) << ")\n";
-      err = -EINVAL;
-      break;
-    }
-    idx++;
+  vector<uint8_t> output_vec (output_data, output_data + output_size);
+  vector<uint8_t> golden_vec;
+  golden_vec.reserve (length);
+  golden_vec.insert (golden_vec.begin (), istreambuf_iterator<char> (ifs),
+                     istreambuf_iterator<char> ());
+
+  /* find the first mismatch */
+  int err = 0;
+  auto mispair =
+      mismatch (golden_vec.begin (), golden_vec.end (), output_vec.begin ());
+  if (mispair.first != golden_vec.end ()) {
+    uint32_t idx = distance (golden_vec.begin (), mispair.first);
+
+    cerr << "[ERROR] Output mismatch detected!\n";
+    cerr << "- Index: 0x" << HEX32 (idx);
+    cerr << ", Golden: 0x" << HEX8 (*mispair.first);
+    cerr << ", Output: 0x" << HEX8 (*mispair.second);
+    cerr << "\n\n";
+
+    err = -EINVAL;
   }
+
   cerr.flags (flags);
 
   return err;