18#ifndef ONERT_MICRO_EXECUTE_PAL_CONV_2D_H
19#define ONERT_MICRO_EXECUTE_PAL_CONV_2D_H
21#include "PALConv2DCommon.h"
35 const int8_t *input_data,
const core::OMRuntimeShape &filter_shape,
36 const int8_t *filter_data,
const int32_t *bias_data,
37 const core::OMRuntimeShape &
output_shape, int8_t *output_data)
40 const int32_t input_offset = params.input_offset;
41 const int stride_width = params.stride_width;
42 const int stride_height = params.stride_height;
43 const int dilation_width_factor = params.dilation_width_factor;
44 const int dilation_height_factor = params.dilation_height_factor;
45 const int pad_width = params.pad_w;
46 const int pad_height = params.pad_h;
47 const int32_t output_offset = params.output_offset;
49 const auto &output_multiplier = params.per_channel_output_multiplier;
50 const auto &output_shift = params.per_channel_output_shift;
53 const int32_t output_activation_min = params.quantized_activation_min;
54 const int32_t output_activation_max = params.quantized_activation_max;
57 assert(output_activation_max >= output_activation_min);
58 assert(input_shape.dimensionsCount() == 4);
59 assert(filter_shape.dimensionsCount() == 4);
63 const int input_depth = input_shape.dims(3);
67 const int input_height = input_shape.dims(1);
68 const int input_width = input_shape.dims(2);
69 const int filter_height = filter_shape.dims(1);
70 const int filter_width = filter_shape.dims(2);
71 const int filter_input_depth = filter_shape.dims(3);
72 const int groups = input_depth / filter_input_depth;
74 assert(input_depth % filter_input_depth == 0);
75 const int filters_per_group = output_depth / groups;
76 assert(filters_per_group != 0);
79 for (
int batch = 0; batch < batches; ++batch)
81 for (
int out_y = 0; out_y < output_height; ++out_y)
83 const int in_y_origin = (out_y * stride_height) - pad_height;
84 for (
int out_x = 0; out_x < output_width; ++out_x)
86 const int in_x_origin = (out_x * stride_width) - pad_width;
87 for (
int out_channel = 0; out_channel < output_depth; ++out_channel)
89 auto group = out_channel / filters_per_group;
91 for (
int filter_y = 0; filter_y < filter_height; ++filter_y)
93 const int in_y = in_y_origin + dilation_height_factor * filter_y;
94 for (
int filter_x = 0; filter_x < filter_width; ++filter_x)
96 const int in_x = in_x_origin + dilation_width_factor * filter_x;
99 const bool is_point_inside_image =
100 (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height);
102 if (!is_point_inside_image)
107 for (
int in_channel = 0; in_channel < filter_input_depth; ++in_channel)
109 int32_t input_val =
input_data[
offset(input_shape.dimsData(), batch, in_y, in_x,
110 in_channel + group * filter_input_depth)];
111 int32_t filter_val = filter_data[
offset(filter_shape.dimsData(), out_channel,
112 filter_y, filter_x, in_channel)];
128 acc += filter_val * (input_val + input_offset);
135 acc += bias_data[out_channel];
138 output_shift[out_channel]);
139 acc += output_offset;
140 acc = std::max(acc, output_activation_min);
141 acc = std::min(acc, output_activation_max);
143 static_cast<int8_t
>(acc);
int32_t dimensionsCount() const
int32_t dims(int i) const
const luci_interpreter::RuntimeShape output_shape
OMStatus ConvPerChannel(const core::ConvQuant ¶ms, const core::OMRuntimeShape &input_shape, const int8_t *input_data, const core::OMRuntimeShape &filter_shape, const int8_t *filter_data, const int32_t *bias_data, const core::OMRuntimeShape &output_shape, int8_t *output_data)
int MatchingDim(const core::OMRuntimeShape &shape1, int index1, const core::OMRuntimeShape &shape2, int index2)
int offset(const int32_t *dims_data, int i0, int i1, int i2, int i3)
int32_t multiplyByQuantizedMultiplier(int32_t x, int32_t quantized_multiplier, int shift)