SHL 2.2.x
Loading...
Searching...
No Matches
csinn_runtime.h
Go to the documentation of this file.
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
25#ifndef INCLUDE_CSINN_RUNTIME_H_
26#define INCLUDE_CSINN_RUNTIME_H_
27
28#include <assert.h>
29#include <float.h>
30#include <math.h>
31#include <stdint.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#if (!defined SHL_BUILD_RTOS)
36#include <omp.h>
37#endif
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
68#define VERSION_MAJOR 2
69#define VERSION_MINOR 0
70#define VERSION_PATCH 0
71#define VERSION_SHIFT 8
72int csinn_version(char *vstr);
73
74/* tensor */
81int csinn_tensor_size(struct csinn_tensor *tensor);
82
89int csinn_tensor_byte_size(struct csinn_tensor *tensor);
90
97struct csinn_tensor *csinn_alloc_tensor(struct csinn_session *session);
98
104void csinn_free_tensor(struct csinn_tensor *tensor);
105
112void csinn_realloc_quant_info(struct csinn_tensor *tensor, int quant_info_num);
113
120void csinn_tensor_copy(struct csinn_tensor *dest, struct csinn_tensor *src);
121
129int csinn_tensor_data_convert(struct csinn_tensor *dest, struct csinn_tensor *src);
130
138int csinn_tensor_layout_convert(struct csinn_tensor *dest, struct csinn_tensor *src);
139
140/* op parameters */
148void *csinn_alloc_params(int params_size, struct csinn_session *session);
149
155void csinn_free_params(void *params);
156
157/* session */
168
174void csinn_free_session(struct csinn_session *session);
175
184void csinn_session_init(struct csinn_session *session);
185
191void csinn_session_deinit(struct csinn_session *session);
192
202int csinn_session_setup(struct csinn_session *session);
203
213int csinn_session_run(struct csinn_session *session);
214
224int csinn_load_binary_model(struct csinn_session *session);
225
235struct csinn_session *__attribute__((weak)) csinn_import_binary_model(char *bm_addr);
236
237/* input/output */
244void csinn_set_input_number(int number, struct csinn_session *sess);
245
252void csinn_set_output_number(int number, struct csinn_session *sess);
253
260int csinn_get_input_number(struct csinn_session *sess);
261
268int csinn_get_output_number(struct csinn_session *sess);
269
278int csinn_set_input(int index, struct csinn_tensor *input, struct csinn_session *sess);
279
288int csinn_set_output(int index, struct csinn_tensor *output, struct csinn_session *sess);
289
301int csinn_get_input(int index, struct csinn_tensor *input, struct csinn_session *sess);
302
314int csinn_get_output(int index, struct csinn_tensor *output, struct csinn_session *sess);
315
324int csinn_update_input(int index, struct csinn_tensor *input, struct csinn_session *sess);
333int csinn_update_output(int index, struct csinn_tensor *output, struct csinn_session *sess);
334
342int csinn_set_tensor_entry(struct csinn_tensor *tensor, struct csinn_session *sess);
343
344#ifdef __cplusplus
345}
346#endif
347
348#endif // INCLUDE_CSINN_RUNTIME_H_
int csinn_get_input(int index, struct csinn_tensor *input, struct csinn_session *sess)
Get the specified input of the model.
Definition: setup.c:326
int csinn_set_input(int index, struct csinn_tensor *input, struct csinn_session *sess)
Set the specified input of the model.
Definition: setup.c:290
int csinn_set_output(int index, struct csinn_tensor *output, struct csinn_session *sess)
Set the specified output of the model.
Definition: setup.c:272
int csinn_get_output(int index, struct csinn_tensor *output, struct csinn_session *sess)
Get the specified output of the model.
Definition: setup.c:308
void csinn_set_input_number(int number, struct csinn_session *sess)
Set the input number of the model.
Definition: setup.c:218
int csinn_get_input_number(struct csinn_session *sess)
Get the input number of the model.
Definition: setup.c:254
int csinn_set_tensor_entry(struct csinn_tensor *tensor, struct csinn_session *sess)
Set input nodes.
Definition: setup.c:445
void csinn_set_output_number(int number, struct csinn_session *sess)
Set the output number of the model.
Definition: setup.c:200
int csinn_update_input(int index, struct csinn_tensor *input, struct csinn_session *sess)
Update specified input information.
Definition: setup.c:344
int csinn_get_output_number(struct csinn_session *sess)
Get the output number of the model.
Definition: setup.c:236
int csinn_update_output(int index, struct csinn_tensor *output, struct csinn_session *sess)
Update specified output information.
Definition: setup.c:375
void csinn_free_params(void *params)
Release a structure described by an operator parameter.
Definition: utils.c:381
void * csinn_alloc_params(int params_size, struct csinn_session *session)
Allocate a basic structure common to all operators.
Definition: utils.c:361
void csinn_session_init(struct csinn_session *session)
Initialize session.
Definition: setup.c:167
int csinn_load_binary_model(struct csinn_session *session)
Load binary model.
Definition: setup.c:462
struct csinn_session * __attribute__((weak)) csinn_import_binary_model(char *bm_addr)
Import binary model.
Definition: format.c:951
void csinn_free_session(struct csinn_session *session)
Release a session.
Definition: setup.c:107
int csinn_session_run(struct csinn_session *session)
Run function.
Definition: setup.c:419
struct csinn_session * csinn_alloc_session()
Allocate a session.
Definition: setup.c:91
int csinn_session_setup(struct csinn_session *session)
Setup function.
Definition: setup.c:393
void csinn_session_deinit(struct csinn_session *session)
Uninitialize session.
Definition: setup.c:184
int csinn_tensor_layout_convert(struct csinn_tensor *dest, struct csinn_tensor *src)
Convert the layout of source and target tensor.
Definition: utils.c:1578
void csinn_realloc_quant_info(struct csinn_tensor *tensor, int quant_info_num)
Reallocate a specified amount of quantitative information.
Definition: utils.c:309
int csinn_tensor_size(struct csinn_tensor *tensor)
Get the number of elements in the tensor.
Definition: utils.c:226
struct csinn_tensor * csinn_alloc_tensor(struct csinn_session *session)
Allocate a tensor structure.
Definition: utils.c:289
void csinn_tensor_copy(struct csinn_tensor *dest, struct csinn_tensor *src)
Copying tensor, excluding data in tensor.
Definition: utils.c:323
void csinn_free_tensor(struct csinn_tensor *tensor)
Release a tensor structure.
Definition: utils.c:346
int csinn_tensor_data_convert(struct csinn_tensor *dest, struct csinn_tensor *src)
Numerical conversion according to the data type of source and target tensor.
Definition: utils.c:1806
int csinn_tensor_byte_size(struct csinn_tensor *tensor)
Get the number of bytes of elements in the tensor.
Definition: utils.c:253
Definition: csinn_data_structure.h:502
struct csinn_tensor ** input
Definition: csinn_data_structure.h:516
struct csinn_tensor ** output
Definition: csinn_data_structure.h:517
Definition: csinn_data_structure.h:475