CPU API

优质
小牛编辑
134浏览
2023-12-01
/* GXDNN
 * Copyright (C) 1991-2017 NationalChip Co., Ltd
 *
 * gxdnn.h  NPU Task loader and executor
 *
 */

#ifndef __GXDNN_H__
#define __GXDNN_H__

#ifdef __cplusplus
extern "C" {
#endif

/*===============================================================================================*/

typedef void* GxDnnDevice;
typedef void* GxDnnTask;

typedef enum {
    GXDNN_RESULT_SUCCESS = 0,
    GXDNN_RESULT_WRONG_PARAMETER,
    GXDNN_RESULT_MEMORY_NOT_ENOUGH,
    GXDNN_RESULT_DEVICE_ERROR,
    GXDNN_RESULT_FILE_NOT_FOUND,
    GXDNN_RESULT_UNSUPPORT,
    GXDNN_RESULT_UNKNOWN_ERROR,
    GXDNN_RESULT_OVERTIME,
} GxDnnResult;

/*===============================================================================================*/

/**
 * @brief   Open NPU device
 * @param   [in]    devicePath      the path to device
 *          [out]   device          a handle to the openned device
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 *                      GXDNN_RESULT_DEVICE_ERROR       device error
 * @remark  if devicePath is "/dev/gxnpu", open npu device
 *             devicePath is "/dev/gxsnpu", open snpu device
 */
GxDnnResult GxDnnOpenDevice(const char *devicePath,
                            GxDnnDevice *device);

/*===============================================================================================*/

/**
 * @brief   Close NPU device
 * @param   [in]    device          the handle to openned device
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 *                      GXDNN_RESULT_DEVICE_ERROR       device error
 * @remark
 */
GxDnnResult GxDnnCloseDevice(GxDnnDevice device);

/*===============================================================================================*/

/**
 * @brief   Load NPU Task from file (in Linux/MacOSX)
 * @param   [in]    device          the device handle
 *          [in]    taskPath        the path to NPU task file
 *          [out]   task            a handle to the loaded task
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 *                      GXDNN_RESULT_MEMORY_NOT_ENOUGH  no enough memory
 *                      GXDNN_RESULT_DEVICE_ERROR       device error
 *                      GXDNN_RESULT_FILE_NOT_FOUND     file not found
 *                      GXDNN_RESULT_UNSUPPORT          unsupport NPU type or npu task version
 * @remark
 */
GxDnnResult GxDnnCreateTaskFromFile(GxDnnDevice device,
                                    const char *taskPath,
                                    GxDnnTask *task);

/*===============================================================================================*/

/**
 * @brief   Load NPU task from memory
 * @param   [in]    device          the device handle
 *          [in]    taskBuffer      the pointer to NPU task buffer
 *          [in]    bufferSize      the buffer size of the NPU task buffer
 *          [out]   task            a handle to the loaded task
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 *                      GXDNN_RESULT_MEMORY_NOT_ENOUGH  no enough memory
 *                      GXDNN_RESULT_DEVICE_ERROR       device error
 *                      GXDNN_RESULT_UNSUPPORT          unsupport NPU type or npu task version
 * @remark
 */
GxDnnResult GxDnnCreateTaskFromBuffer(GxDnnDevice device,
                                      const unsigned char *taskBuffer,
                                      const int bufferSize,
                                      GxDnnTask *task);

/*===============================================================================================*/

/**
 * @brief   Release NPU task
 * @param   [in]    task            the loaded task handle
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 * @remark
 */
GxDnnResult GxDnnReleaseTask(GxDnnTask task);

/*===============================================================================================*/

#define MAX_NAME_SIZE 30
#define MAX_SHAPE_SIZE 10

typedef struct NpuIOInfo {
    int direction;              /* 0: Input; 1: Output */
    char name[MAX_NAME_SIZE];   /* name of the IO */
    int shape[MAX_SHAPE_SIZE];  /* the shape of the IO */
    unsigned int dimension;     /* the dimension of the IO */
    void *dataBuffer;           /* the data buffer */
    int bufferSize;             /* the data buffer size */
} GxDnnIOInfo;

/**
 * @brief   Get the IO Num of the loaded task
 * @param   [in]    task            the loaded task
 *          [out]   inputNum        Input number
 *          [out]   outputNum       Output Number
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 * @remark
 */
GxDnnResult GxDnnGetTaskIONum(GxDnnTask task,
                              int *inputNum,
                              int *outputNum);

/*===============================================================================================*/

/**
 * @brief   Get the IO Info of the loaded task
 * @param [in]      task            the loaded task
 *        [out]     inputInfo       the input information List
 *        [in]      inputInfoSize   the size of the output info list buffer
 *        [out]     outputInfo      the output information list
 *        [in]      outputInfoSize  the size of the output info list buffer
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_ERR_BAD_PARAMETER wrong parameter
 * @remark
 */
GxDnnResult GxDnnGetTaskIOInfo(GxDnnTask task,
                               GxDnnIOInfo *inputInfo,
                               int inputInfoSize,
                               GxDnnIOInfo *outputInfo,
                               int outputInfoSize);

/*===============================================================================================*/

typedef enum {
    GXDNN_EVENT_FINISH,
    GXDNN_EVENT_ABORT,
    GXDNN_EVENT_FAILURE
} GxDnnEvent;

/**
 * @brief   The event handler
 * @param   [in]    task            the running task
 *          [in]    event           the event type
 *          [in]    userData        the userData passed by GxDnnRunTask
 * @return  int     0               break the task
 *                  not 0           continue the task
 */
typedef int (*GxDnnEventHandler)(GxDnnTask task, GxDnnEvent event, void *userData);

/*===============================================================================================*/

/**
 * @brief   Run task
 * @param   [in]    task            the loaded task
 *          [in]    priority        the task priority
 *          [in]    eventHandler    the event callback (see remark)
 *          [in]    userData        a void data will be passed to event handler
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 * @remark  if eventHandler == NULL, the function will not return until finish or error happens;
 *          if the task is running, the task will stop first;
 */
GxDnnResult GxDnnRunTask(GxDnnTask task,
                         int priority,
                         GxDnnEventHandler eventHandler,
                         void *userData);

/*===============================================================================================*/

/**
 * @brief   Stop task
 * @param   [in]    task            the loaded task
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 * @remark  if the task is running, the event handler will be invoked
 */
GxDnnResult GxDnnStopTask(GxDnnTask task);

/*===============================================================================================*/

typedef struct NpuDevUtilInfo {
    float ratio;
} GxDnnDevUtilInfo;

/**
 * @brief   Get device utilization information
 * @param   [in]   GxDnnDevice device
 *          [out]  GxDnnDevUtilInfo info
 * @return  GxDnnResult GXDNN_RESULT_SUCCESS    succeed without error
 *                      GXDNN_RESULT_WRONG_PARAMETER    wrong parameter
 *                      GXDNN_RESULT_DEVICE_ERROR    device error
 */
GxDnnResult GxDnnGetDeviceUtil(GxDnnDevice device, GxDnnDevUtilInfo *info);

/*===============================================================================================*/

#ifdef __cplusplus
} /* extern C */
#endif

#endif

最后更新:

类似资料

  • 支持2/4/6/8路麦克风阵列,集成8通道ADC/I2S/PDM,支持模拟麦和数字麦,内置DSP,支持降噪、AEC、Beamforming、去混响等算法。

  • 概述 GX8010 Smart Speaker Develop(简称SSD)是面向智能音箱应用而设计的方案,运行离线的demo程序后可进行基本的本地语音交互。SSD 平台具备如下特点: 6 路模拟MEMS 麦克风 4 个功能按键 12 个RGB 3 色LED 阵列 WIFI+BT 组合模块 TF 卡插槽 两个10W 40Ohm 扬声器 2200 毫安时电池,带充电功能 USB2.0 主机与从机接口

相关阅读