33 const float *filter_data,
const float *bias_data,
36 const int stride_width = params->
stride_w;
37 const int stride_height = params->
stride_h;
40 const int pad_width = params->
pad_w;
41 const int pad_height = params->
pad_h;
45 const auto batches = input_shape.
dims(0);
46 const int input_height = input_shape.
dims(1);
47 const int input_width = input_shape.
dims(2);
48 const int input_depth = input_shape.
dims(3);
49 const int output_depth = filter_shape.
dims(0);
50 const int filter_height = filter_shape.
dims(1);
51 const int filter_width = filter_shape.
dims(2);
54 for (
int batch = 0; batch < batches; ++batch)
56 for (
int out_y = 0; out_y < output_height; ++out_y)
58 const int in_y_origin = (out_y * stride_height) - pad_height;
59 for (
int out_x = 0; out_x < output_width; ++out_x)
61 const int in_x_origin = (out_x * stride_width) - pad_width;
62 for (
int out_channel = 0; out_channel < output_depth; ++out_channel)
65 for (
int filter_y = 0; filter_y < filter_height; ++filter_y)
67 const int in_y = in_y_origin + dilation_height_factor * filter_y;
68 for (
int filter_x = 0; filter_x < filter_width; ++filter_x)
70 const int in_x = in_x_origin + dilation_width_factor * filter_x;
73 const bool is_point_inside_image =
74 (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height);
76 if (!is_point_inside_image)
81 for (
int in_channel = 0; in_channel < input_depth; ++in_channel)
83 const int input_data_offset =
84 ((batch * input_height + in_y) * input_width + in_x) * input_depth + in_channel;
86 const int filter_data_offset =
87 ((out_channel * filter_height + filter_y) * filter_width + filter_x) *
91 const float input_value = input_data[input_data_offset];
92 const float filter_value = filter_data[filter_data_offset];
93 total += (input_value * filter_value);
100 total += bias_data[out_channel];
103 const int output_data_offset =
104 ((batch * output_height + out_y) * output_width + out_x) * output_depth + out_channel;
106 output_data[output_data_offset] =
107 std::min(std::max(total, output_activation_min), output_activation_max);
OMStatus ConvFloat(const core::FloatConv2D *params, const core::OMRuntimeShape &input_shape, const float *input_data, const core::OMRuntimeShape &filter_shape, const float *filter_data, const float *bias_data, const core::OMRuntimeShape &output_shape, float *output_data)