blob: 1ec1417a58f9fadc73e66b9bf6dffad5897109cd [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
arovir019e53a352018-08-31 15:26:35 +01006#include "NeonDepthwiseConvolutionFloatWorkload.hpp"
telsoa014fcda012018-03-09 14:13:49 +00007#include "backends/NeonLayerSupport.hpp"
8#include "backends/CpuTensorHandle.hpp"
9#include "backends/ArmComputeTensorUtils.hpp"
10
11
12namespace armnn
13{
14using namespace armcomputetensorutils;
15
arovir019e53a352018-08-31 15:26:35 +010016NeonDepthwiseConvolutionFloatWorkload::NeonDepthwiseConvolutionFloatWorkload(
telsoa014fcda012018-03-09 14:13:49 +000017 const DepthwiseConvolution2dQueueDescriptor& descriptor,
18 const WorkloadInfo& info)
telsoa01c577f2c2018-08-31 09:22:23 +010019 : FloatWorkload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000020{
21 const TensorInfo& weightInfo = m_Data.m_Weight->GetTensorInfo();
22
telsoa01c577f2c2018-08-31 09:22:23 +010023 m_KernelTensor = std::make_unique<arm_compute::Tensor>();
24 BuildArmComputeTensor(*m_KernelTensor, weightInfo);
telsoa014fcda012018-03-09 14:13:49 +000025
telsoa014fcda012018-03-09 14:13:49 +000026 if (m_Data.m_Parameters.m_BiasEnabled)
27 {
telsoa01c577f2c2018-08-31 09:22:23 +010028 m_BiasTensor = std::make_unique<arm_compute::Tensor>();
29 BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo());
telsoa014fcda012018-03-09 14:13:49 +000030 }
31
32 arm_compute::PadStrideInfo padStrideInfo(m_Data.m_Parameters.m_StrideX,
33 m_Data.m_Parameters.m_StrideY,
34 m_Data.m_Parameters.m_PadLeft,
35 m_Data.m_Parameters.m_PadRight,
36 m_Data.m_Parameters.m_PadTop,
37 m_Data.m_Parameters.m_PadBottom,
38 arm_compute::DimensionRoundingType::FLOOR);
39
arovir019e53a352018-08-31 15:26:35 +010040 m_Data.ValidateInputsOutputs("NeonDepthwiseConvolutionFloatWorkload", 1, 1);
telsoa014fcda012018-03-09 14:13:49 +000041
42 arm_compute::ITensor& input = static_cast<INeonTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
43 arm_compute::ITensor& output = static_cast<INeonTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
44
45 bool use3x3Optimisation = weightInfo.GetShape()[3] == 3 && weightInfo.GetShape()[2] == 3;
46 if (use3x3Optimisation)
47 {
48 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer3x3>();
49 static_cast<arm_compute::NEDepthwiseConvolutionLayer3x3*>(
50 m_pDepthwiseConvolutionLayer.get())->configure(&input,
telsoa01c577f2c2018-08-31 09:22:23 +010051 m_KernelTensor.get(),
52 m_BiasTensor.get(),
telsoa014fcda012018-03-09 14:13:49 +000053 &output,
54 padStrideInfo);
55 }
56 else
57 {
58 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer>();
59 static_cast<arm_compute::NEDepthwiseConvolutionLayer*>(
60 m_pDepthwiseConvolutionLayer.get())->configure(&input,
telsoa01c577f2c2018-08-31 09:22:23 +010061 m_KernelTensor.get(),
62 m_BiasTensor.get(),
telsoa014fcda012018-03-09 14:13:49 +000063 &output,
64 padStrideInfo);
65 }
66
67 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
68
telsoa01c577f2c2018-08-31 09:22:23 +010069 InitializeArmComputeTensorDataForFloatTypes(*m_KernelTensor, m_Data.m_Weight);
telsoa014fcda012018-03-09 14:13:49 +000070
telsoa01c577f2c2018-08-31 09:22:23 +010071 if (m_BiasTensor)
telsoa014fcda012018-03-09 14:13:49 +000072 {
telsoa01c577f2c2018-08-31 09:22:23 +010073 InitializeArmComputeTensorDataForFloatTypes(*m_BiasTensor, m_Data.m_Bias);
telsoa014fcda012018-03-09 14:13:49 +000074 }
telsoa01c577f2c2018-08-31 09:22:23 +010075
76 m_pDepthwiseConvolutionLayer->prepare();
77 FreeUnusedTensors();
telsoa014fcda012018-03-09 14:13:49 +000078}
79
arovir019e53a352018-08-31 15:26:35 +010080void NeonDepthwiseConvolutionFloatWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000081{
arovir019e53a352018-08-31 15:26:35 +010082 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonDepthwiseConvolutionFloatWorkload_Execute");
telsoa014fcda012018-03-09 14:13:49 +000083 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
84
85 m_pDepthwiseConvolutionLayer->run();
86}
87
arovir019e53a352018-08-31 15:26:35 +010088void NeonDepthwiseConvolutionFloatWorkload::FreeUnusedTensors()
telsoa01c577f2c2018-08-31 09:22:23 +010089{
90 FreeTensorIfUnused(m_KernelTensor);
91 FreeTensorIfUnused(m_BiasTensor);
92}
93
telsoa014fcda012018-03-09 14:13:49 +000094} //namespace armnn