Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RefDepthwiseConvolution2dWorkload.hpp" |
| 7 | |
| 8 | #include "ConvImpl.hpp" |
| 9 | #include "RefWorkloadUtils.hpp" |
| 10 | #include "Decoders.hpp" |
| 11 | #include "Encoders.hpp" |
| 12 | #include "Profiling.hpp" |
| 13 | #include <ResolveType.hpp> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | RefDepthwiseConvolution2dWorkload::RefDepthwiseConvolution2dWorkload( |
| 19 | const DepthwiseConvolution2dQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 20 | : BaseWorkload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info) |
| 21 | { |
| 22 | m_Weight = std::make_unique<ScopedCpuTensorHandle>(*(descriptor.m_Weight)); |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 23 | const TensorInfo& rFilterInfo = m_Weight->GetTensorInfo(); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 24 | m_FilterShape = rFilterInfo.GetShape(); |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 25 | m_FilterDecoder = MakeDecoder<float>(rFilterInfo, m_Weight->Map(true)); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 26 | |
| 27 | if (descriptor.m_Parameters.m_BiasEnabled) |
| 28 | { |
| 29 | m_Bias = std::make_unique<ScopedCpuTensorHandle>(*(descriptor.m_Bias)); |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 30 | const TensorInfo& biasInfo = m_Bias->GetTensorInfo(); |
| 31 | m_BiasDecoder = MakeDecoder<float>(biasInfo, m_Bias->Map(true)); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
| 35 | void RefDepthwiseConvolution2dWorkload::PostAllocationConfigure() |
| 36 | { |
| 37 | const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]); |
| 38 | m_InputShape = inputInfo.GetShape(); |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 39 | m_InputDecoder = MakeDecoder<float>(inputInfo); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 40 | |
| 41 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 42 | m_OutputShape = outputInfo.GetShape(); |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 43 | m_OutputEncoder = MakeEncoder<float>(outputInfo); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void RefDepthwiseConvolution2dWorkload::Execute() const |
| 47 | { |
| 48 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefDepthwiseConvolution2dWorkload_Execute"); |
| 49 | std::unique_ptr<Decoder<float>> pBiasDecoder{}; |
| 50 | |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 51 | m_InputDecoder->Reset(m_Data.m_Inputs[0]->Map()); |
| 52 | m_OutputEncoder->Reset(m_Data.m_Outputs[0]->Map()); |
| 53 | |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 54 | Convolve(m_InputShape, *m_InputDecoder, m_OutputShape, *m_OutputEncoder, |
| 55 | m_FilterShape, *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(), |
| 56 | m_Data.m_Parameters.m_DataLayout, m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft, |
| 57 | m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY, |
| 58 | m_Data.m_Parameters.m_DilationX, |
| 59 | m_Data.m_Parameters.m_DilationY, true); |
| 60 | } |
| 61 | |
| 62 | } //namespace armnn |