[MODEL/META] Verify the magiccode in npubinfmt's metadata
authorDongju Chae <dongju.chae@samsung.com>
Fri, 3 Jan 2020 05:09:28 +0000 (14:09 +0900)
committer파리차이카푸르/On-Device Lab(SR)/Engineer/삼성전자 <pk.kapoor@samsung.com>
Tue, 7 Jan 2020 09:59:09 +0000 (18:59 +0900)
This commit verifies the magiccode in npubinfmt's metadata.
Also, it updates related unitttests to use the default magiccode.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/ne-handler.c
src/test/apptests/async_callbacks.c
src/test/apptests/dmabuf_buffers.c
src/test/apptests/dmabuf_model.c
src/test/apptests/dummy_inference.c
src/test/apptests/example_visa.c
src/test/unittests/ne_core_comm_ip_test.cpp
src/test/unittests/ne_core_handler_test.cpp
src/test/unittests/ne_core_inf_test.cpp

index b5a6bc6..ead6999 100644 (file)
@@ -137,6 +137,12 @@ parse_model_meta (model_priv* mpriv, void *binary)
 
   memcpy (meta, binary, NPUBIN_META_SIZE);
 
+  /* check the metadata is really for SRNPU HW */
+  if (!CHECK_NPUBIN(meta->magiccode)) {
+    logerr (TAG, "invalid magiccode %llx\n", meta->magiccode);
+    return -EINVAL;
+  }
+
   return 0;
 }
 
@@ -251,6 +257,7 @@ handler_register_model (hwmem *hwmem, uint64_t *id, uint64_t *version)
     hpriv.model_size += hwmem->size;
   } else {
     /* set dummy metadata */
+    mpriv->meta.magiccode = NPUBIN_MAGICCODE | 0x1;
     mpriv->meta.type = SMODEL_OPS_NPU_ASR;
     mpriv->meta.size = 0;
     mpriv->meta.buffer_size = 4096;
index 950d9c8..b42580d 100644 (file)
@@ -87,6 +87,7 @@ run_inference (npudev_h dev)
   /* make dummy model data */
   npubin_meta meta = {
     /* below are compiler stuff */
+    .magiccode = NPUBIN_MAGICCODE | 0x1,
     .name = "dummy model",
     .model_id = 1,
     .model_version = 1,
index e9a88a4..1e9b195 100644 (file)
 #include "../../core/ne-conf.h"
 
 /** @brief compare output result with the golden data */
-static int 
+static int
 compare_result (const void *data, uint32_t size)
 {
   /* @todo */
-  return 0; 
+  return 0;
 }
 
 /** @brief inference entry */
@@ -54,6 +54,7 @@ run_inference (npudev_h dev)
   /* make dummy model data */
   npubin_meta meta = {
     /* below are compiler stuff */
+    .magiccode = NPUBIN_MAGICCODE | 0x1,
     .name = "dummy model",
     .model_id = 1,
     .model_version = 1,
index 346d30c..8517444 100644 (file)
 #include "../../core/ne-conf.h"
 
 /** @brief compare output result with the golden data */
-static int 
+static int
 compare_result (const void *data, uint32_t size)
 {
   /* @todo */
-  return 0; 
+  return 0;
 }
 
 /** @brief inference entry */
@@ -54,6 +54,7 @@ run_inference (npudev_h dev)
   /* make dummy model data */
   npubin_meta meta = {
     /* below are compiler stuff */
+    .magiccode = NPUBIN_MAGICCODE | 0x1,
     .name = "dummy model",
     .model_id = 1,
     .model_version = 1,
index f6a88e1..7e0236c 100644 (file)
 #include "../ne_test_utils.h"
 
 /** @brief compare output result with the golden data */
-static int 
+static int
 compare_result (const void *data, uint32_t size)
 {
   /* @todo */
-  return 0; 
+  return 0;
 }
 
 /** @brief inference entry */
@@ -55,6 +55,7 @@ run_inference (npudev_h dev)
   /* make dummy model data */
   npubin_meta meta = {
     /* below are compiler stuff */
+    .magiccode = NPUBIN_MAGICCODE | 0x1,
     .name = "dummy model",
     .model_id = 1,
     .model_version = 1,
index b017902..e46f35f 100644 (file)
@@ -27,7 +27,7 @@ static int total_succs;
 static int total_fails;
 
 /** @brief compare output result with the golden data */
-static int 
+static int
 compare_result (const char *golden_path, const char *output_data, uint64_t output_size)
 {
   FILE *fp = fopen (golden_path, "r");
@@ -209,13 +209,13 @@ main (int argc, char **argv)
   }
 
   total_succs = total_fails = 0;
-  
+
   result = run_inference (dev, argv[1]);
 
   fprintf(stderr, "[APPTEST] %s: %s (%d/%d)\n", argv[0],
       result == 0 ? "PASSED" : "FAILED",
       total_succs, total_succs + total_fails);
+
   free (dev);
 
   return result;
index f6a9362..7dbecbc 100644 (file)
@@ -101,6 +101,7 @@ const size_t output_size = 2048;
  * @param[in] name a string to be set to the name member of this meta
  */
 static inline void set_default_val_to_meta (npubin_meta *meta, const char *name) {
+  meta->magiccode = NPUBIN_MAGICCODE | 0x1;
   if (!name) {
     strncpy (meta->name, "", max_len_model_name - 1);
   } else {
index 4b9392e..ce37832 100644 (file)
@@ -25,7 +25,7 @@ extern "C"
 }
 
 /** configuration to fill the model meta */
-#define MAGICCODE 0x10101101
+#define MAGICCODE (NPUBIN_MAGICCODE | 0x1)
 
 static const hostHandlerInfo *host_handle = NULL;
 
index 24e7647..4420b5e 100644 (file)
@@ -25,7 +25,7 @@ extern "C"
 }
 
 /** configuration to fill the model meta */
-#define MAGICCODE 0x10101101
+#define MAGICCODE (NPUBIN_MAGICCODE | 0x1)
 #define STOP_SLEEP 1
 #define SLEEP_DURATION 2