You're reading the documentation for a development version.
For the latest stable release version, please have a look at master.

Program Listing for File nn_api.h

Return to documentation for file (include/nn_api.h)

#ifndef _NN_API_H_
#define _NN_API_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include "pnna_lite.h"

typedef struct _buffer
{
    void     *data;
    uint32_t  size;
} buffer_t;


typedef struct _nn_ctx
{
    /* nn information. */
    int             input_count;
    int             output_count;

    pnna_buffer_create_params_t *input_quant;
    pnna_buffer_create_params_t *output_quant;

    /* PNNA lite buffer objects. */
    pnna_network    network;
    pnna_buffer    *input_buffers;
    pnna_buffer    *output_buffers;
} nn_ctx_t;


typedef int (*preprocess_cb)(nn_ctx_t *ctx, buffer_t *output, buffer_t *input);


typedef int (*postprocess_cb)(nn_ctx_t *ctx, void *custom_output, buffer_t *input);


typedef struct _app_ctx
{
    /* 神经网络上下文 */
    nn_ctx_t *ctx;

    /* 中间缓冲区:量化后临时 buffer_t (用于前处理与推理之间) */
    buffer_t *tmp0_buffer;

    /* 中间缓冲区:推理输出临时 buffer_t (用于推理与后处理之间) */
    buffer_t *tmp1_buffer;

    /* 前处理回调函数 */
    preprocess_cb  preprocess_fn;

    /* 后处理回调函数 */
    postprocess_cb postprocess_fn;
} app_ctx_t;


app_ctx_t *create_app_ctx(buffer_t *nbg_buffer,
                          preprocess_cb  model_preprocess,
                          postprocess_cb model_postprocess);


void destroy_app_ctx(app_ctx_t *model);


int app(app_ctx_t *model, void **output, buffer_t *input);


int pnna_open(void);

int pnna_close(void);


nn_ctx_t *create_model(buffer_t *nbg_buffer, unsigned int time_out);

int infer(nn_ctx_t *ctx, buffer_t *output, buffer_t *input);


void destroy_model(nn_ctx_t *context);


float get_infer_time_ms(nn_ctx_t *ctx);

#ifdef __cplusplus
}
#endif

#endif // !_NN_API_H_