18#ifndef ONERT_MICRO_EXECUTE_PAL_DEPTHWISE_CONV_2D_H
19#define ONERT_MICRO_EXECUTE_PAL_DEPTHWISE_CONV_2D_H
21#include "PALDepthwiseConv2DCommon.h"
31 const core::OMRuntimeShape &input_shape,
const int8_t *input_data,
32 const core::OMRuntimeShape &filter_shape,
33 const int8_t *filter_data,
const int32_t *bias_data,
34 const core::OMRuntimeShape &
output_shape, int8_t *output_data)
37 const int stride_width = params.stride_width;
38 const int stride_height = params.stride_height;
39 const int dilation_width_factor = params.dilation_width_factor;
40 const int dilation_height_factor = params.dilation_height_factor;
41 const int pad_width = params.pad_w;
42 const int pad_height = params.pad_h;
43 const int depth_multiplier = params.depth_multiplier;
44 const int32_t input_offset = params.input_offset;
45 const int32_t output_offset = params.output_offset;
46 const int32_t output_activation_min = params.quantized_activation_min;
47 const int32_t output_activation_max = params.quantized_activation_max;
49 const auto &output_multiplier = params.per_channel_output_multiplier;
50 const auto &output_shift = params.per_channel_output_shift;
53 assert(input_shape.dimensionsCount() == 4);
54 assert(filter_shape.dimensionsCount() == 4);
59 const int input_height = input_shape.dims(1);
60 const int input_width = input_shape.dims(2);
61 const int input_depth = input_shape.dims(3);
62 const int filter_height = filter_shape.dims(1);
63 const int filter_width = filter_shape.dims(2);
66 assert(output_depth == input_depth * depth_multiplier);
68 for (
int batch = 0; batch < batches; ++batch)
70 for (
int out_y = 0; out_y < output_height; ++out_y)
72 for (
int out_x = 0; out_x < output_width; ++out_x)
74 for (
int in_channel = 0; in_channel < input_depth; ++in_channel)
76 for (
int m = 0;
m < depth_multiplier; ++
m)
78 const int output_channel =
m + in_channel * depth_multiplier;
79 const int in_x_origin = (out_x * stride_width) - pad_width;
80 const int in_y_origin = (out_y * stride_height) - pad_height;
82 for (
int filter_y = 0; filter_y < filter_height; ++filter_y)
84 for (
int filter_x = 0; filter_x < filter_width; ++filter_x)
86 const int in_x = in_x_origin + dilation_width_factor * filter_x;
87 const int in_y = in_y_origin + dilation_height_factor * filter_y;
89 const bool is_point_inside_image =
90 (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height);
91 if (is_point_inside_image)
95 int32_t filter_val = filter_data[
offset(filter_shape.dimsData(), 0, filter_y,
96 filter_x, output_channel)];
112 acc += filter_val * (input_val + input_offset);
118 acc += bias_data[output_channel];
121 output_shift[output_channel]);
122 acc += output_offset;
123 acc = std::max(acc, output_activation_min);
124 acc = std::min(acc, output_activation_max);
126 static_cast<int8_t
>(acc);
int32_t dimensionsCount() const
int32_t dims(int i) const
const luci_interpreter::RuntimeShape output_shape
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)
OMStatus DepthwiseConvPerChannel(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)
int32_t multiplyByQuantizedMultiplier(int32_t x, int32_t quantized_multiplier, int shift)