SHL 2.2.x
Loading...
Searching...
No Matches
shl_utils.h
1/*
2 * Copyright (C) 2016-2023 T-Head Semiconductor Co., Ltd. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* SHL version 2.2.x */
20
21#ifndef INCLUDE_SHL_UTILS_H_
22#define INCLUDE_SHL_UTILS_H_
23
24#include <assert.h>
25#include <float.h>
26#include <math.h>
27#include <stdint.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#if (!defined SHL_BUILD_RTOS)
32#include <omp.h>
33#endif
35#ifdef SHL_MCONF_CONFIG
36#include "mconf_config.h"
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43struct shl_ref_graph {
44 struct shl_node **input;
45 struct shl_node **output;
46 int input_num;
47 int output_num;
48 struct shl_node **layer;
49 int layer_size;
50 int layer_index;
51};
52
53struct shl_gref_target_data {
54 struct shl_ref_graph *graph;
55 int is_hybrid_quantization_type;
56 void *cpu_option;
57};
58
59void shl_get_top5(float *buf, uint32_t size, float *prob, uint32_t *cls);
60void shl_show_top5(struct csinn_tensor *output, struct csinn_session *sess);
61uint64_t shl_get_timespec();
62void shl_print_time_interval(uint64_t start, uint64_t end, const char *msg);
63void shl_statistical_mean_std(float *data, int sz);
64void shl_quantize_multiplier(double double_multiplier, int32_t *quantized_multiplier,
65 int32_t *shift);
66
67void shl_register_runtime_callback(int api, void *cb);
68void shl_register_op_callback(int api, void *cb);
69int shl_op_callback_map(struct csinn_params_base *base, int op, int dtype);
70
71void *shl_get_p0_cb(struct csinn_params_base *base);
72void *shl_get_init_cb(struct csinn_params_base *base);
73
74enum csinn_rmode_enum shl_get_run_mode(struct csinn_params_base *base);
75
76struct shl_cb_table {
77 int shl_cb_key;
78 struct csinn_callback shl_cb_value;
79};
80
81struct shl_cb_op_list {
82 struct shl_cb_op_list *next;
83 enum csinn_dtype_enum dtype;
84 enum csinn_op_enum op_name;
85 struct csinn_callback *cb;
86};
87
88struct shl_cb_op_list *shl_cb_list_end(struct shl_cb_op_list *list);
89struct csinn_callback *shl_cb_list_match(struct shl_cb_op_list *list, enum csinn_dtype_enum dtype,
90 enum csinn_op_enum op_name);
91
92struct shl_bm_sections {
93 int32_t graph_offset;
94 int32_t graph_size;
95 int32_t params_offset;
96 int32_t params_size;
97 int32_t info_offset;
98 int32_t info_size;
99 int32_t debug_offset;
100 int32_t debug_size;
101};
102
103struct shl_binary_model_section_info {
104 int32_t section_num;
105 int32_t section_info_size;
106 int32_t reserve[6];
107 struct shl_bm_sections sections[127];
108};
109
110char *shl_bm_header_str();
111
112void shl_dump_bm_header(FILE *f);
113void shl_dump_bm_section_info(FILE *f, struct shl_binary_model_section_info *info);
114int shl_dump_bm_graph_info_section(FILE *f, struct csinn_session *sess);
115void shl_bm_session_load(struct csinn_session *dest, struct csinn_session *src);
116int shl_dump_bm_graph_struct_section(FILE *f, struct shl_ref_graph *graph);
117void shl_bm_graph_struct_load(struct shl_ref_graph *dest, struct shl_ref_graph *src);
118
119bool shl_is_first_layer_input(struct csinn_tensor *input, struct csinn_session *sess);
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif // INCLUDE_SHL_UTILS_H_
csinn_rmode_enum
Definition: csinn_data_structure.h:111
csinn_op_enum
Definition: csinn_data_structure.h:127
csinn_dtype_enum
Definition: csinn_data_structure.h:39
Definition: csinn_data_structure.h:524
Definition: csinn_data_structure.h:533
Definition: csinn_data_structure.h:502
Definition: csinn_data_structure.h:475