#include <typedef.h>
/* Same with the typical page size */
-#define NPUBIN_META_SIZE (4096)
+#define NPUBIN_META_SIZE (4096)
+#define MAX_TENSORS (16)
+#define MAX_RANK (4)
+#define DATA_GRANULARITY (64)
+/* npubinfmt magiccode macros */
+#define NPUBIN_MAGICCODE (0x53524E5055000000ULL) /* ASCII hex for 'SRNPU' */
+#define NPUBIN_VERSION(magiccode) ((magiccode) & 0xFFULL)
+#define CHECK_NPUBIN(magiccode) (((magiccode) & ~0xFFFFFFULL) == NPUBIN_MAGICCODE)
/**************************************************
* NPU Binary Format: "Main" *
* Actual composition of values to be determined **
* by H/W and compiler. ***************************/
-
/**
* @brief Meta data, "MAIN".
* @detail First 2048 bytes are to be accessed by NPU Engine
/** Reserved for NPU Engine. Do not use these without approvals from NPU Engine matinainers */
union {
struct {
- uint64_t magiccode;
+ /**
+ * Descriptions for NPUBIN_MAGICCODE (64 bits)
+ *
+ * ---------------------+--------------------
+ * | 63 - 24 | 23 - 8 | 7 - 0 |
+ * | ASCII hex for SRNPU | RESERVED | VERSION |
+ * ------------------------------------------
+ *
+ * CHECK_NPUBIN(magiccode) should be true. Also, its least significant byte indicates
+ * the npubinfmt's version. E.g., if npubinfmt is v2, NPUBIN_VERSION(magiccode) == 0x2
+ */
+ uint64_t magiccode; /**< npubinfmt's magiccode */
uint64_t npu_version;
uint64_t compiler_version;
uint64_t model_version;
/** About input/output/intermediate DRAM buffer format, for the first input and the last output, which are required for host communication. */
- uint64_t buffer_size;
+ 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 */
- /** If input comes from host, the buffer may be filled with input data. Input and output areas may have intersection as they are not required simultaneously. */
- uint64_t input_offset; /**< Input offset for this model. */
- uint64_t input_size; /**< Input size for this model.*/
-
- uint64_t output_offset; /**< Output offset for this model.*/
- uint64_t output_size; /**< Output size for this model.*/
+ model_opmode type; /**< Type of the model, consistent with model_opmode. Refer to typedef.h */
uint64_t program_size; /**< Size of the program list instructions */
uint64_t weight_size; /**< Size of the model weights */
+
+ /**
+ * If input comes from host, the buffer may be filled with input data.
+ * Input and output areas may have intersection as they are not required simultaneously.
+ * For per-tensor info, refer to 'reserved_for_compiler' field.
+ */
+ union {
+ /** npubinfmt v2; this format supports non-contiguous tensors */
+ struct {
+ /** input tensor details */
+ uint32_t input_num; /**< Number of input tensors (<= MAX_TENSORS) */
+ uint32_t input_offsets[MAX_TENSORS]; /**< offsets for input tensors; each tensor would be not contiguous */
+
+ uint32_t input_elem_size[MAX_TENSORS]; /**< input per-element size (in bytes) */
+ uint32_t input_dims[MAX_TENSORS][MAX_RANK]; /**< input dimensions (e.g., width, height, depth, batch) */
+
+ uint32_t input_emod_y[MAX_TENSORS]; /**< input addressing info (emod_y) */
+ uint32_t input_emod_z[MAX_TENSORS]; /**< input addressing info (emod_z) */
+
+ /** output tensor details */
+ uint32_t output_num; /**< Number of output tensors (<= MAX_TENSORS) */
+ uint32_t output_offsets[MAX_TENSORS]; /**< offsets for output tensors; each tensor would be not contiguous */
+
+ uint32_t output_elem_size[MAX_TENSORS]; /**< output per-element size (in bytes) */
+ uint32_t output_dims[MAX_TENSORS][MAX_RANK]; /**< output dimensions (e.g., width, height, depth, batch) */
+
+ uint32_t output_emod_y[MAX_TENSORS]; /**< output addressing info (emod_y) */
+ uint32_t output_emod_z[MAX_TENSORS]; /**< output addressing info (emod_z) */
+ };
+ /** npubinfmt v1; this format assumes contiguous tensors */
+ struct {
+ uint64_t input_offset; /**< Input offset for this model. */
+ uint64_t input_size; /**< Input size for this model.*/
+
+ uint64_t output_offset; /**< Output offset for this model.*/
+ uint64_t output_size; /**< Output size for this model.*/
+ };
+ };
};
char reserved_npu_engine[2048]; /**< Ensure NPU-Engine part is 2048 bytes */
};
char reserved_for_future[1024]; /**< Ensure the whole meta is within size with ct_assert */
-} npubin_meta;
+} __attribute__((packed)) npubin_meta;
/* Compile-time assert. From http://www.pixelbeat.org/programming/gcc/static_assert.html */
#define ASSERT_CONCAT_(a, b) a##b