forked from xuos/xiuos
fix some bugs for sd read
This commit is contained in:
parent
6fa996d132
commit
2df54e7f41
|
@ -3,5 +3,9 @@ menuconfig USING_K210_YOLOV2_DETECT
|
|||
depends on USING_KPU_PROCESSING
|
||||
default n
|
||||
|
||||
config CAMERA_DEV_DRIVER
|
||||
string "Set camera dev path"
|
||||
default "/dev/ov2640"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
SRC_FILES := k210_yolov2_detect.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
#ifndef _K210_DETECT_H_
|
||||
#define _K210_DETECT_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#include "sleep.h"
|
||||
|
||||
void k210_detect(char *json_file_path);
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
SRC_FILES := region_layer.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -224,7 +224,7 @@ static void get_region_boxes(region_layer_t *rl, float *predictions, float **pro
|
|||
correct_region_boxes(rl, boxes);
|
||||
}
|
||||
|
||||
static int nms_comparator(void *pa, void *pb)
|
||||
static int nms_comparator(const void *pa,const void *pb)
|
||||
{
|
||||
sortable_box_t a = *(sortable_box_t *)pa;
|
||||
sortable_box_t b = *(sortable_box_t *)pb;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
SRC_FILES := json_parser.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
#include "json_parser.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
// #include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
|
@ -31,9 +34,9 @@ yolov2_params_t param_parse(char *json_file_path)
|
|||
} else {
|
||||
printf("Reading config from: %s\n", json_file_path);
|
||||
}
|
||||
|
||||
read(fin, buffer, sizeof(buffer));
|
||||
close(fin);
|
||||
|
||||
// read json string
|
||||
json_obj = cJSON_Parse(buffer);
|
||||
// free(buffer);
|
||||
|
|
|
@ -73,6 +73,12 @@ typedef int pid_t;
|
|||
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg);
|
||||
int pthread_attr_init(pthread_attr_t *attr);
|
||||
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stack_size);
|
||||
int pthread_attr_setschedparam(pthread_attr_t *attr,struct sched_param const *param);
|
||||
int pthread_attr_setstack(pthread_attr_t *attr,
|
||||
void *stack_base,
|
||||
size_t stack_size);
|
||||
void pthread_exit(void *value_ptr);
|
||||
int pthread_detach(pthread_t thread);
|
||||
int pthread_join(pthread_t thread, void **retval);
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
#include <stdio.h>
|
||||
#include "include/pthread.h"
|
||||
|
||||
#define DEFAULT_STACK_SIZE 2048
|
||||
#define DEFAULT_PRIORITY (KTASK_PRIORITY_MAX/2 + KTASK_PRIORITY_MAX/4)
|
||||
|
||||
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg)
|
||||
{
|
||||
|
@ -55,6 +59,27 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|||
|
||||
}
|
||||
|
||||
int pthread_attr_init(pthread_attr_t *attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_attr_setschedparam(pthread_attr_t *attr,
|
||||
struct sched_param const *param)
|
||||
{
|
||||
NULL_PARAM_CHECK(attr != NULL);
|
||||
NULL_PARAM_CHECK(param != NULL);
|
||||
|
||||
attr->schedparam.sched_priority = param->sched_priority;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stack_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pthread_exit(void *value_ptr){
|
||||
//todo add exit value
|
||||
UserTaskQuit();
|
||||
|
|
|
@ -70,6 +70,7 @@ extern int HwLcdInit(void);
|
|||
extern int HwSpiInit(void);
|
||||
extern int HwSoftSPIInit(void);
|
||||
extern int HwWiznetInit(void);
|
||||
extern int HwDvpInit(void);
|
||||
|
||||
#include <iot-vfs.h>
|
||||
#ifdef MOUNT_USB
|
||||
|
|
|
@ -123,9 +123,17 @@ menuconfig BSP_USING_WIZCHIP
|
|||
|
||||
menuconfig BSP_USING_CAMERA
|
||||
bool "Using camera device"
|
||||
default y
|
||||
default n
|
||||
select RESOURCES_CAMERA
|
||||
if BSP_USING_CAMERA
|
||||
source "$BSP_DIR/third_party_driver/dvp/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_KPU
|
||||
bool "Using kpu device"
|
||||
default n
|
||||
select RESOURCES_KPU
|
||||
if BSP_USING_KPU
|
||||
source "$BSP_DIR/third_party_driver/kpu/Kconfig"
|
||||
endif
|
||||
|
||||
|
|
|
@ -59,9 +59,13 @@ endif
|
|||
ifeq ($(CONFIG_BSP_USING_WIZCHIP),y)
|
||||
SRC_DIR += ethernet
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BSP_USING_CAMERA),y)
|
||||
SRC_DIR += dvp
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BSP_USING_KPU),y)
|
||||
SRC_DIR += kpu
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -0,0 +1,930 @@
|
|||
/* Copyright 2018 Canaan Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef _KPU_H
|
||||
#define _KPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <plic.h>
|
||||
#include "dmac.h"
|
||||
|
||||
#define kpu_matmul_begin kpu_conv2d_output
|
||||
|
||||
typedef int (*plic_irq_callback_t)(void *ctx);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t int_en:1;
|
||||
uint64_t ram_flag:1;
|
||||
uint64_t full_add:1;
|
||||
uint64_t depth_wise_layer:1;
|
||||
uint64_t reserved:60;
|
||||
} data;
|
||||
} interrupt_enabe;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t image_src_addr:15;
|
||||
uint64_t reserved0:17;
|
||||
uint64_t image_dst_addr:15;
|
||||
uint64_t reserved1:17;
|
||||
} data;
|
||||
} image_addr;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t i_ch_num:10;
|
||||
uint64_t reserved0:22;
|
||||
uint64_t o_ch_num:10;
|
||||
uint64_t reserved1:6;
|
||||
uint64_t o_ch_num_coef:10;
|
||||
uint64_t reserved2:6;
|
||||
} data;
|
||||
} image_channel_num;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t i_row_wid:10;
|
||||
uint64_t i_col_high:9;
|
||||
uint64_t reserved0:13;
|
||||
uint64_t o_row_wid:10;
|
||||
uint64_t o_col_high:9;
|
||||
uint64_t reserved1:13;
|
||||
} data;
|
||||
} image_size;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t kernel_type:3;
|
||||
uint64_t pad_type:1;
|
||||
uint64_t pool_type:4;
|
||||
uint64_t first_stride:1;
|
||||
uint64_t bypass_conv:1;
|
||||
uint64_t load_para:1;
|
||||
uint64_t reserved0:5;
|
||||
uint64_t dma_burst_size:8;
|
||||
uint64_t pad_value:8;
|
||||
uint64_t bwsx_base_addr:32;
|
||||
} data;
|
||||
} kernel_pool_type_cfg;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t load_coor:1;
|
||||
uint64_t load_time:6;
|
||||
uint64_t reserved0:8;
|
||||
uint64_t para_size:17;
|
||||
uint64_t para_start_addr:32;
|
||||
} data;
|
||||
} kernel_load_cfg;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t coef_column_offset:4;
|
||||
uint64_t coef_row_offset:12;
|
||||
uint64_t reserved0:48;
|
||||
} data;
|
||||
} kernel_offset;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t channel_switch_addr:15;
|
||||
uint64_t reserved:1;
|
||||
uint64_t row_switch_addr:4;
|
||||
uint64_t coef_size:8;
|
||||
uint64_t coef_group:3;
|
||||
uint64_t load_act:1;
|
||||
uint64_t active_addr:32;
|
||||
} data;
|
||||
} kernel_calc_type_cfg;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t wb_channel_switch_addr:15;
|
||||
uint64_t reserved0:1;
|
||||
uint64_t wb_row_switch_addr:4;
|
||||
uint64_t wb_group:3;
|
||||
uint64_t reserved1:41;
|
||||
} data;
|
||||
} write_back_cfg;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t shr_w:4;
|
||||
uint64_t shr_x:4;
|
||||
uint64_t arg_w:24;
|
||||
uint64_t arg_x:24;
|
||||
uint64_t reserved0:8;
|
||||
} data;
|
||||
} conv_value;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t arg_add:40;
|
||||
uint64_t reserved:24;
|
||||
} data;
|
||||
} conv_value2;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t send_data_out:1;
|
||||
uint64_t reserved:15;
|
||||
uint64_t channel_byte_num:16;
|
||||
uint64_t dma_total_byte:32;
|
||||
} data;
|
||||
} dma_parameter;
|
||||
} kpu_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t shift_number:8;
|
||||
uint64_t y_mul:16;
|
||||
uint64_t x_start:36;
|
||||
} data;
|
||||
} activate_para[16];
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint8_t result_bias[8];
|
||||
} data;
|
||||
} activate_para_bias0;
|
||||
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint8_t result_bias[8];
|
||||
} data;
|
||||
} activate_para_bias1;
|
||||
} kpu_activate_table_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint64_t norm_mul:24;
|
||||
uint64_t norm_add:32;
|
||||
uint64_t norm_shift:4;
|
||||
} data;
|
||||
} batchnorm;
|
||||
} kpu_batchnorm_argument_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint64_t reg;
|
||||
struct
|
||||
{
|
||||
uint16_t weight[9];
|
||||
} data;
|
||||
} weights;
|
||||
} kpu_weights_kernel_16_3x3_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t calc_done_int:1;
|
||||
uint64_t layer_cfg_almost_empty_int:1;
|
||||
uint64_t layer_cfg_almost_full_int:1;
|
||||
uint64_t reserved:61;
|
||||
} kpu_config_interrupt_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t fifo_full_threshold:4;
|
||||
uint64_t fifo_empty_threshold:4;
|
||||
uint64_t reserved:56;
|
||||
} kpu_config_fifo_threshold_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t dma_fifo_flush_n:1;
|
||||
uint64_t gs_fifo_flush_n:1;
|
||||
uint64_t cfg_fifo_flush_n:1;
|
||||
uint64_t cmd_fifo_flush_n:1;
|
||||
uint64_t resp_fifo_flush_n:1;
|
||||
uint64_t reserved:59;
|
||||
} kpu_config_fifo_ctrl_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t eight_bit_mode:1;
|
||||
uint64_t reserved:63;
|
||||
} kpu_config_eight_bit_mode_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
volatile uint64_t layer_argument_fifo;
|
||||
|
||||
volatile union
|
||||
{
|
||||
uint64_t reg;
|
||||
kpu_config_interrupt_t data;
|
||||
} interrupt_status;
|
||||
|
||||
volatile union
|
||||
{
|
||||
uint64_t reg;
|
||||
kpu_config_interrupt_t data;
|
||||
} interrupt_raw;
|
||||
|
||||
volatile union {
|
||||
uint64_t reg;
|
||||
kpu_config_interrupt_t data;
|
||||
} interrupt_mask;
|
||||
|
||||
volatile union
|
||||
{
|
||||
uint64_t reg;
|
||||
kpu_config_interrupt_t data;
|
||||
} interrupt_clear;
|
||||
|
||||
volatile union
|
||||
{
|
||||
uint64_t reg;
|
||||
kpu_config_fifo_threshold_t data;
|
||||
} fifo_threshold;
|
||||
|
||||
volatile uint64_t fifo_data_out;
|
||||
|
||||
volatile union
|
||||
{
|
||||
uint64_t reg;
|
||||
kpu_config_fifo_ctrl_t data;
|
||||
} fifo_ctrl;
|
||||
|
||||
volatile union
|
||||
{
|
||||
uint64_t reg;
|
||||
kpu_config_eight_bit_mode_t data;
|
||||
} eight_bit_mode;
|
||||
} kpu_config_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
kpu_layer_argument_t *layers;
|
||||
kpu_layer_argument_t *remain_layers;
|
||||
plic_irq_callback_t callback;
|
||||
void *ctx;
|
||||
uint64_t *src;
|
||||
uint64_t *dst;
|
||||
uint32_t src_length;
|
||||
uint32_t dst_length;
|
||||
uint32_t layers_length;
|
||||
uint32_t remain_layers_length;
|
||||
dmac_channel_number_t dma_ch;
|
||||
uint32_t eight_bit_mode;
|
||||
float output_scale;
|
||||
float output_bias;
|
||||
float input_scale;
|
||||
float input_bias;
|
||||
} kpu_task_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t version;
|
||||
uint32_t flags;
|
||||
uint32_t arch;
|
||||
uint32_t layers_length;
|
||||
uint32_t max_start_address;
|
||||
uint32_t main_mem_usage;
|
||||
uint32_t output_count;
|
||||
} kpu_kmodel_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t version;
|
||||
uint32_t flags;
|
||||
uint32_t layers_length;
|
||||
uint32_t max_start_address;
|
||||
uint32_t layers_argument_start;
|
||||
} kpu_model_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t address;
|
||||
uint32_t size;
|
||||
} kpu_model_output_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KL_INVALID = 0,
|
||||
KL_ADD,
|
||||
KL_QUANTIZED_ADD,
|
||||
KL_GLOBAL_MAX_POOL2D,
|
||||
KL_QUANTIZED_GLOBAL_MAX_POOL2D,
|
||||
KL_GLOBAL_AVERAGE_POOL2D,
|
||||
KL_QUANTIZED_GLOBAL_AVERAGE_POOL2D,
|
||||
KL_MAX_POOL2D,
|
||||
KL_QUANTIZED_MAX_POOL2D,
|
||||
KL_AVERAGE_POOL2D,
|
||||
KL_QUANTIZED_AVERAGE_POOL2D,
|
||||
KL_QUANTIZE,
|
||||
KL_DEQUANTIZE,
|
||||
KL_REQUANTIZE,
|
||||
KL_L2_NORMALIZATION,
|
||||
KL_SOFTMAX,
|
||||
KL_CONCAT,
|
||||
KL_QUANTIZED_CONCAT,
|
||||
KL_FULLY_CONNECTED,
|
||||
KL_QUANTIZED_FULLY_CONNECTED,
|
||||
KL_TENSORFLOW_FLATTEN,
|
||||
KL_QUANTIZED_TENSORFLOW_FLATTEN,
|
||||
KL_RESIZE_NEAREST_NEIGHBOR,
|
||||
KL_QUANTIZED_RESIZE_NEAREST_NEIGHBOR,
|
||||
KL_CHANNELWISE_DEQUANTIZE,
|
||||
KL_K210_CONV = 10240,
|
||||
KL_K210_ADD_PADDING,
|
||||
KL_K210_REMOVE_PADDING,
|
||||
KL_K210_UPLOAD
|
||||
} kpu_model_layer_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type;
|
||||
uint32_t body_size;
|
||||
} kpu_model_layer_header_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KLF_NONE = 0,
|
||||
KLF_MAIN_MEM_OUT = 1
|
||||
} kpu_model_layer_flags_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KLP_SAME = 0,
|
||||
KLP_VALID = 1
|
||||
} kpu_model_padding_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KLA_LINEAR = 0,
|
||||
KLA_RELU = 1,
|
||||
KLA_RELU6 = 2
|
||||
} kpu_model_activation_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float scale;
|
||||
float bias;
|
||||
} kpu_model_quant_param_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t channels;
|
||||
} kpu_model_shape_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t start;
|
||||
uint32_t size;
|
||||
} kpu_model_memory_range_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t layer_offset;
|
||||
uint32_t weights_offset;
|
||||
uint32_t bn_offset;
|
||||
uint32_t act_offset;
|
||||
} kpu_model_conv_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_a_address;
|
||||
uint32_t main_mem_in_b_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t count;
|
||||
} kpu_model_add_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_a_address;
|
||||
uint32_t main_mem_in_b_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t count;
|
||||
int32_t in_a_offset;
|
||||
int32_t in_a_mul;
|
||||
int32_t in_a_shift;
|
||||
int32_t in_b_offset;
|
||||
int32_t in_b_mul;
|
||||
int32_t in_b_shift;
|
||||
int32_t out_offset;
|
||||
int32_t out_mul;
|
||||
int32_t out_shift;
|
||||
} kpu_model_quant_add_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t kernel_size;
|
||||
uint32_t channels;
|
||||
} kpu_model_gap2d_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
kpu_model_shape_t in_shape;
|
||||
kpu_model_shape_t out_shape;
|
||||
uint32_t kernel_width;
|
||||
uint32_t kernel_height;
|
||||
uint32_t stride_width;
|
||||
uint32_t stride_height;
|
||||
uint32_t padding_width;
|
||||
uint32_t padding_height;
|
||||
} kpu_model_quant_max_pool2d_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
kpu_model_shape_t in_shape;
|
||||
kpu_model_shape_t out_shape;
|
||||
uint32_t kernel_width;
|
||||
uint32_t kernel_height;
|
||||
uint32_t stride_width;
|
||||
uint32_t stride_height;
|
||||
uint32_t padding_width;
|
||||
uint32_t padding_height;
|
||||
kpu_model_activation_t act;
|
||||
} kpu_model_ave_pool2d_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t mem_out_address;
|
||||
uint32_t count;
|
||||
kpu_model_quant_param_t quant_param;
|
||||
} kpu_model_quantize_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t count;
|
||||
kpu_model_quant_param_t quant_param;
|
||||
} kpu_model_dequantize_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t count;
|
||||
uint8_t table[256];
|
||||
} kpu_model_requantize_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t kpu_mem_out_address;
|
||||
uint32_t channels;
|
||||
} kpu_model_add_padding_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t channels;
|
||||
} kpu_model_remove_padding_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t kpu_mem_out_address;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t channels;
|
||||
} kpu_model_upload_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t channels;
|
||||
} kpu_model_l2_norm_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t channels;
|
||||
} kpu_model_softmax_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t input_count;
|
||||
kpu_model_memory_range_t inputs_mem[0];
|
||||
} kpu_model_concat_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t in_channels;
|
||||
uint32_t out_channels;
|
||||
kpu_model_activation_t act;
|
||||
float weights[0];
|
||||
} kpu_model_fully_connected_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
kpu_model_shape_t shape;
|
||||
} kpu_model_tf_flatten_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
kpu_model_shape_t in_shape;
|
||||
uint32_t out_width;
|
||||
uint32_t out_height;
|
||||
uint32_t align_corners;
|
||||
} kpu_model_resize_nearest_neighbor_layer_argument_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t main_mem_in_address;
|
||||
uint32_t main_mem_out_address;
|
||||
uint32_t channels;
|
||||
uint32_t channel_size;
|
||||
kpu_model_quant_param_t quant_params[0];
|
||||
} kpu_model_channelwise_dequant_argument_t;
|
||||
|
||||
typedef void(*kpu_done_callback_t)(void* userdata);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const uint8_t *model_buffer;
|
||||
uint8_t *main_buffer;
|
||||
uint32_t output_count;
|
||||
const kpu_model_output_t *outputs;
|
||||
const kpu_model_layer_header_t *layer_headers;
|
||||
const uint8_t *body_start;
|
||||
uint32_t layers_length;
|
||||
volatile uint32_t current_layer;
|
||||
const uint8_t * volatile current_body;
|
||||
dmac_channel_number_t dma_ch;
|
||||
kpu_done_callback_t done_callback;
|
||||
void *userdata;
|
||||
} kpu_model_context_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t weigths_offset;
|
||||
uint32_t bn_offset;
|
||||
uint32_t act_offset;
|
||||
float input_scale;
|
||||
float input_bias;
|
||||
float output_scale;
|
||||
float output_bias;
|
||||
} kpu_model_layer_metadata_t;
|
||||
|
||||
typedef struct _quantize_param
|
||||
{
|
||||
float scale;
|
||||
float bias;
|
||||
} quantize_param_t;
|
||||
|
||||
extern volatile kpu_config_t *const kpu;
|
||||
|
||||
/**
|
||||
* @brief Modle complier init kpu handler
|
||||
*
|
||||
* @param[in] task Kpu handler
|
||||
*
|
||||
* @return Kpu handler
|
||||
*/
|
||||
extern kpu_task_t *kpu_task_init(kpu_task_t* task);
|
||||
|
||||
/**
|
||||
* @brief Kpu run for AI
|
||||
*
|
||||
* @param[in] task Kpu handler
|
||||
* @param[in] dma_ch DMA for kpu
|
||||
* @param[in] src The picture data
|
||||
* @param[in] dest The result of kpu
|
||||
* @param[in] callback The callback of kpu
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.Kpu is busy.
|
||||
*/
|
||||
int kpu_run(kpu_task_t* task, dmac_channel_number_t dma_ch, const void *src, void* dest, plic_irq_callback_t callback);
|
||||
|
||||
/**
|
||||
* @brief Get kpu result buf
|
||||
*
|
||||
* @param[in] task Kpu handler
|
||||
*
|
||||
* @return Kpu result buf
|
||||
*/
|
||||
uint8_t *kpu_get_output_buf(kpu_task_t* task);
|
||||
|
||||
/**
|
||||
* @brief Release kpu output buf
|
||||
*
|
||||
* @param[in] output_buf Kpu output buf
|
||||
*
|
||||
*/
|
||||
void kpu_release_output_buf(uint8_t *output_buf);
|
||||
|
||||
/**
|
||||
* @brief Kpu run for AI
|
||||
*
|
||||
* @param[in] task Kpu handler
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.Kpu is busy.
|
||||
*/
|
||||
int kpu_start(kpu_task_t *task);
|
||||
|
||||
/**
|
||||
* @brief Initialize kpu handler
|
||||
*
|
||||
* @param[in] task Kpu handler
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.
|
||||
*/
|
||||
int kpu_single_task_init(kpu_task_t *task);
|
||||
|
||||
/**
|
||||
* @brief Uninitialize kpu handler
|
||||
*
|
||||
* @param[in] task Kpu handler
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.
|
||||
*/
|
||||
int kpu_single_task_deinit(kpu_task_t *task);
|
||||
|
||||
/**
|
||||
* @brief Load kmodel and init kpu task
|
||||
*
|
||||
* @param[in] task Kpu handler
|
||||
* @param[in] buffer Kmodel
|
||||
* @param[in] meta Test data
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.
|
||||
*/
|
||||
int kpu_model_load_from_buffer(kpu_task_t *task, uint8_t *buffer, kpu_model_layer_metadata_t **meta);
|
||||
|
||||
/**
|
||||
* @brief Kpu initialize
|
||||
*
|
||||
* @param[in] eight_bit_mode 0:16bit mode 1:8bit mode
|
||||
* @param[in] callback Callback of kpu
|
||||
* @param[in] userdata Data of callback
|
||||
*
|
||||
*/
|
||||
void kpu_init(int eight_bit_mode, plic_irq_callback_t callback, void *userdata);
|
||||
|
||||
/**
|
||||
* @brief Kpu input data by dma
|
||||
*
|
||||
* @param[in] layer Kpu task layer
|
||||
* @param[in] src Image data
|
||||
* @param[in] dma_ch Dmac channel
|
||||
* @param[in] callback Dmac complete callback
|
||||
* @param[in] userdata Data of callback
|
||||
*
|
||||
*/
|
||||
void kpu_input_dma(const kpu_layer_argument_t *layer, const uint8_t *src, dmac_channel_number_t dma_ch, plic_irq_callback_t callback, void *userdata);
|
||||
|
||||
/**
|
||||
* @brief Kpu input data by cpu
|
||||
*
|
||||
* @param[in] layer Kpu task layer
|
||||
* @param[in] src Image data
|
||||
* @param[in] width Image width
|
||||
* @param[in] height Image heigth
|
||||
* @param[in] channels Color channel, RGB is 3
|
||||
*
|
||||
*/
|
||||
void kpu_input_with_padding(kpu_layer_argument_t *layer, const uint8_t *src, int width, int height, int channels);
|
||||
|
||||
/**
|
||||
* @brief Kpu run only one layer
|
||||
*
|
||||
* @param[in] layer Kpu task layer
|
||||
*
|
||||
*/
|
||||
void kpu_conv2d(kpu_layer_argument_t *layer);
|
||||
|
||||
/**
|
||||
* @brief Kpu run only one layer then get the result by dma
|
||||
*
|
||||
* @param[in] layer Kpu task layer
|
||||
* @param[in] dma_ch Dmac channel
|
||||
* @param[in] dest Result
|
||||
* @param[in] callback Dmac complete callback
|
||||
* @param[in] userdata Data of callback
|
||||
*
|
||||
*/
|
||||
void kpu_conv2d_output(kpu_layer_argument_t *layer, dmac_channel_number_t dma_ch, uint8_t *dest, plic_irq_callback_t callback, void *userdata);
|
||||
|
||||
/**
|
||||
* @brief Kpu pooling
|
||||
*
|
||||
* @param[in] src Source
|
||||
* @param[in] src_param Source param
|
||||
* @param[in] kernel_size Kernel size, 7*7 is 49
|
||||
* @param[in] channels Channels
|
||||
* @param[in] dest Dest
|
||||
* @param[in] dest_param Dest param
|
||||
*
|
||||
*/
|
||||
void kpu_global_average_pool(const uint8_t *src, const quantize_param_t *src_param, int kernel_size, int channels, uint8_t *dest, const quantize_param_t *dest_param);
|
||||
|
||||
/**
|
||||
* @brief Kpu pooling
|
||||
*
|
||||
* @param[in] src Source
|
||||
* @param[in] src_param Source param
|
||||
* @param[in] kernel_size Kernel size, 7*7 is 49
|
||||
* @param[in] channels Channels
|
||||
* @param[in] dest Dest
|
||||
*
|
||||
*/
|
||||
void kpu_global_average_pool_float(const uint8_t *src, const quantize_param_t *src_param, int kernel_size, int channels, float *dest);
|
||||
|
||||
/**
|
||||
* @brief Kpu fullly connected by cpu
|
||||
*
|
||||
* @param[in] src Source
|
||||
* @param[in] weights Weight
|
||||
* @param[in] biases Biases
|
||||
* @param[in] dest Dest
|
||||
* @param[in] input_channels Input channels
|
||||
* @param[in] output_channels Output channels
|
||||
*
|
||||
*/
|
||||
void kpu_fully_connected(const float *src, const float *weights, const float *biases, float *dest, int input_channels, int output_channels);
|
||||
|
||||
/**
|
||||
* @brief Kpu matrix multiplication
|
||||
*
|
||||
* @param[in] src Source
|
||||
* @param[in] channels Channels
|
||||
* @param[in] dest Dest
|
||||
* @param[in] dest_param Dest param
|
||||
*
|
||||
*/
|
||||
void kpu_matmul_end(const uint8_t *src, int channels, float *dest, const quantize_param_t *dest_param);
|
||||
|
||||
/**
|
||||
* @brief Kpu dequantize
|
||||
*
|
||||
* @param[in] src Source
|
||||
* @param[in] src_param Source param
|
||||
* @param[in] count Dequantize count
|
||||
* @param[in] dest Dest
|
||||
*
|
||||
*/
|
||||
void kpu_dequantize(const uint8_t *src, const quantize_param_t *src_param, size_t count, float *dest);
|
||||
|
||||
/**
|
||||
* @brief Kpu load kmodel
|
||||
*
|
||||
* @param[in] ctx Kmodel object
|
||||
* @param[in] buffer Kmodel buffer
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.
|
||||
*/
|
||||
int kpu_load_kmodel(kpu_model_context_t *ctx, const uint8_t *buffer);
|
||||
|
||||
/**
|
||||
* @brief Kpu free kmodel buffer
|
||||
*
|
||||
* @param[in] ctx kmodel object
|
||||
*
|
||||
*/
|
||||
void kpu_model_free(kpu_model_context_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief Kpu load kmodel
|
||||
*
|
||||
* @param[in] ctx Kmodel object
|
||||
* @param[in] index Output index
|
||||
* @param[in] data Output data
|
||||
* @param[in] size Output data size
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.
|
||||
*/
|
||||
int kpu_get_output(kpu_model_context_t *ctx, uint32_t index, uint8_t **data, size_t *size);
|
||||
|
||||
/**
|
||||
* @brief Kpu run kmodel
|
||||
*
|
||||
* @param[in] ctx Kmodel object
|
||||
* @param[in] src Source data
|
||||
* @param[in] dma_ch Dma channel
|
||||
* @param[in] done_callback Kpu complete callback
|
||||
* @param[in] userdata Data of callback
|
||||
*
|
||||
* @return result
|
||||
* - 0 Success
|
||||
* - Other Fail.
|
||||
*/
|
||||
int kpu_run_kmodel(kpu_model_context_t *ctx, const uint8_t *src, dmac_channel_number_t dma_ch, kpu_done_callback_t done_callback, void *userdata);
|
||||
|
||||
#endif
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
SRC_FILES := kpu.c
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
File diff suppressed because it is too large
Load Diff
|
@ -461,6 +461,9 @@ KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/tensorflow
|
|||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/tensorflow-lite/tensorflow-lite-for-mcu/source/third_party/gemmlowp #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/tensorflow-lite/tensorflow-lite-for-mcu/source/third_party/flatbuffers/include #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/tensorflow-lite/tensorflow-lite-for-mcu/source/third_party/ruy #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/kpu/k210_yolov2_detect_procedure #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/kpu/yolov2 #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/kpu/yolov2_json #
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIB_LV),y)
|
||||
|
@ -479,6 +482,10 @@ KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/control/plc_protoc
|
|||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/control/plc_protocol/melsec #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/control/plc_protocol/opcua #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/control/plc_protocol/s7 #
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(CONFIG_LIB_USING_CJSON), y)
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/lib/cJSON
|
||||
endif
|
||||
|
||||
|
|
|
@ -850,7 +850,6 @@ static uint32 SdReadMultiBlock(SpiSdDeviceType spi_sd_dev, uint32 id, const uint
|
|||
|
||||
do
|
||||
{
|
||||
BusDevWriteData(&spi_sd_dev->spi_dev->haldev, &write_param);
|
||||
BusDevReadData(&spi_sd_dev->spi_dev->haldev, &read_param);
|
||||
|
||||
SD_TIMEOUT(start_time, 10 * SPI_SD_TIMEOUT_NUM);
|
||||
|
|
Loading…
Reference in New Issue