MCPcopy Create free account
hub / github.com/OAID/Tengine / ref_conv_int8

Function ref_conv_int8

executor/operator/ref/kernel/convolution/ref_conv_int8.c:2–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1
2static int ref_conv_int8(const int8_t* input, int8_t* output, const int8_t* kernel, const int32_t* bias, op_data* param)
3{
4 int batch = param->batch;
5 int group = param->group;
6 int input_c = param->in_shape[0] / group;
7 int input_h = param->in_shape[1];
8 int input_w = param->in_shape[2];
9 int output_c = param->out_shape[0] / group;
10 int output_h = param->out_shape[1];
11 int output_w = param->out_shape[2];
12
13 int kernel_size = input_c * param->kernels[0] * param->kernels[1];
14 float *i32_f32_scales = (float*)malloc(sizeof(float) * param->out_shape[0]);
15
16 for(int i = 0; i < param->out_shape[0]; i++)
17 {
18 i32_f32_scales[i] = (param->scale[0] * param->k_scale[i]);
19 }
20 /* malloc output */
21 int output_size = group * batch * output_c * output_h * output_w;
22 float* output_buf = ( float* )malloc(sizeof(float) * output_size);
23
24 int n, g, c, h, w, kc, kh, kw;
25 int input_offset = 0;
26 int kernel_offset = 0;
27 int output_offset = 0;
28 for(n = 0; n < batch; ++n)
29 {
30 for(g = 0; g < group; ++g)
31 {
32 for(c = 0; c < output_c; ++c)
33 {
34 for(h = 0; h < output_h; ++h)
35 {
36 for(w = 0; w < output_w; ++w)
37 {
38 const int h_start = (h * param->strides[0]) - param->pads[0];
39 const int w_start = (w * param->strides[1]) - param->pads[1];
40 int32_t total = 0.f;
41 if(param->layout == 0)
42 {
43 output_offset = n * group * output_c * output_h * output_w +
44 g * output_c * output_h * output_w + c * output_h * output_w +
45 h * output_w + w;
46 }
47 else
48 {
49 output_offset = n * group * output_c * output_h * output_w +
50 h * output_w * group * output_c + w * group * output_c + output_c * g + c;
51 }
52 for(kc = 0; kc < input_c; ++kc)
53 {
54 for(kh = 0; kh < param->kernels[0]; ++kh)
55 {
56 for(kw = 0; kw < param->kernels[1]; ++kw)
57 {
58 const int cur_y = h_start + param->dilations[0] * kh;
59 const int cur_x = w_start + param->dilations[1] * kw;
60 // If the location is outside the bounds of the input image,

Callers

nothing calls this directly

Calls 1

activationFunction · 0.70

Tested by

no test coverage detected