NPU model API deployment process*
1. Use NPU*
After the model file is generated by the NPU compiler, the model file needs to be deployed on the board. The model file generated by the NPU compiler is a C file. With the API interface provided by us, the model can be run on the board. For details, see NPU Model Deployment Guide.
1.1 Call API flow*
- Open SNPU
- Load the model and input data, run the model, and get the output data.
- Shut down SNPU
gx_snpu.h
/**
* @brief Example Initialize the snpu
*
*
* @return Whether the snpu is initialized successfully
* @retval 0 normal
* @retval -1 failure
*/
int gx_snpu_init(void);
/**
* @brief Shut down snpu
*
*
* @return Whether the snpu is shut down successfully
* @retval 0 normal
* @retval -1 failure
*/
int gx_snpu_exit(void);
/**
* @brief Data format for the input and output of the snpu. Note: The output format of GRUS can choose whether to use float16 or float32 when compiling the model
*/
typedef short GX_SNPU_FLOAT;
/**
* @brief snpu working status
*/
typedef enum {
GX_SNPU_IDLE, /**< Idle state*/
GX_SNPU_BUSY, /**< Busy state*/
GX_SNPU_STALL, /**< Stagnant state*/
} GX_SNPU_STATE;
/**
* @brief snpu callback function. After the task is processed, the function is interrupted
*/
typedef int (*GX_SNPU_CALLBACK)(int module_id, GX_SNPU_STATE state, void *private_data);
/**
* @brief snpu Work task
*/
typedef struct {
int module_id; /**< Module identification number module id defined by programmer*/
void *ops; /**< mcu operator information content area ops_content in model.h*/
void *data; /**< Temporary data content area data_content in model.h*/
void *input; /**< Model input data input in model.h*/
void *output; /**< Model output data output in model.h*/
void *cmd; /**< Instruction content area cmd_content in model.h*/
void *tmp_mem; /**< Temporary data content area tmp_content in model.h*/
void *weight; /**< Weighted content area weight_content in model.h*/
} GX_SNPU_TASK;
/**
* @brief Run a work task asynchronously
*
* @param task Work task
* @param callback Callback function that interrupts the execution of the function after the task is completed
* @param private_data Arguments to the callback function
*
* @return snpu task status
* @retval 0 normal
* @retval -1 failure
*/
int gx_snpu_run_task(GX_SNPU_TASK *task, GX_SNPU_CALLBACK callback, void *private_data);
/**
* @brief Run a work task in synchronous mode
*
* @param task Work task
*
* @return snpu task status
* @retval 0 normal
* @retval -1 failure
*/
int gx_snpu_run_task_sync(GX_SNPU_TASK *task);
/**
* @brief The snpu is in working state
*
*
* @return snpu task status
* @retval GX_SNPU_IDLE Idle state
* @retval GX_SNPU_BUSY Busy state
* @retval GX_SNPU_STALL Stagnant state
*/
GX_SNPU_STATE gx_snpu_get_state(void);