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 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 6 | #include "NeonDepthwiseConvolutionFloatWorkload.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 7 | #include "backends/NeonLayerSupport.hpp" |
| 8 | #include "backends/CpuTensorHandle.hpp" |
| 9 | #include "backends/ArmComputeTensorUtils.hpp" |
| 10 | |
| 11 | |
| 12 | namespace armnn |
| 13 | { |
| 14 | using namespace armcomputetensorutils; |
| 15 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 16 | NeonDepthwiseConvolutionFloatWorkload::NeonDepthwiseConvolutionFloatWorkload( |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | const DepthwiseConvolution2dQueueDescriptor& descriptor, |
| 18 | const WorkloadInfo& info) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 19 | : FloatWorkload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | { |
| 21 | const TensorInfo& weightInfo = m_Data.m_Weight->GetTensorInfo(); |
| 22 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 23 | m_KernelTensor = std::make_unique<arm_compute::Tensor>(); |
| 24 | BuildArmComputeTensor(*m_KernelTensor, weightInfo); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 26 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 27 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 28 | m_BiasTensor = std::make_unique<arm_compute::Tensor>(); |
| 29 | BuildArmComputeTensor(*m_BiasTensor, m_Data.m_Bias->GetTensorInfo()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 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); |
| 39 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 40 | m_Data.ValidateInputsOutputs("NeonDepthwiseConvolutionFloatWorkload", 1, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | |
| 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(); |
| 44 | |
| 45 | bool use3x3Optimisation = weightInfo.GetShape()[3] == 3 && weightInfo.GetShape()[2] == 3; |
| 46 | if (use3x3Optimisation) |
| 47 | { |
| 48 | m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer3x3>(); |
| 49 | static_cast<arm_compute::NEDepthwiseConvolutionLayer3x3*>( |
| 50 | m_pDepthwiseConvolutionLayer.get())->configure(&input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 51 | m_KernelTensor.get(), |
| 52 | m_BiasTensor.get(), |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | &output, |
| 54 | padStrideInfo); |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | m_pDepthwiseConvolutionLayer = std::make_unique<arm_compute::NEDepthwiseConvolutionLayer>(); |
| 59 | static_cast<arm_compute::NEDepthwiseConvolutionLayer*>( |
| 60 | m_pDepthwiseConvolutionLayer.get())->configure(&input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 61 | m_KernelTensor.get(), |
| 62 | m_BiasTensor.get(), |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 63 | &output, |
| 64 | padStrideInfo); |
| 65 | } |
| 66 | |
| 67 | BOOST_ASSERT(m_pDepthwiseConvolutionLayer); |
| 68 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 69 | InitializeArmComputeTensorDataForFloatTypes(*m_KernelTensor, m_Data.m_Weight); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 70 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 71 | if (m_BiasTensor) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 72 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 73 | InitializeArmComputeTensorDataForFloatTypes(*m_BiasTensor, m_Data.m_Bias); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 74 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 75 | |
| 76 | m_pDepthwiseConvolutionLayer->prepare(); |
| 77 | FreeUnusedTensors(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 78 | } |
| 79 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 80 | void NeonDepthwiseConvolutionFloatWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 81 | { |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 82 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonDepthwiseConvolutionFloatWorkload_Execute"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 83 | BOOST_ASSERT(m_pDepthwiseConvolutionLayer); |
| 84 | |
| 85 | m_pDepthwiseConvolutionLayer->run(); |
| 86 | } |
| 87 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 88 | void NeonDepthwiseConvolutionFloatWorkload::FreeUnusedTensors() |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 89 | { |
| 90 | FreeTensorIfUnused(m_KernelTensor); |
| 91 | FreeTensorIfUnused(m_BiasTensor); |
| 92 | } |
| 93 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 94 | } //namespace armnn |