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

Function ref_conv_uint8

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

Source from the content-addressed store, hash-verified

1
2static int ref_conv_uint8(const uint8_t* input, uint8_t* output, const uint8_t* kernel, const int* 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
15 /* dequant input */
16 int input_size = batch * group * input_c * input_h * input_w;
17 float* input_buf = ( float* )malloc(sizeof(float) * input_size);
18 for(int i = 0; i < input_size; i++)
19 input_buf[i] = (input[i] - param->zero[0]) * param->scale[0];
20
21 /* dequant kernel */
22 int kernel_total = group * output_c * kernel_size;
23 float* kernel_buf = ( float* )malloc(sizeof(float) * kernel_total);
24 for(int i = 0; i < kernel_total; i++)
25 kernel_buf[i] = (kernel[i] - param->zero[1]) * param->k_scale[0];
26
27 /* dequant biases */
28 int bias_size = group * output_c;
29
30 float* bias_buf = NULL;
31 if(bias != NULL)
32 {
33 bias_buf = ( float* )malloc(sizeof(float) * bias_size);
34 for(int i = 0; i < bias_size; i++)
35 bias_buf[i] = bias[i] * param->scale[0] * param->k_scale[0];
36 }
37
38 int n, g, c, h, w, kc, kh, kw;
39 int input_offset = 0;
40 int kernel_offset = 0;
41 int output_offset = 0;
42 for(n = 0; n < batch; ++n)
43 {
44 for(g = 0; g < group; ++g)
45 {
46 for(c = 0; c < output_c; ++c)
47 {
48 for(h = 0; h < output_h; ++h)
49 {
50 for(w = 0; w < output_w; ++w)
51 {
52 const int h_start = (h * param->strides[0]) - param->pads[0];
53 const int w_start = (w * param->strides[1]) - param->pads[1];
54 float total = 0.f;
55 if(param->layout == 0)
56 {
57 output_offset = n * group * output_c * output_h * output_w +
58 g * output_c * output_h * output_w + c * output_h * output_w +
59 h * output_w + w;
60 }

Callers

nothing calls this directly

Calls 1

activationFunction · 0.70

Tested by

no test coverage detected