32 const int32_t *output_multiplier,
const int32_t *output_shift,
33 const Shape &input_shape,
const uint8_t *input_data,
34 const Shape &filter_shape,
const uint8_t *filter_data,
35 const int32_t *filter_zeropoint,
36 [[maybe_unused]]
const Shape &bias_shape,
59 assert(output_activation_min <= output_activation_max);
62 const int input_height = input_shape.
Dims(1);
63 const int input_width = input_shape.
Dims(2);
64 const int input_depth = input_shape.
Dims(3);
65 const int filter_height = filter_shape.
Dims(1);
66 const int filter_width = filter_shape.
Dims(2);
69 assert(output_depth == input_depth * depth_multiplier);
70 assert(bias_shape.FlatSize() == output_depth);
72 for (
int batch = 0; batch < batches; ++batch)
74 for (
int out_y = 0; out_y < output_height; ++out_y)
76 for (
int out_x = 0; out_x < output_width; ++out_x)
78 for (
int in_channel = 0; in_channel < input_depth; ++in_channel)
80 for (
int m = 0;
m < depth_multiplier; ++
m)
82 const int output_channel =
m + in_channel * depth_multiplier;
83 const int in_x_origin = (out_x * stride_width) - pad_width;
84 const int in_y_origin = (out_y * stride_height) - pad_height;
86 for (
int filter_y = 0; filter_y < filter_height; ++filter_y)
88 for (
int filter_x = 0; filter_x < filter_width; ++filter_x)
90 const int in_x = in_x_origin + dilation_width_factor * filter_x;
91 const int in_y = in_y_origin + dilation_height_factor * filter_y;
93 const bool is_point_inside_image =
94 (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height);
95 if (is_point_inside_image)
98 input_data[
Offset(input_shape, batch, in_y, in_x, in_channel)];
100 filter_data[
Offset(filter_shape, 0, filter_y, filter_x, output_channel)];
122 const int32_t filter_offset = -filter_zeropoint[output_channel];
123 acc += (filter_val + filter_offset) * (input_val + input_offset);
130 acc += bias_data[output_channel];
133 output_shift[output_channel]);
134 acc += output_offset;
135 acc = std::max(acc, output_activation_min);
136 acc = std::min(acc, output_activation_max);
139 static_cast<uint8_t
>(acc);
void DepthwiseConvPerChannel(const DepthwiseConvParams ¶ms, const int32_t *output_multiplier, const int32_t *output_shift, const Shape &input_shape, const uint8_t *input_data, const Shape &filter_shape, const uint8_t *filter_data, const int32_t *filter_zeropoint, const Shape &bias_shape, const int32_t *bias_data, const Shape &output_shape, uint8_t *output_data)