blob: cae9682bd04a6ef4345d70aba4f99a80f3f69897 [file] [log] [blame]
#ifndef SW_VEC_IREE_SAMPLES_UTIL_UTIL_H_
#define SW_VEC_IREE_SAMPLES_UTIL_UTIL_H_
#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;
// Allocate the input buffer w.r.t the model config.
// The buffer must be released by the external caller.
static inline iree_status_t alloc_input_buffer(const MlModel *model,
void **buffer) {
iree_status_t result = iree_ok_status();
for (int i = 0; i < model->num_input; ++i) {
if (iree_status_is_ok(result)) {
buffer[i] =
iree_aligned_alloc(
sizeof(uint32_t),
model->input_size_bytes[i] * model->input_length[i]);
if (buffer[i] == NULL) {
result = iree_make_status(IREE_STATUS_RESOURCE_EXHAUSTED);
}
}
}
return result;
}
#endif // SW_VEC_IREE_SAMPLES_UTIL_UTIL_H_