56 const circle::Tensor *input;
57 const circle::Tensor *weight;
58 const circle::Tensor *output;
65 const circle::Conv2DOptions *options;
73 input = runtime_kernel.
inputs[inputTensorIdx];
74 weight = runtime_kernel.
inputs[weightTensorIdx];
75 output = runtime_kernel.
outputs[outputTensorIdx];
76 assert(input !=
nullptr);
77 assert(weight !=
nullptr);
79 assert(output !=
nullptr);
81 status = runtime_kernel.
getDataFromStorage(op_index, runtime_storage, runtime_context);
85 input_data = runtime_kernel.
inputs_data[inputTensorIdx];
86 weight_data = runtime_kernel.
inputs_data[weightTensorIdx];
87 bias_data = runtime_kernel.
inputs_data[biasTensorIdx];
88 output_data = runtime_kernel.
outputs_data[outputTensorIdx];
89 assert(input_data !=
nullptr);
90 assert(weight_data !=
nullptr);
92 assert(output_data !=
nullptr);
94 options = runtime_kernel.
first_operator->builtin_options_as_Conv2DOptions();
99 int32_t padding_h = 0;
100 int32_t padding_w = 0;
106 const int input_width = input_shape.
dims(2);
107 const int input_height = input_shape.
dims(1);
108 const int weight_width = weight_shape.
dims(2);
109 const int weight_height = weight_shape.
dims(1);
111 options->dilation_h_factor(), options->dilation_w_factor(),
112 input_height, input_width, weight_height, weight_width,
113 options->padding(), &padding_h, &padding_w);
115 switch (input->type())
118 case circle::TensorType_FLOAT32:
122 ¶ms.activation_min, ¶ms.activation_max);
123 params.stride_w = options->stride_w();
124 params.stride_h = options->stride_h();
125 params.dilation_width_factor = options->dilation_w_factor();
126 params.dilation_height_factor = options->dilation_h_factor();
127 params.pad_h = padding_h;
128 params.pad_w = padding_w;
133 status =
pal::ConvFloat(¶ms, input_shape, core::utils::castInputData<float>(input_data),
134 weight_shape, core::utils::castInputData<float>(weight_data),
135 core::utils::castInputData<float>(bias_data),
output_shape,
136 core::utils::castOutputData<float>(output_data));
137 assert(status ==
Ok);
142 case circle::TensorType_INT8:
145 params.
pad_h = padding_h;
146 params.pad_w = padding_w;
148 const auto padding = options->padding();
149 const auto stride_height = options->stride_h();
150 const auto stride_width = options->stride_w();
151 const auto dilation_height_factor = options->dilation_h_factor();
152 const auto dilation_width_factor = options->dilation_h_factor();
154 params.stride_height = stride_height;
155 params.stride_width = stride_width;
156 params.dilation_height_factor = dilation_height_factor;
157 params.dilation_width_factor = dilation_width_factor;
160 createConvParams(params, input, weight, output, options->fused_activation_function());
161 assert(status ==
Ok);
167 weight_shape, core::utils::castInputData<int8_t>(weight_data),
168 core::utils::castInputData<int32_t>(bias_data),
output_shape,
169 core::utils::castOutputData<int8_t>(output_data));
176 assert(
false &&
"Unsupported type.");
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)
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)
void computePaddingHeightWidth(int32_t stride_height, int32_t stride_width, int32_t dilation_rate_height, int32_t dilation_rate_width, int32_t in_height, int32_t in_width, int32_t filter_height, int32_t filter_width, circle::Padding padding, int32_t *padding_h, int32_t *padding_w)