18#ifndef LUCI_INTERPRETER_PAL_DEPTHWISE_CONV2D_COMMON_H
19#define LUCI_INTERPRETER_PAL_DEPTHWISE_CONV2D_COMMON_H
25static inline void DepthwiseConv2D(
const ConvParams ¶ms,
const int32_t *input_shape,
26 const float *input_data,
const int32_t *filter_shape,
27 const float *filter_data,
const float *bias_data,
30 const int stride_width = params.stride_width;
31 const int stride_height = params.stride_height;
32 const int dilation_width_factor = params.dilation_width_factor;
33 const int dilation_height_factor = params.dilation_height_factor;
34 const int pad_width = params.padding_values.width;
35 const int pad_height = params.padding_values.height;
36 const int depth_multiplier = params.depth_multiplier;
37 const float output_activation_min = params.float_activation_min;
38 const float output_activation_max = params.float_activation_max;
40 const int batches = input_shape[0];
41 const int input_height = input_shape[1];
42 const int input_width = input_shape[2];
43 const int input_depth = input_shape[3];
44 const int filter_height = filter_shape[1];
45 const int filter_width = filter_shape[2];
49 for (
int b = 0;
b < batches; ++
b)
51 for (
int out_y = 0; out_y < output_height; ++out_y)
53 for (
int out_x = 0; out_x < output_width; ++out_x)
55 for (
int ic = 0; ic < input_depth; ++ic)
57 for (
int m = 0;
m < depth_multiplier;
m++)
59 const int oc =
m + ic * depth_multiplier;
60 const int in_x_origin = (out_x * stride_width) - pad_width;
61 const int in_y_origin = (out_y * stride_height) - pad_height;
63 for (
int filter_y = 0; filter_y < filter_height; ++filter_y)
65 for (
int filter_x = 0; filter_x < filter_width; ++filter_x)
67 const int in_x = in_x_origin + dilation_width_factor * filter_x;
68 const int in_y = in_y_origin + dilation_height_factor * filter_y;
71 if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height))
74 float filter_value = filter_data[
offset(filter_shape, 0, filter_y, filter_x, oc)];
75 total += (input_value * filter_value);
79 float bias_value = 0.0f;
82 bias_value = bias_data[oc];
85 total + bias_value, output_activation_min, output_activation_max);
const luci_interpreter::RuntimeShape output_shape
int offset(const int32_t *dims_data, int i0, int i1, int i2, int i3)
T activationFunctionWithMinMax(T x, T output_activation_min, T output_activation_max)