2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
6 #include "NeonDepthwiseConvolutionUint8Workload.hpp"
7 #include "backends/NeonLayerSupport.hpp"
8 #include "backends/CpuTensorHandle.hpp"
9 #include "backends/ArmComputeTensorUtils.hpp"
14 using namespace armcomputetensorutils;
16 NeonDepthwiseConvolutionUint8Workload::NeonDepthwiseConvolutionUint8Workload(
17 const DepthwiseConvolution2dQueueDescriptor& descriptor,
18 const WorkloadInfo& info)
19 : Uint8Workload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info)
21 const TensorInfo& weightInfo = m_Data.m_Weight->GetTensorInfo();
23 m_KernelTensor = std::make_unique<arm_compute::Tensor>();
24 BuildArmComputeTensor(*m_KernelTensor, weightInfo);
26 if (m_Data.m_Parameters.m_BiasEnabled)
28 m_BiasTensor = std::make_unique<arm_compute::Tensor>();
29 BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo());
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);
40 m_Data.ValidateInputsOutputs("NeonDepthwiseConvolutionUint8Workload", 1, 1);
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();
45 bool use3x3Optimisation = weightInfo.GetShape()[3] == 3 && weightInfo.GetShape()[2] == 3;
46 if (use3x3Optimisation)
48 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer3x3>();
49 static_cast<arm_compute::NEDepthwiseConvolutionLayer3x3*>(
50 m_pDepthwiseConvolutionLayer.get())->configure(&input,
58 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer>();
59 static_cast<arm_compute::NEDepthwiseConvolutionLayer*>(
60 m_pDepthwiseConvolutionLayer.get())->configure(&input,
67 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
69 InitialiseArmComputeTensorData(*m_KernelTensor, m_Data.m_Weight->GetConstTensor<uint8_t>());
73 InitialiseArmComputeTensorData(*m_BiasTensor, m_Data.m_Bias->GetConstTensor<int32_t>());
76 m_pDepthwiseConvolutionLayer->prepare();
80 void NeonDepthwiseConvolutionUint8Workload::Execute() const
82 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonDepthwiseConvolutionUint8Workload_Execute");
83 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
85 m_pDepthwiseConvolutionLayer->run();
88 void NeonDepthwiseConvolutionUint8Workload::FreeUnusedTensors()
90 FreeTensorIfUnused(m_KernelTensor);
91 FreeTensorIfUnused(m_BiasTensor);