41 Status validate_arguments_optimized(
const ITensorInfo *
src,
42 const ITensorInfo *weights,
43 const ITensorInfo *biases,
44 const ITensorInfo *
dst,
45 const ConvolutionInfo &
info)
59 src->dimension(idx_w) +
info.pad_stride_info.pad_left() +
60 info.pad_stride_info.pad_right());
62 src->dimension(idx_h) +
info.pad_stride_info.pad_top() +
63 info.pad_stride_info.pad_bottom());
65 if (biases !=
nullptr)
85 const ITensorInfo *weights,
86 const ITensorInfo *biases,
88 const ConvolutionInfo &
info)
96 _has_bias = biases !=
nullptr;
100 _are_weights_const = weights->are_values_constant();
103 _is_activationlayer_enabled =
106 _dwc_optimized_func = std::make_unique<CpuDepthwiseConv2dAssemblyDispatch>();
109 _permute_input = std::make_unique<cpu::CpuPermute>();
110 _permute_weights = std::make_unique<cpu::CpuPermute>();
111 _permute_output = std::make_unique<cpu::CpuPermute>();
113 auto input_perm = std::make_unique<TensorInfo>();
114 auto weights_perm = std::make_unique<TensorInfo>();
115 auto output_perm = std::make_unique<TensorInfo>();
122 _permute_weights->configure(weights, weights_perm.get(),
PermutationVector(2U, 0U, 1U));
126 output_perm->set_quantization_info(
dst->quantization_info());
129 _dwc_optimized_func->configure(input_perm.get(), weights_perm.get(), biases, output_perm.get(),
info);
137 _dwc_optimized_func->configure(
src, weights, biases,
dst,
info);
141 if (_is_activationlayer_enabled)
143 _activationlayer_function = std::make_unique<cpu::CpuActivation>();
144 _activationlayer_function->configure(
dst,
nullptr,
info.act_info);
149 const ITensorInfo *weights,
150 const ITensorInfo *biases,
151 const ITensorInfo *
dst,
152 const ConvolutionInfo &
info)
154 return validate_arguments_optimized(
src, weights, biases,
dst,
info);
175 _permute_input->run(
pack);
192 _dwc_optimized_func->run(
pack);
207 _dwc_optimized_func->run(
pack);
217 _permute_output->run(
pack);
221 if (_is_activationlayer_enabled)
226 _activationlayer_function->run(
pack);
230 void CpuDepthwiseConv2d::CpuDepthwiseConv2dOptimizedInternal::prepare(ITensorPack &tensors)
234 if (!_are_weights_const)
240 ITensorPack pack_opt;
246 _dwc_optimized_func->prepare(pack_opt);
265 _permute_weights->run(
pack);
267 weights->mark_as_unused();
269 ITensorPack pack_opt;
275 _dwc_optimized_func->prepare(pack_opt);
279 ITensorPack pack_opt;
285 _dwc_optimized_func->prepare(pack_opt);
293 const ITensorInfo *weights,
294 const ITensorInfo *biases,
296 const ConvolutionInfo &
info)
303 _is_prepared = !_is_nchw;
305 ITensorInfo *input_to_use =
src;
306 const ITensorInfo *weights_to_use = weights;
307 ITensorInfo *output_to_use =
dst;
309 auto input_perm = std::make_unique<TensorInfo>();
310 auto weights_perm = std::make_unique<TensorInfo>();
311 auto output_perm = std::make_unique<TensorInfo>(
312 dst->clone()->set_is_resizable(
true).reset_padding().set_tensor_shape(TensorShape()));
316 _permute_input = std::make_unique<cpu::CpuPermute>();
317 _permute_weights = std::make_unique<cpu::CpuPermute>();
321 input_to_use = input_perm.get();
323 _permute_weights->configure(weights, weights_perm.get(),
PermutationVector(2U, 0U, 1U));
325 weights_to_use = weights_perm.get();
327 output_to_use = output_perm.get();
330 _depthwise_conv_kernel = std::make_unique<cpu::kernels::CpuDepthwiseConv2dNativeKernel>();
331 _depthwise_conv_kernel->configure(input_to_use, weights_to_use, biases, output_to_use,
info);
335 _permute_output = std::make_unique<cpu::CpuPermute>();
341 _is_activationlayer_enabled =
info.act_info.enabled();
342 if (_is_activationlayer_enabled)
344 _activationlayer_function = std::make_unique<cpu::CpuActivation>();
345 _activationlayer_function->configure(
dst,
nullptr,
info.act_info);
350 const ITensorInfo *weights,
351 const ITensorInfo *biases,
352 const ITensorInfo *
dst,
353 const ConvolutionInfo &
info)
358 TensorShape permuted_input_shape =
src->tensor_shape();
359 TensorShape permuted_weights_shape = weights->tensor_shape();
360 TensorShape permuted_output_shape =
366 const TensorInfo permuted_input = TensorInfo(
src->clone()
367 ->set_is_resizable(
true)
369 .set_tensor_shape(permuted_input_shape)
371 const TensorInfo permuted_weights = TensorInfo(weights->clone()
372 ->set_is_resizable(
true)
374 .set_tensor_shape(permuted_weights_shape)
376 const TensorInfo permuted_output = TensorInfo(
dst->clone()
377 ->set_is_resizable(
true)
379 .set_tensor_shape(permuted_output_shape)
387 &permuted_input, &permuted_weights, biases, &permuted_output,
info));
421 _permute_input->run(
pack);
423 ITensorPack pack_depth;
433 ITensorPack pack_depth;
448 _permute_output->run(
pack);
451 if (_is_activationlayer_enabled)
456 _activationlayer_function->run(
pack);
460 void CpuDepthwiseConv2d::CpuDepthwiseConv2dGeneric::prepare(ITensorPack &tensors)
473 _permute_weights->run(
pack);
474 weights->mark_as_unused();
489 switch (_depth_conv_func)
492 _func_optimized.configure(
src, weights, biases,
dst,
info);
495 _func_generic.configure(
src, weights, biases,
dst,
info);
509 switch (depth_conv_func)
540 switch (_depth_conv_func)
543 _func_optimized.run(tensors);
546 _func_generic.run(tensors);
555 switch (_depth_conv_func)
558 _func_optimized.prepare(tensors);
561 _func_generic.prepare(tensors);