blob: 722b778eba08bf4e8facec0de54057b518f34fd5 [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
6#include "NeonDepthwiseConvolutionUint8Workload.hpp"
David Beck0dbe0ee2018-09-24 15:59:27 +01007#include <backends/neon/NeonLayerSupport.hpp>
David Beck711fa312018-09-24 10:46:38 +01008#include <backends/CpuTensorHandle.hpp>
9#include <backends/aclCommon/ArmComputeTensorUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000010
11namespace armnn
12{
13using namespace armcomputetensorutils;
14
15NeonDepthwiseConvolutionUint8Workload::NeonDepthwiseConvolutionUint8Workload(
16 const DepthwiseConvolution2dQueueDescriptor& descriptor,
17 const WorkloadInfo& info)
18 : Uint8Workload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info)
19{
20 const TensorInfo& weightInfo = m_Data.m_Weight->GetTensorInfo();
21
telsoa01c577f2c2018-08-31 09:22:23 +010022 m_KernelTensor = std::make_unique<arm_compute::Tensor>();
Nikhil Raja05c2102018-09-25 16:16:13 +010023 BuildArmComputeTensor(*m_KernelTensor, weightInfo, descriptor.m_DataLayout);
telsoa014fcda012018-03-09 14:13:49 +000024
telsoa014fcda012018-03-09 14:13:49 +000025 if (m_Data.m_Parameters.m_BiasEnabled)
26 {
telsoa01c577f2c2018-08-31 09:22:23 +010027 m_BiasTensor = std::make_unique<arm_compute::Tensor>();
Nikhil Raja05c2102018-09-25 16:16:13 +010028 BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo(), descriptor.m_DataLayout);
telsoa014fcda012018-03-09 14:13:49 +000029 }
30
31 arm_compute::PadStrideInfo padStrideInfo(m_Data.m_Parameters.m_StrideX,
32 m_Data.m_Parameters.m_StrideY,
33 m_Data.m_Parameters.m_PadLeft,
34 m_Data.m_Parameters.m_PadRight,
35 m_Data.m_Parameters.m_PadTop,
36 m_Data.m_Parameters.m_PadBottom,
37 arm_compute::DimensionRoundingType::FLOOR);
38
39 m_Data.ValidateInputsOutputs("NeonDepthwiseConvolutionUint8Workload", 1, 1);
40
41 arm_compute::ITensor& input = static_cast<INeonTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
42 arm_compute::ITensor& output = static_cast<INeonTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
43
44 bool use3x3Optimisation = weightInfo.GetShape()[3] == 3 && weightInfo.GetShape()[2] == 3;
45 if (use3x3Optimisation)
46 {
47 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer3x3>();
48 static_cast<arm_compute::NEDepthwiseConvolutionLayer3x3*>(
49 m_pDepthwiseConvolutionLayer.get())->configure(&input,
telsoa01c577f2c2018-08-31 09:22:23 +010050 m_KernelTensor.get(),
51 m_BiasTensor.get(),
telsoa014fcda012018-03-09 14:13:49 +000052 &output,
53 padStrideInfo);
54 }
55 else
56 {
57 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer>();
58 static_cast<arm_compute::NEDepthwiseConvolutionLayer*>(
59 m_pDepthwiseConvolutionLayer.get())->configure(&input,
telsoa01c577f2c2018-08-31 09:22:23 +010060 m_KernelTensor.get(),
61 m_BiasTensor.get(),
telsoa014fcda012018-03-09 14:13:49 +000062 &output,
63 padStrideInfo);
64 }
65
66 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
67
telsoa01c577f2c2018-08-31 09:22:23 +010068 InitialiseArmComputeTensorData(*m_KernelTensor, m_Data.m_Weight->GetConstTensor<uint8_t>());
telsoa014fcda012018-03-09 14:13:49 +000069
telsoa01c577f2c2018-08-31 09:22:23 +010070 if (m_BiasTensor)
telsoa014fcda012018-03-09 14:13:49 +000071 {
telsoa01c577f2c2018-08-31 09:22:23 +010072 InitialiseArmComputeTensorData(*m_BiasTensor, m_Data.m_Bias->GetConstTensor<int32_t>());
telsoa014fcda012018-03-09 14:13:49 +000073 }
telsoa01c577f2c2018-08-31 09:22:23 +010074
75 m_pDepthwiseConvolutionLayer->prepare();
76 FreeUnusedTensors();
telsoa014fcda012018-03-09 14:13:49 +000077}
78
79void NeonDepthwiseConvolutionUint8Workload::Execute() const
80{
telsoa01c577f2c2018-08-31 09:22:23 +010081 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonDepthwiseConvolutionUint8Workload_Execute");
telsoa014fcda012018-03-09 14:13:49 +000082 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
83
84 m_pDepthwiseConvolutionLayer->run();
85}
86
telsoa01c577f2c2018-08-31 09:22:23 +010087void NeonDepthwiseConvolutionUint8Workload::FreeUnusedTensors()
88{
89 FreeTensorIfUnused(m_KernelTensor);
90 FreeTensorIfUnused(m_BiasTensor);
91}
92
telsoa014fcda012018-03-09 14:13:49 +000093} //namespace armnn