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 | { |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 22 | m_Weight = std::make_unique<ScopedTensorHandle>(*(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 | { |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 29 | m_Bias = std::make_unique<ScopedTensorHandle>(*(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 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 35 | void RefDepthwiseConvolution2dWorkload::Execute() const |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 36 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 37 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 40 | void RefDepthwiseConvolution2dWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 41 | { |
| 42 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 43 | } |
| 44 | |
| 45 | void RefDepthwiseConvolution2dWorkload::Execute(std::vector<ITensorHandle*> inputs, |
| 46 | std::vector<ITensorHandle*> outputs) const |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 47 | { |
| 48 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefDepthwiseConvolution2dWorkload_Execute"); |
| 49 | std::unique_ptr<Decoder<float>> pBiasDecoder{}; |
| 50 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 51 | std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map()); |
| 52 | std::unique_ptr<Encoder<float>> OutputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map()); |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 53 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 54 | const TensorShape& inputShape = GetTensorInfo(inputs[0]).GetShape(); |
| 55 | const TensorShape& outputShape = GetTensorInfo(outputs[0]).GetShape(); |
| 56 | |
| 57 | Convolve(inputShape, *inputDecoder, outputShape, *OutputEncoder, |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 58 | m_FilterShape, *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(), |
| 59 | m_Data.m_Parameters.m_DataLayout, m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft, |
| 60 | m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY, |
| 61 | m_Data.m_Parameters.m_DilationX, |
| 62 | m_Data.m_Parameters.m_DilationY, true); |
| 63 | } |
| 64 | |
| 65 | } //namespace armnn |