#ifndef MNN_WRAPPER_H
#define MNN_WRAPPER_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct MNN_InferenceEngine MNN_InferenceEngine;
typedef struct MNN_SessionPool MNN_SessionPool;
typedef struct MNN_SharedRuntime MNN_SharedRuntime;
typedef enum
{
MNNR_SUCCESS = 0,
MNNR_ERROR_INVALID_PARAMETER = 1,
MNNR_ERROR_OUT_OF_MEMORY = 2,
MNNR_ERROR_RUNTIME_ERROR = 3,
MNNR_ERROR_UNSUPPORTED = 4,
MNNR_ERROR_MODEL_LOAD_FAILED = 5
} MNNR_ErrorCode;
typedef enum
{
MNNR_DATA_FORMAT_NCHW = 0, MNNR_DATA_FORMAT_NHWC = 1, MNNR_DATA_FORMAT_AUTO = 2 } MNNR_DataFormat;
typedef struct
{
int32_t thread_count; int32_t precision_mode; bool use_cache; int32_t data_format; } MNNR_Config;
const char *mnnr_get_version(void);
MNN_SharedRuntime *mnnr_create_runtime(const MNNR_Config *config);
void mnnr_destroy_runtime(MNN_SharedRuntime *runtime);
MNN_InferenceEngine *mnnr_create_engine(
const void *buffer,
size_t size,
const MNNR_Config *config);
MNN_InferenceEngine *mnnr_create_engine_with_runtime(
const void *buffer,
size_t size,
MNN_SharedRuntime *runtime);
void mnnr_destroy_engine(MNN_InferenceEngine *engine);
MNNR_ErrorCode mnnr_get_input_shape(
const MNN_InferenceEngine *engine,
size_t *dims,
size_t *out_ndims);
MNNR_ErrorCode mnnr_get_output_shape(
const MNN_InferenceEngine *engine,
size_t *dims,
size_t *out_ndims);
MNNR_ErrorCode mnnr_run_inference(
MNN_InferenceEngine *engine,
const float *input_data,
size_t input_size,
float *output_data,
size_t output_size);
const char *mnnr_get_last_error(const MNN_InferenceEngine *engine);
MNN_SessionPool *mnnr_create_session_pool(
MNN_InferenceEngine *engine,
size_t pool_size,
const MNNR_Config *config);
void mnnr_destroy_session_pool(MNN_SessionPool *pool);
MNNR_ErrorCode mnnr_session_pool_run(
MNN_SessionPool *pool,
const float *input_data,
size_t input_size,
float *output_data,
size_t output_size);
size_t mnnr_session_pool_available(const MNN_SessionPool *pool);
const char *mnnr_session_pool_get_last_error(const MNN_SessionPool *pool);
typedef struct MNN_SingleSession MNN_SingleSession;
MNN_SingleSession *mnnr_create_session(
MNN_InferenceEngine *engine,
const MNNR_Config *config);
void mnnr_destroy_session(MNN_SingleSession *session);
MNNR_ErrorCode mnnr_run_inference_with_session(
MNN_SingleSession *session,
const float *input_data,
size_t input_size,
float *output_data,
size_t output_size);
const char *mnnr_session_get_last_error(const MNN_SingleSession *session);
MNNR_ErrorCode mnnr_run_inference_dynamic(
MNN_InferenceEngine *engine,
const float *input_data,
const size_t *input_dims,
size_t input_ndims,
float **output_data,
size_t *output_size,
size_t *output_dims,
size_t *output_ndims);
void mnnr_free_output(float *output_data);
#ifdef __cplusplus
}
#endif
#endif