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