blob: a40901982485adbf5375407f73d7a9566a59d944 [file] [log] [blame]
#ifndef SW_VEC_IREE_SAMPLES_UTIL_MODEL_API_H_
#define SW_VEC_IREE_SAMPLES_UTIL_MODEL_API_H_
// Define ML model configuration and model-specific utility APIs.
#include "iree/base/api.h"
#include "iree/hal/api.h"
#include "iree/modules/hal/module.h"
#include "iree/vm/api.h"
#include "iree/vm/bytecode_module.h"
#define MAX_MODEL_INPUT_NUM 2
#define MAX_MODEL_INPUT_DIM 4
#define MAX_MODEL_OUTPUTS 12
#define MAX_ENTRY_FUNC_NAME 20
typedef struct {
int num_input;
int num_input_dim[MAX_MODEL_INPUT_NUM];
iree_hal_dim_t input_shape[MAX_MODEL_INPUT_NUM][MAX_MODEL_INPUT_DIM];
int input_length[MAX_MODEL_INPUT_NUM];
int input_size_bytes[MAX_MODEL_INPUT_NUM];
int num_output;
int output_length[MAX_MODEL_OUTPUTS];
int output_size_bytes;
enum iree_hal_element_types_t hal_element_type;
char entry_func[MAX_ENTRY_FUNC_NAME];
char model_name[];
} MlModel;
// Load the VM bytecode module from the embedded c library into memory.
const iree_const_byte_span_t load_bytecode_module_data();
// For each ML workload, based on the model configuration, allocate the buffer
// and prepare the data. It can be loaded from a embedded image binary, a
// randomly generated stream, or a pointer from the sensor/ISP output.
iree_status_t load_input_data(const MlModel *model, void **buffer);
// Check the ML execution output, and prepare the final data to be sent to the
// host with post processing. The final format is model dependent.
iree_status_t check_output_data(const MlModel *model,
iree_hal_buffer_mapping_t *mapped_memory,
int index_output);
#endif // SW_VEC_IREE_SAMPLES_UTIL_MODEL_API_H_