SHL 2.2.x
Loading...
Searching...
No Matches
shl_e907.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_E907_H_
22#define INCLUDE_SHL_E907_H_
23
24#if __riscv_dsp
25#include <riscv-dsp.h>
26#endif //__riscv_dsp
27
28#include "csi_nn.h"
29#include "shl_gref.h"
30#include "shl_ref.h"
31
32int shl_e907_fullyconnected_init(struct csinn_tensor *input, struct csinn_tensor *output,
33 struct csinn_tensor *weights, struct csinn_tensor *bias,
34 struct csinn_fc_params *params);
35
36int shl_e907_concat_int8(struct csinn_tensor **input, struct csinn_tensor *output,
37 struct csinn_concat_params *params);
38int shl_e907_fullyconnected_int8(struct csinn_tensor *input, struct csinn_tensor *output,
39 struct csinn_tensor *weights, struct csinn_tensor *bias,
40 struct csinn_fc_params *params);
41int shl_e907_mul_int8(struct csinn_tensor *input0, struct csinn_tensor *input1,
42 struct csinn_tensor *output, struct csinn_diso_params *params);
43int shl_e907_softmax_int8(struct csinn_tensor *input, struct csinn_tensor *output,
44 struct csinn_softmax_params *params);
45int shl_e907_relu_int8(struct csinn_tensor *input, struct csinn_tensor *output,
46 struct csinn_relu_params *params);
47int shl_e907_sum_int8(struct csinn_tensor *input, struct csinn_tensor *output,
48 struct csinn_reduce_params *params);
49int shl_e907_conv2d_int8(struct csinn_tensor *input, struct csinn_tensor *output,
50 struct csinn_tensor *kernel, struct csinn_tensor *bias,
51 struct csinn_conv2d_params *params);
52
53int shl_rvp_get_xlenb();
54void shl_rvp_int8_to_int16(int8_t *src, int16_t *dst, size_t len);
55void shl_rvp_int16_to_int32(int16_t *src, int32_t *dst, size_t len);
56void shl_rvp_int32_to_int16(int32_t *src, int16_t *dst, size_t len);
57void shl_rvp_int16_to_int8(int16_t *src, int8_t *dst, size_t len);
58intXLEN_t shl_rvp_int16_to_xlen(int16_t val);
59intXLEN_t shl_rvp_int32_to_xlen(int32_t val);
60void shl_rvp_requantize(int32_t *src, int32_t multiplier, int32_t shift, int channel_size);
61void shl_rvp_saturated_int8(int32_t *src, int8_t *dst, int32_t out_zp, int size);
62
63static inline int32_t shl_rvp_mulh(int32_t rs1, int32_t rs2)
64{
65 int ret = 0;
66 asm volatile("mulh %0, %1, %2" : "=r"(ret) : "r"(rs1), "r"(rs2));
67 return ret;
68}
69
70static inline int8_t shl_rvp_clip_i8(int32_t val)
71{
72 if (val > 127) {
73 return 127;
74 } else if (val < -128) {
75 return -128;
76 } else {
77 return (int8_t)val;
78 }
79}
80
81#endif // INCLUDE_SHL_E907_H_
Definition: csinn_data_structure.h:780
Definition: csinn_data_structure.h:553
Definition: csinn_data_structure.h:753
Definition: csinn_data_structure.h:596
Definition: csinn_data_structure.h:1033
Definition: csinn_data_structure.h:676
Definition: csinn_data_structure.h:692
Definition: csinn_data_structure.h:475