source: azure_iot_hub_riscv/trunk/app_iothub_client/kendryte/kpu.h@ 453

Last change on this file since 453 was 453, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 22.7 KB
Line 
1/* Copyright 2018 Canaan Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef _KPU_H
16#define _KPU_H
17
18#include <kendryte-k210.h>
19#include <stdint.h>
20#include "device.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define kpu_matmul_begin kpu_conv2d_output
27#define IOMEM 0x40000000
28
29typedef int (*plic_irq_callback_t)(void *ctx);
30
31typedef struct
32{
33 union
34 {
35 uint64_t reg;
36 struct
37 {
38 uint64_t int_en : 1;
39 uint64_t ram_flag : 1;
40 uint64_t full_add : 1;
41 uint64_t depth_wise_layer : 1;
42 uint64_t reserved : 60;
43 } data;
44 } interrupt_enabe;
45
46 union
47 {
48 uint64_t reg;
49 struct
50 {
51 uint64_t image_src_addr : 15;
52 uint64_t reserved0 : 17;
53 uint64_t image_dst_addr : 15;
54 uint64_t reserved1 : 17;
55 } data;
56 } image_addr;
57
58 union
59 {
60 uint64_t reg;
61 struct
62 {
63 uint64_t i_ch_num : 10;
64 uint64_t reserved0 : 22;
65 uint64_t o_ch_num : 10;
66 uint64_t reserved1 : 6;
67 uint64_t o_ch_num_coef : 10;
68 uint64_t reserved2 : 6;
69 } data;
70 } image_channel_num;
71
72 union
73 {
74 uint64_t reg;
75 struct
76 {
77 uint64_t i_row_wid : 10;
78 uint64_t i_col_high : 9;
79 uint64_t reserved0 : 13;
80 uint64_t o_row_wid : 10;
81 uint64_t o_col_high : 9;
82 uint64_t reserved1 : 13;
83 } data;
84 } image_size;
85
86 union
87 {
88 uint64_t reg;
89 struct
90 {
91 uint64_t kernel_type : 3;
92 uint64_t pad_type : 1;
93 uint64_t pool_type : 4;
94 uint64_t first_stride : 1;
95 uint64_t bypass_conv : 1;
96 uint64_t load_para : 1;
97 uint64_t reserved0 : 5;
98 uint64_t dma_burst_size : 8;
99 uint64_t pad_value : 8;
100 uint64_t bwsx_base_addr : 32;
101 } data;
102 } kernel_pool_type_cfg;
103
104 union
105 {
106 uint64_t reg;
107 struct
108 {
109 uint64_t load_coor : 1;
110 uint64_t load_time : 6;
111 uint64_t reserved0 : 8;
112 uint64_t para_size : 17;
113 uint64_t para_start_addr : 32;
114 } data;
115 } kernel_load_cfg;
116
117 union
118 {
119 uint64_t reg;
120 struct
121 {
122 uint64_t coef_column_offset : 4;
123 uint64_t coef_row_offset : 12;
124 uint64_t reserved0 : 48;
125 } data;
126 } kernel_offset;
127
128 union
129 {
130 uint64_t reg;
131 struct
132 {
133 uint64_t channel_switch_addr : 15;
134 uint64_t reserved : 1;
135 uint64_t row_switch_addr : 4;
136 uint64_t coef_size : 8;
137 uint64_t coef_group : 3;
138 uint64_t load_act : 1;
139 uint64_t active_addr : 32;
140 } data;
141 } kernel_calc_type_cfg;
142
143 union
144 {
145 uint64_t reg;
146 struct
147 {
148 uint64_t wb_channel_switch_addr : 15;
149 uint64_t reserved0 : 1;
150 uint64_t wb_row_switch_addr : 4;
151 uint64_t wb_group : 3;
152 uint64_t reserved1 : 41;
153 } data;
154 } write_back_cfg;
155
156 union
157 {
158 uint64_t reg;
159 struct
160 {
161 uint64_t shr_w : 4;
162 uint64_t shr_x : 4;
163 uint64_t arg_w : 24;
164 uint64_t arg_x : 24;
165 uint64_t reserved0 : 8;
166 } data;
167 } conv_value;
168
169 union
170 {
171 uint64_t reg;
172 struct
173 {
174 uint64_t arg_add : 40;
175 uint64_t reserved : 24;
176 } data;
177 } conv_value2;
178
179 union
180 {
181 uint64_t reg;
182 struct
183 {
184 uint64_t send_data_out : 1;
185 uint64_t reserved : 15;
186 uint64_t channel_byte_num : 16;
187 uint64_t dma_total_byte : 32;
188 } data;
189 } dma_parameter;
190} kpu_layer_argument_t;
191
192typedef struct
193{
194 union
195 {
196 uint64_t reg;
197 struct
198 {
199 uint64_t shift_number : 8;
200 uint64_t y_mul : 16;
201 uint64_t x_start : 36;
202 } data;
203 } activate_para[16];
204
205 union
206 {
207 uint64_t reg;
208 struct
209 {
210 uint8_t result_bias[8];
211 } data;
212 } activate_para_bias0;
213
214 union
215 {
216 uint64_t reg;
217 struct
218 {
219 uint8_t result_bias[8];
220 } data;
221 } activate_para_bias1;
222} kpu_activate_table_t;
223
224typedef struct
225{
226 union
227 {
228 uint64_t reg;
229 struct
230 {
231 uint64_t norm_mul : 24;
232 uint64_t norm_add : 32;
233 uint64_t norm_shift : 4;
234 } data;
235 } batchnorm;
236} kpu_batchnorm_argument_t;
237
238typedef struct
239{
240 union
241 {
242 uint64_t reg;
243 struct
244 {
245 uint16_t weight[9];
246 } data;
247 } weights;
248} kpu_weights_kernel_16_3x3_t;
249
250typedef struct
251{
252 uint64_t calc_done_int : 1;
253 uint64_t layer_cfg_almost_empty_int : 1;
254 uint64_t layer_cfg_almost_full_int : 1;
255 uint64_t reserved : 61;
256} kpu_config_interrupt_t;
257
258typedef struct
259{
260 uint64_t fifo_full_threshold : 4;
261 uint64_t fifo_empty_threshold : 4;
262 uint64_t reserved : 56;
263} kpu_config_fifo_threshold_t;
264
265typedef struct
266{
267 uint64_t dma_fifo_flush_n : 1;
268 uint64_t gs_fifo_flush_n : 1;
269 uint64_t cfg_fifo_flush_n : 1;
270 uint64_t cmd_fifo_flush_n : 1;
271 uint64_t resp_fifo_flush_n : 1;
272 uint64_t reserved : 59;
273} kpu_config_fifo_ctrl_t;
274
275typedef struct
276{
277 uint64_t eight_bit_mode : 1;
278 uint64_t reserved : 63;
279} kpu_config_eight_bit_mode_t;
280
281typedef struct
282{
283 volatile uint64_t layer_argument_fifo;
284
285 volatile union
286 {
287 uint64_t reg;
288 kpu_config_interrupt_t data;
289 } interrupt_status;
290
291 volatile union
292 {
293 uint64_t reg;
294 kpu_config_interrupt_t data;
295 } interrupt_raw;
296
297 volatile union
298 {
299 uint64_t reg;
300 kpu_config_interrupt_t data;
301 } interrupt_mask;
302
303 volatile union
304 {
305 uint64_t reg;
306 kpu_config_interrupt_t data;
307 } interrupt_clear;
308
309 volatile union
310 {
311 uint64_t reg;
312 kpu_config_fifo_threshold_t data;
313 } fifo_threshold;
314
315 volatile uint64_t fifo_data_out;
316
317 volatile union
318 {
319 uint64_t reg;
320 kpu_config_fifo_ctrl_t data;
321 } fifo_ctrl;
322
323 volatile union
324 {
325 uint64_t reg;
326 kpu_config_eight_bit_mode_t data;
327 } eight_bit_mode;
328} kpu_config_t;
329
330#define dmac_channel_number_t int
331
332typedef struct
333{
334 kpu_layer_argument_t *layers;
335 kpu_layer_argument_t *remain_layers;
336 plic_irq_callback_t callback;
337 void *ctx;
338 uint64_t *src;
339 uint64_t *dst;
340 uint32_t src_length;
341 uint32_t dst_length;
342 uint32_t layers_length;
343 uint32_t remain_layers_length;
344 dmac_channel_number_t dma_ch;
345 uint32_t eight_bit_mode;
346 float output_scale;
347 float output_bias;
348 float input_scale;
349 float input_bias;
350} kpu_task_t;
351
352typedef struct
353{
354 uint32_t version;
355 uint32_t flags;
356 uint32_t arch;
357 uint32_t layers_length;
358 uint32_t max_start_address;
359 uint32_t main_mem_usage;
360 uint32_t output_count;
361} kpu_kmodel_header_t;
362
363typedef struct
364{
365 uint32_t version;
366 uint32_t flags;
367 uint32_t layers_length;
368 uint32_t max_start_address;
369 uint32_t layers_argument_start;
370} kpu_model_header_t;
371
372typedef struct
373{
374 uint32_t address;
375 uint32_t size;
376} kpu_model_output_t;
377
378typedef enum
379{
380 KL_INVALID = 0,
381 KL_ADD,
382 KL_QUANTIZED_ADD,
383 KL_GLOBAL_MAX_POOL2D,
384 KL_QUANTIZED_GLOBAL_MAX_POOL2D,
385 KL_GLOBAL_AVERAGE_POOL2D,
386 KL_QUANTIZED_GLOBAL_AVERAGE_POOL2D,
387 KL_MAX_POOL2D,
388 KL_QUANTIZED_MAX_POOL2D,
389 KL_AVERAGE_POOL2D,
390 KL_QUANTIZED_AVERAGE_POOL2D,
391 KL_QUANTIZE,
392 KL_DEQUANTIZE,
393 KL_REQUANTIZE,
394 KL_L2_NORMALIZATION,
395 KL_SOFTMAX,
396 KL_CONCAT,
397 KL_QUANTIZED_CONCAT,
398 KL_FULLY_CONNECTED,
399 KL_QUANTIZED_FULLY_CONNECTED,
400 KL_TENSORFLOW_FLATTEN,
401 KL_QUANTIZED_TENSORFLOW_FLATTEN,
402 KL_RESIZE_NEAREST_NEIGHBOR,
403 KL_QUANTIZED_RESIZE_NEAREST_NEIGHBOR,
404 KL_CHANNELWISE_DEQUANTIZE,
405 KL_LOGISTIC,
406 KL_K210_CONV = 10240,
407 KL_K210_ADD_PADDING,
408 KL_K210_REMOVE_PADDING,
409 KL_K210_UPLOAD
410} kpu_model_layer_type_t;
411
412typedef struct
413{
414 uint32_t type;
415 uint32_t body_size;
416} kpu_model_layer_header_t;
417
418typedef enum
419{
420 KLF_NONE = 0,
421 KLF_MAIN_MEM_OUT = 1
422} kpu_model_layer_flags_t;
423
424typedef enum
425{
426 KLP_SAME = 0,
427 KLP_VALID = 1
428} kpu_model_padding_t;
429
430typedef enum
431{
432 KLA_LINEAR = 0,
433 KLA_RELU = 1,
434 KLA_RELU6 = 2
435} kpu_model_activation_t;
436
437typedef struct
438{
439 float scale;
440 float bias;
441} kpu_model_quant_param_t;
442
443typedef struct
444{
445 uint32_t width;
446 uint32_t height;
447 uint32_t channels;
448} kpu_model_shape_t;
449
450typedef struct
451{
452 uint32_t start;
453 uint32_t size;
454} kpu_model_memory_range_t;
455
456typedef struct
457{
458 uint32_t flags;
459 uint32_t main_mem_out_address;
460 uint32_t layer_offset;
461 uint32_t weights_offset;
462 uint32_t bn_offset;
463 uint32_t act_offset;
464} kpu_model_conv_layer_argument_t;
465
466typedef struct
467{
468 uint32_t flags;
469 uint32_t main_mem_in_a_address;
470 uint32_t main_mem_in_b_address;
471 uint32_t main_mem_out_address;
472 uint32_t count;
473} kpu_model_add_layer_argument_t;
474
475typedef struct
476{
477 uint32_t flags;
478 uint32_t main_mem_in_a_address;
479 uint32_t main_mem_in_b_address;
480 uint32_t main_mem_out_address;
481 uint32_t count;
482 int32_t in_a_offset;
483 int32_t in_a_mul;
484 int32_t in_a_shift;
485 int32_t in_b_offset;
486 int32_t in_b_mul;
487 int32_t in_b_shift;
488 int32_t out_offset;
489 int32_t out_mul;
490 int32_t out_shift;
491} kpu_model_quant_add_layer_argument_t;
492
493typedef struct
494{
495 uint32_t flags;
496 uint32_t main_mem_in_address;
497 uint32_t main_mem_out_address;
498 uint32_t kernel_size;
499 uint32_t channels;
500} kpu_model_gap2d_layer_argument_t;
501
502typedef struct
503{
504 uint32_t flags;
505 uint32_t main_mem_in_address;
506 uint32_t main_mem_out_address;
507 kpu_model_shape_t in_shape;
508 kpu_model_shape_t out_shape;
509 uint32_t kernel_width;
510 uint32_t kernel_height;
511 uint32_t stride_width;
512 uint32_t stride_height;
513 uint32_t padding_width;
514 uint32_t padding_height;
515} kpu_model_quant_max_pool2d_layer_argument_t;
516
517typedef struct
518{
519 uint32_t flags;
520 uint32_t main_mem_in_address;
521 uint32_t main_mem_out_address;
522 kpu_model_shape_t in_shape;
523 kpu_model_shape_t out_shape;
524 uint32_t kernel_width;
525 uint32_t kernel_height;
526 uint32_t stride_width;
527 uint32_t stride_height;
528 uint32_t padding_width;
529 uint32_t padding_height;
530 kpu_model_activation_t act;
531} kpu_model_ave_pool2d_layer_argument_t;
532
533typedef struct
534{
535 uint32_t flags;
536 uint32_t main_mem_in_address;
537 uint32_t mem_out_address;
538 uint32_t count;
539 kpu_model_quant_param_t quant_param;
540} kpu_model_quantize_layer_argument_t;
541
542typedef struct
543{
544 uint32_t flags;
545 uint32_t main_mem_in_address;
546 uint32_t main_mem_out_address;
547 uint32_t count;
548 kpu_model_quant_param_t quant_param;
549} kpu_model_dequantize_layer_argument_t;
550
551typedef struct
552{
553 uint32_t flags;
554 uint32_t main_mem_in_address;
555 uint32_t main_mem_out_address;
556 uint32_t count;
557 uint8_t table[256];
558} kpu_model_requantize_layer_argument_t;
559
560typedef struct
561{
562 uint32_t flags;
563 uint32_t main_mem_in_address;
564 uint32_t kpu_mem_out_address;
565 uint32_t channels;
566} kpu_model_add_padding_layer_argument_t;
567
568typedef struct
569{
570 uint32_t flags;
571 uint32_t main_mem_in_address;
572 uint32_t main_mem_out_address;
573 uint32_t channels;
574} kpu_model_remove_padding_layer_argument_t;
575
576typedef struct
577{
578 uint32_t flags;
579 uint32_t main_mem_in_address;
580 uint32_t kpu_mem_out_address;
581 uint32_t width;
582 uint32_t height;
583 uint32_t channels;
584} kpu_model_upload_layer_argument_t;
585
586typedef struct
587{
588 uint32_t flags;
589 uint32_t main_mem_in_address;
590 uint32_t main_mem_out_address;
591 uint32_t channels;
592} kpu_model_l2_norm_layer_argument_t;
593
594typedef struct
595{
596 uint32_t flags;
597 uint32_t main_mem_in_address;
598 uint32_t main_mem_out_address;
599 uint32_t channels;
600} kpu_model_softmax_layer_argument_t;
601
602typedef struct
603{
604 uint32_t flags;
605 uint32_t main_mem_out_address;
606 uint32_t input_count;
607 kpu_model_memory_range_t inputs_mem[0];
608} kpu_model_concat_layer_argument_t;
609
610typedef struct
611{
612 uint32_t flags;
613 uint32_t main_mem_in_address;
614 uint32_t main_mem_out_address;
615 uint32_t in_channels;
616 uint32_t out_channels;
617 kpu_model_activation_t act;
618 float weights[0];
619} kpu_model_fully_connected_layer_argument_t;
620
621typedef struct
622{
623 uint32_t flags;
624 uint32_t main_mem_in_address;
625 uint32_t main_mem_out_address;
626 kpu_model_shape_t shape;
627} kpu_model_tf_flatten_layer_argument_t;
628
629typedef struct
630{
631 uint32_t flags;
632 uint32_t main_mem_in_address;
633 uint32_t main_mem_out_address;
634 kpu_model_shape_t in_shape;
635 uint32_t out_width;
636 uint32_t out_height;
637 uint32_t align_corners;
638} kpu_model_resize_nearest_neighbor_layer_argument_t;
639
640typedef struct
641{
642 uint32_t flags;
643 uint32_t main_mem_in_address;
644 uint32_t main_mem_out_address;
645 kpu_model_shape_t in_shape;
646 uint32_t out_width;
647 uint32_t out_height;
648 uint32_t align_corners;
649} kpu_model_quant_resize_nearest_neighbor_layer_argument_t;
650
651typedef struct
652{
653 uint32_t flags;
654 uint32_t main_mem_in_address;
655 uint32_t main_mem_out_address;
656 uint32_t channels;
657 uint32_t channel_size;
658 kpu_model_quant_param_t quant_params[0];
659} kpu_model_channelwise_dequant_argument_t;
660
661typedef struct
662{
663 uint32_t flags;
664 uint32_t main_mem_in_address;
665 uint32_t main_mem_out_address;
666 uint32_t channels;
667} kpu_model_logistic_layer_argument_t;
668
669typedef void (*kpu_done_callback_t)(void *userdata);
670
671typedef struct
672{
673 int is_nncase;
674
675 union
676 {
677 struct
678 {
679 const uint8_t *model_buffer;
680 uint8_t *main_buffer;
681 uint32_t output_count;
682 const kpu_model_output_t *outputs;
683 const kpu_model_layer_header_t *layer_headers;
684 const uint8_t *body_start;
685 uint32_t layers_length;
686 volatile uint32_t current_layer;
687 const uint8_t *volatile current_body;
688 dmac_channel_number_t dma_ch;
689 kpu_done_callback_t done_callback;
690 void *userdata;
691 };
692
693 struct
694 {
695 void* nncase_ctx;
696 };
697 };
698} kpu_model_context_t;
699
700typedef struct
701{
702 uint32_t weigths_offset;
703 uint32_t bn_offset;
704 uint32_t act_offset;
705 float input_scale;
706 float input_bias;
707 float output_scale;
708 float output_bias;
709} kpu_model_layer_metadata_t;
710
711typedef struct _quantize_param
712{
713 float scale;
714 float bias;
715} quantize_param_t;
716
717extern volatile kpu_config_t *const kpu;
718
719/**
720 * @brief Modle complier init kpu handler
721 *
722 * @param[in] task Kpu handler
723 *
724 * @return Kpu handler
725 */
726extern kpu_task_t *kpu_task_init(kpu_task_t *task);
727
728/**
729 * @brief Kpu run for AI
730 *
731 * @param[in] task Kpu handler
732 * @param[in] dma_ch DMA for kpu
733 * @param[in] src The picture data
734 * @param[in] dest The result of kpu
735 * @param[in] callback The callback of kpu
736 *
737 * @return result
738 * - 0 Success
739 * - Other Fail.Kpu is busy.
740 */
741int kpu_run(kpu_task_t *task, dmac_channel_number_t dma_ch, const void *src, void *dest, plic_irq_callback_t callback);
742
743/**
744 * @brief Get kpu result buf
745 *
746 * @param[in] task Kpu handler
747 *
748 * @return Kpu result buf
749 */
750uint8_t *kpu_get_output_buf(kpu_task_t *task);
751
752/**
753 * @brief Release kpu output buf
754 *
755 * @param[in] output_buf Kpu output buf
756 *
757 */
758void kpu_release_output_buf(uint8_t *output_buf);
759
760/**
761 * @brief Kpu run for AI
762 *
763 * @param[in] task Kpu handler
764*
765* @return result
766* - 0 Success
767* - Other Fail.Kpu is busy.
768*/
769int kpu_start(kpu_task_t *task);
770
771/**
772 * @brief Initialize kpu handler
773 *
774 * @param[in] task Kpu handler
775 *
776 * @return result
777 * - 0 Success
778 * - Other Fail.
779 */
780int kpu_single_task_init(kpu_task_t *task);
781
782/**
783 * @brief Uninitialize kpu handler
784 *
785 * @param[in] task Kpu handler
786 *
787 * @return result
788 * - 0 Success
789 * - Other Fail.
790 */
791int kpu_single_task_deinit(kpu_task_t *task);
792
793/**
794 * @brief Load kmodel and init kpu task
795 *
796 * @param[in] task Kpu handler
797 * @param[in] buffer Kmodel
798 * @param[in] meta Test data
799 *
800 * @return result
801 * - 0 Success
802 * - Other Fail.
803 */
804int kpu_model_load_from_buffer(kpu_task_t *task, uint8_t *buffer, kpu_model_layer_metadata_t **meta);
805
806/**
807 * @brief Kpu initialize
808 *
809 * @param[in] eight_bit_mode 0:16bit mode 1:8bit mode
810 * @param[in] callback Callback of kpu
811 * @param[in] userdata Data of callback
812 *
813 */
814void kpu_init(int eight_bit_mode, plic_irq_callback_t callback, void *userdata);
815
816/**
817 * @brief Kpu input data by dma
818 *
819 * @param[in] layer Kpu task layer
820 * @param[in] src Image data
821 * @param[in] dma_ch Dmac channel
822 * @param[in] callback Dmac complete callback
823 * @param[in] userdata Data of callback
824 *
825 */
826void 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);
827
828/**
829 * @brief Kpu input data by cpu
830 *
831 * @param[in] layer Kpu task layer
832 * @param[in] src Image data
833 * @param[in] width Image width
834 * @param[in] height Image heigth
835 * @param[in] channels Color channel, RGB is 3
836 *
837 */
838void kpu_input_with_padding(kpu_layer_argument_t *layer, const uint8_t *src, int width, int height, int channels);
839
840/**
841 * @brief Kpu run only one layer
842 *
843 * @param[in] layer Kpu task layer
844 *
845 */
846void kpu_conv2d(kpu_layer_argument_t *layer);
847
848/**
849 * @brief Kpu run only one layer then get the result by dma
850 *
851 * @param[in] layer Kpu task layer
852 * @param[in] dma_ch Dmac channel
853 * @param[in] dest Result
854 * @param[in] callback Dmac complete callback
855 * @param[in] userdata Data of callback
856 *
857 */
858void kpu_conv2d_output(kpu_layer_argument_t *layer, dmac_channel_number_t dma_ch, uint8_t *dest, plic_irq_callback_t callback, void *userdata);
859
860/**
861 * @brief Kpu pooling
862 *
863 * @param[in] src Source
864 * @param[in] src_param Source param
865 * @param[in] kernel_size Kernel size, 7*7 is 49
866 * @param[in] channels Channels
867 * @param[in] dest Dest
868 * @param[in] dest_param Dest param
869 *
870 */
871void 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);
872
873/**
874 * @brief Kpu pooling
875 *
876 * @param[in] src Source
877 * @param[in] src_param Source param
878 * @param[in] kernel_size Kernel size, 7*7 is 49
879 * @param[in] channels Channels
880 * @param[in] dest Dest
881 *
882 */
883void kpu_global_average_pool_float(const uint8_t *src, const quantize_param_t *src_param, int kernel_size, int channels, float *dest);
884
885/**
886 * @brief Kpu fullly connected by cpu
887 *
888 * @param[in] src Source
889 * @param[in] weights Weight
890 * @param[in] biases Biases
891 * @param[in] dest Dest
892 * @param[in] input_channels Input channels
893 * @param[in] output_channels Output channels
894 *
895 */
896void kpu_fully_connected(const float *src, const float *weights, const float *biases, float *dest, int input_channels, int output_channels);
897
898/**
899 * @brief Kpu matrix multiplication
900 *
901 * @param[in] src Source
902 * @param[in] channels Channels
903 * @param[in] dest Dest
904 * @param[in] dest_param Dest param
905 *
906 */
907void kpu_matmul_end(const uint8_t *src, int channels, float *dest, const quantize_param_t *dest_param);
908
909/**
910 * @brief Kpu dequantize
911 *
912 * @param[in] src Source
913 * @param[in] src_param Source param
914 * @param[in] count Dequantize count
915 * @param[in] dest Dest
916 *
917 */
918void kpu_dequantize(const uint8_t *src, const quantize_param_t *src_param, size_t count, float *dest);
919
920/**
921 * @brief Kpu load kmodel
922 *
923 * @param[in] ctx Kmodel object
924 * @param[in] buffer Kmodel buffer
925 *
926 * @return result
927 * - 0 Success
928 * - Other Fail.
929 */
930int kpu_load_kmodel(kpu_model_context_t *ctx, const uint8_t *buffer);
931
932/**
933 * @brief Kpu free kmodel buffer
934 *
935 * @param[in] ctx kmodel object
936 *
937 */
938void kpu_model_free(kpu_model_context_t *ctx);
939
940/**
941 * @brief Kpu load kmodel
942 *
943 * @param[in] ctx Kmodel object
944 * @param[in] index Output index
945 * @param[in] data Output data
946 * @param[in] size Output data size
947 *
948 * @return result
949 * - 0 Success
950 * - Other Fail.
951 */
952int kpu_get_output(kpu_model_context_t *ctx, uint32_t index, uint8_t **data, size_t *size);
953
954/**
955 * @brief Kpu run kmodel
956 *
957 * @param[in] ctx Kmodel object
958 * @param[in] src Source data
959 * @param[in] dma_ch Dma channel
960 * @param[in] done_callback Kpu complete callback
961 * @param[in] userdata Data of callback
962 *
963 * @return result
964 * - 0 Success
965 * - Other Fail.
966 */
967int 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);
968
969#ifdef __cplusplus
970}
971#endif
972
973#endif
Note: See TracBrowser for help on using the repository browser.