/* 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 */
* 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 */
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.
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 */
/**
* @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;
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;
}