telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include "NeonDepthwiseConvolutionUint8Workload.hpp" |
David Beck | 0dbe0ee | 2018-09-24 15:59:27 +0100 | [diff] [blame] | 7 | #include <backends/neon/NeonLayerSupport.hpp> |
David Beck | 711fa31 | 2018-09-24 10:46:38 +0100 | [diff] [blame] | 8 | #include <backends/CpuTensorHandle.hpp> |
| 9 | #include <backends/aclCommon/ArmComputeTensorUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | using namespace armcomputetensorutils; |
| 14 | |
| 15 | NeonDepthwiseConvolutionUint8Workload::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 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 22 | m_KernelTensor = std::make_unique<arm_compute::Tensor>(); |
Nikhil Raj | a05c210 | 2018-09-25 16:16:13 +0100 | [diff] [blame] | 23 | BuildArmComputeTensor(*m_KernelTensor, weightInfo, descriptor.m_DataLayout); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 26 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | m_BiasTensor = std::make_unique<arm_compute::Tensor>(); |
Nikhil Raj | a05c210 | 2018-09-25 16:16:13 +0100 | [diff] [blame] | 28 | BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo(), descriptor.m_DataLayout); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 29 | } |
| 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, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 50 | m_KernelTensor.get(), |
| 51 | m_BiasTensor.get(), |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 52 | &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, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 60 | m_KernelTensor.get(), |
| 61 | m_BiasTensor.get(), |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 62 | &output, |
| 63 | padStrideInfo); |
| 64 | } |
| 65 | |
| 66 | BOOST_ASSERT(m_pDepthwiseConvolutionLayer); |
| 67 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 68 | InitialiseArmComputeTensorData(*m_KernelTensor, m_Data.m_Weight->GetConstTensor<uint8_t>()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 69 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 70 | if (m_BiasTensor) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 71 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 72 | InitialiseArmComputeTensorData(*m_BiasTensor, m_Data.m_Bias->GetConstTensor<int32_t>()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 73 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 74 | |
| 75 | m_pDepthwiseConvolutionLayer->prepare(); |
| 76 | FreeUnusedTensors(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void NeonDepthwiseConvolutionUint8Workload::Execute() const |
| 80 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 81 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonDepthwiseConvolutionUint8Workload_Execute"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 82 | BOOST_ASSERT(m_pDepthwiseConvolutionLayer); |
| 83 | |
| 84 | m_pDepthwiseConvolutionLayer->run(); |
| 85 | } |
| 86 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 87 | void NeonDepthwiseConvolutionUint8Workload::FreeUnusedTensors() |
| 88 | { |
| 89 | FreeTensorIfUnused(m_KernelTensor); |
| 90 | FreeTensorIfUnused(m_BiasTensor); |
| 91 | } |
| 92 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | } //namespace armnn |