blob: 6c6c2dfb6c27fd95a891ab5ddb6e1551c29efd7d [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 Rajcec6b652018-10-12 13:51:57 +010023 BuildArmComputeTensor(*m_KernelTensor, weightInfo, m_Data.m_Parameters.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 Rajcec6b652018-10-12 13:51:57 +010028 BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo(), m_Data.m_Parameters.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
Nikhil Rajcec6b652018-10-12 13:51:57 +010044 arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
45 input.info()->set_data_layout(aclDataLayout);
46 output.info()->set_data_layout(aclDataLayout);
47
telsoa014fcda012018-03-09 14:13:49 +000048 bool use3x3Optimisation = weightInfo.GetShape()[3] == 3 && weightInfo.GetShape()[2] == 3;
49 if (use3x3Optimisation)
50 {
51 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer3x3>();
52 static_cast<arm_compute::NEDepthwiseConvolutionLayer3x3*>(
53 m_pDepthwiseConvolutionLayer.get())->configure(&input,
telsoa01c577f2c2018-08-31 09:22:23 +010054 m_KernelTensor.get(),
55 m_BiasTensor.get(),
telsoa014fcda012018-03-09 14:13:49 +000056 &output,
57 padStrideInfo);
58 }
59 else
60 {
61 m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer>();
62 static_cast<arm_compute::NEDepthwiseConvolutionLayer*>(
63 m_pDepthwiseConvolutionLayer.get())->configure(&input,
telsoa01c577f2c2018-08-31 09:22:23 +010064 m_KernelTensor.get(),
65 m_BiasTensor.get(),
telsoa014fcda012018-03-09 14:13:49 +000066 &output,
67 padStrideInfo);
68 }
69
70 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
71
telsoa01c577f2c2018-08-31 09:22:23 +010072 InitialiseArmComputeTensorData(*m_KernelTensor, m_Data.m_Weight->GetConstTensor<uint8_t>());
telsoa014fcda012018-03-09 14:13:49 +000073
telsoa01c577f2c2018-08-31 09:22:23 +010074 if (m_BiasTensor)
telsoa014fcda012018-03-09 14:13:49 +000075 {
telsoa01c577f2c2018-08-31 09:22:23 +010076 InitialiseArmComputeTensorData(*m_BiasTensor, m_Data.m_Bias->GetConstTensor<int32_t>());
telsoa014fcda012018-03-09 14:13:49 +000077 }
telsoa01c577f2c2018-08-31 09:22:23 +010078
79 m_pDepthwiseConvolutionLayer->prepare();
80 FreeUnusedTensors();
telsoa014fcda012018-03-09 14:13:49 +000081}
82
83void NeonDepthwiseConvolutionUint8Workload::Execute() const
84{
telsoa01c577f2c2018-08-31 09:22:23 +010085 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonDepthwiseConvolutionUint8Workload_Execute");
telsoa014fcda012018-03-09 14:13:49 +000086 BOOST_ASSERT(m_pDepthwiseConvolutionLayer);
87
88 m_pDepthwiseConvolutionLayer->run();
89}
90
telsoa01c577f2c2018-08-31 09:22:23 +010091void NeonDepthwiseConvolutionUint8Workload::FreeUnusedTensors()
92{
93 FreeTensorIfUnused(m_KernelTensor);
94 FreeTensorIfUnused(m_BiasTensor);
95}
96
telsoa014fcda012018-03-09 14:13:49 +000097} //namespace armnn