/**
* Descriptions for NPUBIN_MAGICCODE (64 bits)
*
+ * Little-Endian Byte Order
* ---------------------+--------------------
* | 63 - 24 | 23 - 8 | 7 - 0 |
* | ASCII hex for SRNPU | RESERVED | VERSION |
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 */
- 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.
*/
+ struct {
+ /**
+ * npubinfmt v1; this format assumes contiguous tensors
+ * keep these variables for backward compatibility.
+ */
+ 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.*/
+ };
+
+ uint64_t program_size; /**< Size of the program list instructions */
+ uint64_t weight_size; /**< Size of the model weights */
+
union {
- /** npubinfmt v2; this format supports non-contiguous tensors */
struct {
+ /** npubinfmt v2; this format supports non-contiguous tensors */
+
/** 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 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.*/
- };
+ /** If npubinfmt should be changed, append here as another version */
};
};
char reserved_npu_engine[2048]; /**< Ensure NPU-Engine part is 2048 bytes */
## these values are common for all existing example visa binaries
META_SIZE=4096
SIZE_ALIGN=4096
+SIGNATURE='SRNPU'
+VERSION=1
+DEBUG=0
## @brief class for NPU model used in NPU Engine
class NPUModel:
self.input = self.outdir + "/input_fmap.bin"
self.output = self.outdir + "/output_fmap.bin"
- print ("binary size: " + str(self.in_binary_size))
+ self.signature = SIGNATURE
+ self.version = VERSION
+
+ if DEBUG:
+ print ("binary size: " + str(self.in_binary_size))
+
+ ## @brief get magic code
+ def get_magic_code (self):
+ value = 0
+ for s in self.signature:
+ value = (value << 8) + ord(s)
+ value <<= (8 - len(self.signature)) * 8
+ value += self.version
+
+ return value
## @brief get binary size; return zero if it does not exist
def get_bin_size (self, name, idx):
if self.single_mode:
log_tag = '[single_layer] '
- print (log_tag + ' input size: ' + str(input_fmap_size))
- print (log_tag + ' esum size: ' + str(input_esum_size))
- print (log_tag + ' weight size: ' + str(input_weight_size))
- print (log_tag + ' output size: ' + str(output_fmap_size))
+ if DEBUG:
+ print (log_tag + ' input size: ' + str(input_fmap_size))
+ print (log_tag + ' esum size: ' + str(input_esum_size))
+ print (log_tag + ' weight size: ' + str(input_weight_size))
+ print (log_tag + ' output size: ' + str(output_fmap_size))
if first_input_size == 0:
first_input_offset = in0_eaddr0
f.seek(0)
# we don't know the exact values yet
- f.write(struct.pack('<Q', 0)) # magiccode
+ f.write(struct.pack('<Q', self.get_magic_code())) # magiccode
f.write(struct.pack('<Q', 0)) # npu_version
f.write(struct.pack('<Q', 0)) # compiler_version
f.write("visa_example_model") # name
try:
model = NPUModel (args)
model.gen()
- print ("[SUCCESS] final model size: " + str(model.size))
+ if DEBUG:
+ print ("[SUCCESS] final model size: " + str(model.size))
except Exception as e:
print ("[FAILURE] error detected: " + str(e))