[npubinfmt/profile] Rename the magiccode's extra field
authorDongju Chae <dongju.chae@samsung.com>
Tue, 12 Jan 2021 03:16:08 +0000 (12:16 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Thu, 14 Jan 2021 03:29:02 +0000 (12:29 +0900)
This patch renames `extra` field in npubinfmt's `magiccode`.
As it's confusing with extra version, it's renamed to `extended`.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
include/common/npubinfmt.h
src/core/ne-handler.cc
src/core/ne-model.h
src/host/ne-host.cc

index ad08ca4..2d86dbc 100644 (file)
 
 /* unit size of metadata (minimal size) */
 #define NPUBIN_META_SIZE (4096)
-/* number of extra metadata */
-#define NPUBIN_META_EXTRA(magiccode) (((magiccode) >> 8) & 0xFFULL)
-
-/* @brief return extra metadata size of npu binary */
-static inline uint64_t NPUBIN_META_EXTRA_SIZE (uint64_t magiccode) {
-  uint64_t num_extra = NPUBIN_META_EXTRA (magiccode);
-  assert (num_extra <= UINT8_MAX);  /** sanity check for svace */
-  return num_extra * NPUBIN_META_SIZE;
+/* number of extended metadata */
+#define NPUBIN_META_NUM_EXTENDED(magiccode) (((magiccode) >> 8) & 0xFFULL)
+
+/* @brief return extended metadata size of npu binary */
+static inline uint64_t NPUBIN_META_EXTENDED_SIZE (uint64_t magiccode) {
+  uint64_t num_extended = NPUBIN_META_NUM_EXTENDED (magiccode);
+  assert (num_extended <= UINT8_MAX);  /** sanity check for svace */
+  return num_extended * NPUBIN_META_SIZE;
 }
 
-/* @brief return total metadata size of npu binary, including extra data */
+/* @brief return total metadata size of npu binary, including extended data */
 static inline uint64_t NPUBIN_META_TOTAL_SIZE (uint64_t magiccode) {
-  uint64_t size_extra = NPUBIN_META_EXTRA_SIZE (magiccode);
-  assert (size_extra <= UINT8_MAX * NPUBIN_META_SIZE); /** sanity check for svace */
-  return size_extra + NPUBIN_META_SIZE;
+  uint64_t size_extended = NPUBIN_META_EXTENDED_SIZE (magiccode);
+  assert (size_extended <= UINT8_MAX * NPUBIN_META_SIZE); /** sanity check for svace */
+  return size_extended + NPUBIN_META_SIZE;
 }
 
 /* tensor data constrains */
@@ -92,17 +92,17 @@ typedef struct {
        * Descriptions for NPUBIN_MAGICCODE (64 bits)
        *
        *              Little-Endian Byte Order
-       *  ---------------------+----------------------------
-       * |       63 - 24       |  23 - 16 | 15 - 8|  7 - 0  |
-       * | ASCII hex for SRNPU | RESERVED | EXTRA | VERSION |
-       *  --------------------------------------------------
+       *  ---------------------+-------------------------------
+       * |       63 - 24       |  23 - 16 |  15 - 8  |  7 - 0  |
+       * | ASCII hex for SRNPU | RESERVED | EXTENDED | VERSION |
+       *  -----------------------------------------------------
        *
        * CHECK_NPUBIN(magiccode) should be true. Also, its least significant byte indicates
-       * the npubinfmt's version. For example, if npubinfmt is v2, NPUBIN_VERSION(magiccode) == 2.
+       * the npubinfmt's version. E.g., if npubinfmt is v2, NPUBIN_VERSION(magiccode) == 2.
        *
-       * Also, the size of metadata is variable depending on the 'EXTRA' field. For example,
-       * if 'EXTRA' is 0, the size of metadata is NPUBIN_META_SIZE. If it's larger than 0,
-       * the actual size of metadata is NPUBIN_META_SIZE + NPUBIN_META_EXTRA_SIZE(magiccode),
+       * Also, the size of metadata can be extended depending on the 'EXTENDED' field. E.g.,
+       * if 'EXTENDED' is 0, the size of metadata is NPUBIN_META_SIZE. If it's larger than 0,
+       * the actual size of metadata is NPUBIN_META_SIZE + NPUBIN_META_EXTENDED_SIZE(magiccode),
        * which is equal to NPUBIN_META_TOTAL_SIZE(magiccode).
        */
       uint64_t magiccode;     /**< npubinfmt's magiccode */
@@ -126,6 +126,7 @@ typedef struct {
       uint64_t buffer_size;   /**< Total buffer size to cover all data (i.e., allocate DRAM size) */
       uint64_t size;          /**< Size of this model, including this meta */
       model_opmode type;      /**< Type of the model, consistent with model_opmode. Refer to typedef.h */
+      uint32_t dummy;         /**< FIXME: Dummy field to keep an aligned offset */
 
       /**
        * If input comes from host, the buffer may be filled with input data.
@@ -231,7 +232,7 @@ typedef struct {
     char reserved_npu_engine[3072]; /**< Ensure NPU-Engine part is 3072 bytes */
   };
   char reserved_compiler[1024]; /**< Reserved for NPU Compiler */
-  char reserved_extra[];      /**< Reserved for future; zero-length array */
+  char reserved_extended[];     /**< Reserved for future; zero-length array */
 } __attribute__((packed, aligned)) npubin_meta;
 
 /* Compile-time assert. From http://www.pixelbeat.org/programming/gcc/static_assert.html */
index 1662905..a2cd891 100644 (file)
@@ -1132,10 +1132,10 @@ TrinityVision2::setModel (const generic_buffer *model_buf, Model ** model_ptr)
     config.program_size = hwmem_prog->getSize ();
     config.program_offset_addr = 0;
 
-    /** for metadata extra section */
+    /** for metadata extended section */
     config.metadata_dbuf_fd = model->getDmabuf ();
     config.metadata_extra_addr = NPUBIN_META_SIZE;
-    config.metadata_extra_size = model->getMetadata()->getMetaExtraSize ();
+    config.metadata_extra_size = model->getMetadata()->getMetaExtendedSize ();
 
     status = api_->registerModel (&config, model->getMetadata()->getNPUVersion());
     if (status != 0)
index a43a1ad..958b5b7 100644 (file)
@@ -91,7 +91,7 @@ class Metadata {
     uint64_t getWeightSize () const { return meta_->weight_size; }
     uint64_t getBufferSize () const { return meta_->buffer_size; }
     uint32_t getMetaSize () const { return NPUBIN_META_TOTAL_SIZE(meta_->magiccode); }
-    uint32_t getMetaExtraSize () const { return NPUBIN_META_EXTRA_SIZE(meta_->magiccode); }
+    uint32_t getMetaExtendedSize () const { return NPUBIN_META_EXTENDED_SIZE(meta_->magiccode); }
     uint32_t getTops () const { return NPU_VERSION_TOPS (getNPUVersion ()); }
 
     int getVersion () const { return version_; }
index eb6ce7c..dc3a7ab 100644 (file)
@@ -535,16 +535,16 @@ int getNPU_deviceStatus(npudev_h dev, npu_status *status, uint32_t *num_requests
 /**
  * @brief Get metadata for NPU model
  * @param[in] model The path of model binary file
- * @param[in] need_extra whether you want to extract the extra data in metadata
+ * @param[in] need_extended whether you want to extract the extended data in metadata
  * @return the metadata structure to be filled if no error, otherwise nullptr
  *
- * @note For most npu-engine users, the extra data is not useful because it will be
+ * @note For most npu-engine users, the extended data is not useful because it will be
  *       used for second-party users (e.g., compiler, simulator).
  *       Also, the caller needs to free the metadata.
  *
  * @note the caller needs to free the metadata
  */
-npubin_meta * getNPUmodel_metadata (const char *model, bool need_extra)
+npubin_meta * getNPUmodel_metadata (const char *model, bool need_extended)
 {
   npubin_meta *meta;
   FILE *fp;
@@ -576,21 +576,22 @@ npubin_meta * getNPUmodel_metadata (const char *model, bool need_extra)
     goto exit_free;
   }
 
-  if (need_extra && NPUBIN_META_EXTRA (meta->magiccode) > 0) {
+  if (need_extended && NPUBIN_META_NUM_EXTENDED (meta->magiccode) > 0) {
     npubin_meta *new_meta;
 
     new_meta = (npubin_meta *) malloc (NPUBIN_META_TOTAL_SIZE(meta->magiccode));
     if (!new_meta) {
-      logerr (TAG, "Failed to allocate extra metadata\n");
+      logerr (TAG, "Failed to allocate extended metadata\n");
       goto exit_free;
     }
 
     memcpy (new_meta, meta, NPUBIN_META_TOTAL_SIZE(meta->magiccode));
     free (meta);
     meta = nullptr;
-    ret = fread (new_meta->reserved_extra, 1, NPUBIN_META_EXTRA_SIZE (new_meta->magiccode), fp);
-    if (ret != NPUBIN_META_EXTRA_SIZE (new_meta->magiccode)) {
-      logerr (TAG, "Invalid extra metadata provided\n");
+    ret = fread (new_meta->reserved_extended, 1,
+        NPUBIN_META_EXTENDED_SIZE (new_meta->magiccode), fp);
+    if (ret != NPUBIN_META_EXTENDED_SIZE (new_meta->magiccode)) {
+      logerr (TAG, "Invalid extended metadata provided\n");
       free (new_meta);
       goto exit_err;
     }