Add headers for nbg_parser

Signed-off-by: xiang.zhang <xiang.zhang@verisilicon.com>
This commit is contained in:
xiang.zhang 2021-10-08 13:38:15 +08:00
parent 47191227e0
commit 830f26c897
4 changed files with 551 additions and 0 deletions

View File

@ -0,0 +1,232 @@
/******************************************************************************\
|* Copyright (c) 2017-2021 by Vivante Corporation. All Rights Reserved. *|
|* *|
|* The material in this file is confidential and contains trade secrets of *|
|* of Vivante Corporation. This is proprietary information owned by Vivante *|
|* Corporation. No part of this work may be disclosed, reproduced, copied, *|
|* transmitted, or used in any way for any purpose, without the express *|
|* written permission of Vivante Corporation. *|
|* *|
\******************************************************************************/
#ifndef _VIP_LITE_NBG_FORMAT_H
#define _VIP_LITE_NBG_FORMAT_H
#if defined(__cplusplus)
extern "C"{
#endif
typedef unsigned char vip_uint8_t;
typedef unsigned short vip_uint16_t;
typedef unsigned int vip_uint32_t;
typedef unsigned long long vip_uint64_t;
typedef signed char vip_int8_t;
typedef signed short vip_int16_t;
typedef signed int vip_int32_t;
typedef signed long long vip_int64_t;
typedef char vip_char_t;
typedef float vip_float_t;
typedef unsigned long long vip_address_t;
#define NETWORK_NAME_SIZE 64
#define LAYER_NAME_SIZE 64
#define MAX_SW_LAYER_NAME_LENGTH 64
#define MAX_IO_NAME_LEGTH 64
#define NN_CMD_SIZE_128 128
#define NN_CMD_SIZE_192 192
#define TP_CMD_SIZE 128
#define MAX_NUM_DIMS 6
/* The vip lite binary data (file) is composed as following layout:
1. Fixed section.
Where fixed information is stored, such as header, pool info, and data entries.
2. Dynamic section.
Where the real data is stored, or indexed.
*/
/********************** The fixed part of the binary file *************************/
typedef struct _gcvip_bin_feature_database
{
vip_uint32_t hi_reorder_fix:1; /* gcFEATURE_BIT_HI_REORDER_FIX */
vip_uint32_t ocb_counter:1; /* gcFEATURE_BIT_OCB_COUNTER */
vip_uint32_t nn_command_size:2; /* the size of NN command, 0: 128bytes, 1: 192bytes */
vip_uint32_t change_ppu_param:1;/* 1: the NBG supports change PPU param, 0: not supports */
vip_uint32_t reserved:27; /* reserved bits */
vip_uint32_t num_pixel_pipes; /* gcFEATURE_VALUE_NumPixelPipes */
vip_uint8_t core_count; /* VIP core count */
vip_uint8_t reserved1;
vip_uint8_t reserved2;
vip_uint8_t reserved3;
vip_uint32_t vsi_reserved[13]; /* reserved for verisilicon */
vip_uint32_t customer_reserved[48]; /* reserved for customer */
} gcvip_bin_feature_database_t;
typedef struct _gcvip_bin_header
{
vip_char_t magic[4];
vip_uint32_t version;
vip_uint32_t hw_target;
vip_char_t network_name[NETWORK_NAME_SIZE];
vip_uint32_t layer_count;
vip_uint32_t operation_count;
vip_uint32_t input_count;
vip_uint32_t output_count;
gcvip_bin_feature_database_t feature_db;
} gcvip_bin_header_t;
typedef struct _gcvip_bin_pool
{
vip_uint32_t size;
vip_uint32_t alignment;
vip_uint32_t base;
} gcvip_bin_pool_t;
typedef struct _gcvip_bin_entry
{
vip_uint32_t offset;
vip_uint32_t size;
} gcvip_bin_entry_t;
typedef struct _gcvip_bin_fixed
{
gcvip_bin_header_t header;
gcvip_bin_pool_t pool;
vip_uint32_t axi_sram_base;
vip_uint32_t axi_sram_size;
vip_uint32_t vip_sram_base;
vip_uint32_t vip_sram_size;
gcvip_bin_entry_t layer_table;
gcvip_bin_entry_t opeartion_table;
gcvip_bin_entry_t LCD_table;
gcvip_bin_entry_t LCD; /* Loading Config Data */
gcvip_bin_entry_t nn_op_data_table;
gcvip_bin_entry_t tp_op_data_table;
gcvip_bin_entry_t sh_op_data_table;
gcvip_bin_entry_t input_table;
gcvip_bin_entry_t output_table;
gcvip_bin_entry_t patch_data_table;
gcvip_bin_entry_t layer_param_table;
gcvip_bin_entry_t sw_op_data_table;
gcvip_bin_entry_t hw_init_op_table;
gcvip_bin_entry_t ICD_table;
gcvip_bin_entry_t ICD; /* Initialize Config Data */
gcvip_bin_entry_t ppu_param_table;
} gcvip_bin_fixed_t;
typedef struct _gcvip_bin_inout_entry
{
vip_uint32_t dim_count;
vip_uint32_t dim_size[MAX_NUM_DIMS];
vip_uint32_t data_format;
vip_uint32_t data_type;
vip_uint32_t quan_format;
vip_int32_t fixed_pos;
vip_float_t tf_scale;
vip_int32_t tf_zerop;
vip_char_t name[MAX_IO_NAME_LEGTH];
} gcvip_bin_inout_entry_t;
typedef struct _gcvip_bin_layer
{
vip_char_t name[LAYER_NAME_SIZE];
vip_uint32_t id;
vip_uint32_t operation_count;
vip_uint32_t uid;
} gcvip_bin_layer_t;
typedef struct _gcvip_bin_operation
{
vip_uint32_t type;
vip_uint32_t index;
vip_uint32_t layer_id;
vip_uint32_t state_id; /* States buffer index in LCDT. */
vip_uint32_t patch_index;
vip_uint32_t patch_count;
} gcvip_bin_operation_t;
typedef struct _gcvip_bin_nn_operation
{
vip_uint8_t cmd[NN_CMD_SIZE_128];
} gcvip_bin_nn_operation_t;
typedef struct _gcvip_bin_nn_operation_192bytes
{
vip_uint8_t cmd[NN_CMD_SIZE_192];
} gcvip_bin_nn_operation_192bytes_t;
typedef struct _gcvip_bin_tp_operation
{
vip_uint8_t cmd[TP_CMD_SIZE];
} gcvip_bin_tp_operation_t;
typedef struct _gcvip_bin_sh_operation
{
vip_uint32_t lcdt_index;
vip_uint32_t ppu_param_index;
} gcvip_bin_sh_operation_t;
typedef struct _gcvip_bin_patch_data_entry
{
vip_uint32_t type;
vip_uint32_t offset_in_states;
vip_uint32_t source_type;
vip_int32_t index;
vip_int32_t orig_base;
vip_uint32_t transformed;
vip_uint32_t name;
} gcvip_bin_patch_data_entry_t;
typedef struct _gcvip_bin_layer_parameter_entry
{
vip_char_t param_name[16];
vip_uint32_t dim_count;
vip_uint32_t dims[MAX_NUM_DIMS];
vip_uint32_t data_format;
vip_uint32_t data_type;
vip_uint32_t quant_format;
vip_int32_t fixpoint_zeropoint;
vip_float_t tfscale;
vip_int32_t index;
vip_uint32_t address_offset;
vip_uint32_t source_type;
} gcvip_bin_layer_parameter_t;
typedef struct _gcvip_bin_sw_operation_info_entry
{
vip_uint32_t sw_peration_type;
vip_char_t name[MAX_SW_LAYER_NAME_LENGTH];
} gcvip_bin_sw_operation_info_t;
typedef struct _gcvip_bin_hw_init_operation_info_entry
{
vip_uint32_t state_id; /* States buffer index in LCDT. */
vip_uint32_t patch_index; /* the first index in patch table */
vip_uint32_t patch_count; /* the total patch count in patch table */
} gcvip_bin_hw_init_operation_info_entry_t;
typedef struct _gcvip_ppu_param_data
{
vip_uint32_t global_offset_x;
vip_uint32_t global_offset_y;
vip_uint32_t global_offset_z;
vip_uint32_t global_scale_x;
vip_uint32_t global_scale_y;
vip_uint32_t global_scale_z;
vip_uint32_t group_size_x;
vip_uint32_t group_size_y;
vip_uint32_t group_size_z;
vip_uint32_t group_count_x;
vip_uint32_t group_count_y;
vip_uint32_t group_count_z;
} gcvip_ppu_param_data_t;
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,222 @@
/******************************************************************************\
|* Copyright (c) 2017-2021 by Vivante Corporation. All Rights Reserved. *|
|* *|
|* The material in this file is confidential and contains trade secrets of *|
|* of Vivante Corporation. This is proprietary information owned by Vivante *|
|* Corporation. No part of this work may be disclosed, reproduced, copied, *|
|* transmitted, or used in any way for any purpose, without the express *|
|* written permission of Vivante Corporation. *|
|* *|
\******************************************************************************/
#ifndef _NBG_PARSER_H
#define _NBG_PARSER_H
#if defined(__cplusplus)
extern "C"{
#endif
#ifndef NBG_NULL
#define NBG_NULL 0
#endif
typedef struct nbg_parser_data_t *nbg_parser_data;
typedef unsigned char nbg_uint8_t;
typedef unsigned short nbg_uint16_t;
typedef unsigned int nbg_uint32_t;
typedef unsigned long long nbg_uint64_t;
typedef signed char nbg_int8_t;
typedef signed short nbg_int16_t;
typedef signed int nbg_int32_t;
typedef signed long long nbg_int64_t;
typedef char nbg_char_t;
typedef float nbg_float_t;
typedef unsigned long long nbg_address_t;
typedef enum _nbg_status
{
NBG_ERROR_OUT_OF_MEMORY = -5,
NBG_ERROR_NOT_SUPPORT = -4,
NBG_ERROR_INVALID_ARGUMENTS = -3,
NBG_ERROR_FORMAT = -2,
NBG_ERROR_FAILURE = -1,
NBG_SUCCESS = 0,
} nbg_status_e;
typedef enum _nbg_buffer_quantize_format_e
{
/*! \brief Not quantized format */
NBG_BUFFER_QUANTIZE_NONE = 0,
/*! \brief The data is quantized with dynamic fixed point */
NBG_BUFFER_QUANTIZE_DYNAMIC_FIXED_POINT = 1,
/*! \brief The data is quantized with TF asymmetric format */
NBG_BUFFER_QUANTIZE_AFFINE_ASYMMETRIC = 2
} nbg_buffer_quantize_format_e;
typedef enum _nbg_buffer_format_e
{
/*! \brief A float type of buffer data */
NBG_BUFFER_FORMAT_FP32 = 0,
/*! \brief A half float type of buffer data */
NBG_BUFFER_FORMAT_FP16 = 1,
/*! \brief A 8 bit unsigned integer type of buffer data */
NBG_BUFFER_FORMAT_UINT8 = 2,
/*! \brief A 8 bit signed integer type of buffer data */
NBG_BUFFER_FORMAT_INT8 = 3,
/*! \brief A 16 bit unsigned integer type of buffer data */
NBG_BUFFER_FORMAT_UINT16 = 4,
/*! \brief A 16 signed integer type of buffer data */
NBG_BUFFER_FORMAT_INT16 = 5,
/*! \brief A char type of data */
NBG_BUFFER_FORMAT_CHAR = 6,
/*! \brief A bfloat 16 type of data */
NBG_BUFFER_FORMAT_BFP16 = 7,
/*! \brief A 32 bit integer type of data */
NBG_BUFFER_FORMAT_INT32 = 8,
/*! \brief A 32 bit unsigned signed integer type of buffer */
NBG_BUFFER_FORMAT_UINT32 = 9,
/*! \brief A 64 bit signed integer type of data */
NBG_BUFFER_FORMAT_INT64 = 10,
/*! \brief A 64 bit unsigned integer type of data */
NBG_BUFFER_FORMAT_UINT64 = 11,
/*! \brief A 64 bit float type of buffer data */
NBG_BUFFER_FORMAT_FP64 = 12,
} nbg_buffer_format_e;
typedef enum _nbg_buffer_type_e
{
/*! \brief A tensor type of buffer data */
NBG_BUFFER_TYPE_TENSOR = 0,
/*! \brief A image type of buffer data */
NBG_BUFFER_TYPE_IMAGE = 1,
/*! \brief A array type of buffer data */
NBG_BUFFER_TYPE_ARRAY = 2,
/*! \brief A scalar type of buffer data */
NBG_BUFFER_TYPE_SCALAR = 3,
} nbg_buffer_type_e;
typedef enum _nbg_buffer_property
{
/*!< \brief The quantization format, the returned value is nbg_buffer_quantize_format_e */
NBG_PARSER_BUFFER_PROP_QUANT_FORMAT = 0,
/*!< \brief The number of dimension for this input, the returned value is nbg_uint32_t*/
NBG_PARSER_BUFFER_PROP_NUM_OF_DIMENSION = 1,
/*!< \brief The size of each dimension for this input,
the returned value is nbg_uint32_t * num_of_dimension */
NBG_PARSER_BUFFER_PROP_DIMENSIONS = 2,
/*!< \brief The data format for this input, the returned value is nbg_buffer_format_e */
NBG_PARSER_BUFFER_PROP_DATA_FORMAT = 3,
/*!< \brief The position of fixed point for dynamic fixed point, the returned value is nbg_uint32_t */
NBG_PARSER_BUFFER_PROP_FIXED_POINT_POS = 4,
/*!< \brief The scale value for TF quantization format, the returned value is nbg_float_t */
NBG_PARSER_BUFFER_PROP_SCALE = 5,
/*!< \brief The zero point for TF quantization format, the returned value is nbg_uint32_t */
NBG_PARSER_BUFFER_PROP_ZERO_POINT = 6,
/*!< \brief The name for network's inputs and outputs,
the returned value size is queried by NBG_PARSER_BUFFER_PROP_NAME_SIZE */
NBG_PARSER_BUFFER_PROP_NAME = 7,
/*!< \brief The data type for input/output buffer, the returned value is nbg_buffer_type_e */
NBG_PARSER_BUFFER_PROP_DATA_TYPE = 8,
/*!< \brief The size of input/output name. the returned value is nbg_uint32_t */
NBG_PARSER_BUFFER_PROP_NAME_SIZE = 128 + NBG_PARSER_BUFFER_PROP_NAME,
} nbg_buffer_property_e;
typedef enum _nbg_network_property_e
{
/* !< \brief The name of network, the returned value size is queried by NBG_PARSET_NETWORK_SIZE_OF_NAME */
NBG_PARSER_NETWORK_NAME = 0,
/* !< \brief The number of network input, the returned value is nbg_uint32_t */
NBG_PARSER_NETWORK_INPUT_COUNT = 1,
/* !< \brief The number of network output, the returned value is nbg_uint32_t */
NBG_PARSER_NETWORK_OUTPUT_COUNT = 2,
/* !< \brief The CID of this NBG, the returned value is nbg_uint32_t */
NBG_PARSER_NETWORK_CID = 3,
/*!< \brief The size of network name. the returned value is nbg_uint32_t */
NBG_PARSER_NETWORK_NAME_SIZE = 128 + NBG_PARSER_NETWORK_NAME,
} nbg_network_property_e;
/*
@brief, Query NBG parser library version
*/
nbg_uint32_t nbg_parser_version(void);
/*
@brief, Initialize NBG parser. use NBG data to initialize nbg parser library.
@param IN buffer, NBG data in memory.
@param IN size, the size of NBG data.
@param OUT nbg, the NBG parser object which created by nbg_parser_init().
*/
nbg_status_e nbg_parser_init(
void *buffer,
nbg_uint32_t size,
nbg_parser_data *nbg
);
/*
@brief, query the input info of network.
@param IN nbg, the NBG parser object created by nbg_parser_init().
@param IN index, the index of network input.
@param IN property, property being queried.
Quant format, dimension count, shape, data format and so on. see nbg_buffer_property_e enumeration.
@param IN size, the size of value buffer.
@param OUT value, The return value data.
please refer nbg_buffer_property_e to know the size of returned value data.
*/
nbg_status_e nbg_parser_query_input(
nbg_parser_data nbg,
nbg_uint32_t index,
nbg_uint32_t property,
void *value,
nbg_uint32_t size
);
/*
@brief, query the output info of network.
@param IN nbg, the NBG parser object created by nbg_parser_init().
@param IN index, the index of network input.
@param IN property, property being queried.
Quant format, dimension count, shape, data format and so on.
see nbg_buffer_property_e enumeration.
@param IN size, the size of value buffer.
@param OUT value, The return value data.
please refer nbg_buffer_property_e to know the size of returned value data.
*/
nbg_status_e nbg_parser_query_output(
nbg_parser_data nbg,
nbg_uint32_t index,
nbg_uint32_t property,
void *value,
nbg_uint32_t size
);
/*
@brief, query the network info.
@param IN nbg, the NBG parser object created by nbg_parser_init().
@param IN property, The property of the network is queried.
network name, input count, output count and so on. see nbg_network_propery_e enumeration.
@param IN size, the size of value buffer.
@param OUT value, The return value data.
please refer nbg_network_propery_e to know the size of returned value data.
*/
nbg_status_e nbg_parser_query_network(
nbg_parser_data nbg,
nbg_uint32_t property,
void *value,
nbg_uint32_t size
);
/*
@brief, destroy nbg parser.
@param, IN nbg, the NBG parser object created by nbg_parser_init().
*/
nbg_status_e nbg_parser_destroy(
nbg_parser_data nbg
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,78 @@
/******************************************************************************\
|* Copyright (c) 2017-2021 by Vivante Corporation. All Rights Reserved. *|
|* *|
|* The material in this file is confidential and contains trade secrets of *|
|* of Vivante Corporation. This is proprietary information owned by Vivante *|
|* Corporation. No part of this work may be disclosed, reproduced, copied, *|
|* transmitted, or used in any way for any purpose, without the express *|
|* written permission of Vivante Corporation. *|
|* *|
\******************************************************************************/
#ifndef _NBG_PARSER_IMPL_H
#define _NBG_PARSER_IMPL_H
#if defined(__cplusplus)
extern "C"{
#endif
#include "gc_vip_nbg_format.h"
/* NBG format version */
#define NBG_FORMAT_VERSION 0x0001000E
enum nbg_nn_command_size_e
{
NBG_NN_COMMAND_SIZE_128 = 0,
NBG_NN_COMMAND_SIZE_192 = 1,
};
typedef struct _nbg_reader
{
vip_uint32_t offset;
vip_uint32_t total_size;
vip_uint8_t *data;
vip_uint8_t *current_data;
} nbg_reader_t;
typedef struct _nbg_parser_data
{
/* Fixed part of the bin. */
gcvip_bin_fixed_t fixed;
/* Dynamic data part of the bin. */
gcvip_bin_inout_entry_t *inputs;
gcvip_bin_inout_entry_t *outputs;
gcvip_bin_layer_t *orig_layers; /* original layers info, loading from binary graph */
gcvip_bin_operation_t *operations;
gcvip_bin_entry_t *LCDT;
gcvip_bin_sh_operation_t *sh_ops;
void *nn_ops;
gcvip_bin_tp_operation_t *tp_ops;
gcvip_bin_patch_data_entry_t *pd_entries;
gcvip_bin_hw_init_operation_info_entry_t *hw_init_ops;
gcvip_bin_entry_t *ICDT;
void *LCD;
vip_uint32_t n_inputs;
vip_uint32_t n_outputs;
vip_uint32_t n_orig_layers; /* the number of original layers */
vip_uint32_t n_operations;
vip_uint32_t n_LCDT;
vip_uint32_t n_nn_ops;
vip_uint32_t n_tp_ops;
vip_uint32_t n_sh_ops;
vip_uint32_t n_pd_entries;
vip_uint32_t n_hw_init_ops;
vip_uint32_t n_ICDT;
nbg_reader_t reader;
} nbg_parser_data_t;
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,19 @@
#ifndef _NBG_PARSER_VERSION_H
#define _NBG_PARSER_VERSION_H
#if defined(__cplusplus)
extern "C"{
#endif
#define VERSION_MAJOR 1
#define VERSION_MINOR 1
#define VERSION_SUB_MINOR 2
#if defined(__cplusplus)
}
#endif
#endif