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 | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 23 | BuildArmComputeTensor(*m_KernelTensor, weightInfo, m_Data.m_Parameters.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 | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 28 | BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo(), m_Data.m_Parameters.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 | |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 44 | 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 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 48 | 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, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 54 | m_KernelTensor.get(), |
| 55 | m_BiasTensor.get(), |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 56 | &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, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 64 | m_KernelTensor.get(), |
| 65 | m_BiasTensor.get(), |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 66 | &output, |
| 67 | padStrideInfo); |
| 68 | } |
| 69 | |
| 70 | BOOST_ASSERT(m_pDepthwiseConvolutionLayer); |
| 71 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 72 | InitialiseArmComputeTensorData(*m_KernelTensor, m_Data.m_Weight->GetConstTensor<uint8_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 | if (m_BiasTensor) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 75 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 76 | InitialiseArmComputeTensorData(*m_BiasTensor, m_Data.m_Bias->GetConstTensor<int32_t>()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 77 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 78 | |
| 79 | m_pDepthwiseConvolutionLayer->prepare(); |
| 80 | FreeUnusedTensors(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void NeonDepthwiseConvolutionUint8Workload::Execute() const |
| 84 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 85 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonDepthwiseConvolutionUint8Workload_Execute"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 86 | BOOST_ASSERT(m_pDepthwiseConvolutionLayer); |
| 87 | |
| 88 | m_pDepthwiseConvolutionLayer->run(); |
| 89 | } |
| 90 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 91 | void NeonDepthwiseConvolutionUint8Workload::FreeUnusedTensors() |
| 92 | { |
| 93 | FreeTensorIfUnused(m_KernelTensor); |
| 94 | FreeTensorIfUnused(m_BiasTensor); |
| 95 | } |
| 96 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 97 | } //namespace armnn |