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) |
Finn Williams | 73c547d | 2022-02-15 20:47:34 +0000 | [diff] [blame] | 20 | : RefBaseWorkload<DepthwiseConvolution2dQueueDescriptor>(descriptor, info) |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 21 | { |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame^] | 22 | WorkloadInfo detailsInfo; |
| 23 | detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos; |
| 24 | detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos; |
| 25 | detailsInfo.m_WeightsTensorInfo = armnn::Optional<armnn::TensorInfo>(info.m_InputTensorInfos[1]); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 26 | |
| 27 | if (descriptor.m_Parameters.m_BiasEnabled) |
| 28 | { |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame^] | 29 | detailsInfo.m_BiasTensorInfo = armnn::Optional<armnn::TensorInfo>(info.m_InputTensorInfos[2]); |
| 30 | } |
| 31 | |
| 32 | // Report Profiling Details |
| 33 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("RefDepthwiseConvolution2dWorkload_Construct", |
| 34 | descriptor.m_Parameters, |
| 35 | detailsInfo, |
| 36 | this->GetGuid()); |
| 37 | } |
| 38 | |
| 39 | void RefDepthwiseConvolution2dWorkload::PostAllocationConfigure() |
| 40 | { |
| 41 | PostAllocationConfigure(m_Data.m_Inputs, m_Data.m_Outputs); |
| 42 | } |
| 43 | |
| 44 | void RefDepthwiseConvolution2dWorkload::PostAllocationConfigure(std::vector<ITensorHandle*> inputs, |
| 45 | std::vector<ITensorHandle*> outputs) |
| 46 | { |
| 47 | IgnoreUnused(outputs); |
| 48 | |
| 49 | const TensorInfo& rFilterInfo = GetTensorInfo(inputs[1]); |
| 50 | m_FilterShape = rFilterInfo.GetShape(); |
| 51 | m_FilterDecoder = MakeDecoder<float>(rFilterInfo); |
| 52 | |
| 53 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 54 | { |
| 55 | const TensorInfo& biasInfo = GetTensorInfo(inputs[2]); |
| 56 | m_BiasDecoder = MakeDecoder<float>(biasInfo); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 60 | void RefDepthwiseConvolution2dWorkload::Execute() const |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 61 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 62 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 65 | void RefDepthwiseConvolution2dWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 66 | { |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame^] | 67 | PostAllocationConfigure(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 68 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 69 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 70 | } |
| 71 | |
| 72 | void RefDepthwiseConvolution2dWorkload::Execute(std::vector<ITensorHandle*> inputs, |
| 73 | std::vector<ITensorHandle*> outputs) const |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 74 | { |
| 75 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefDepthwiseConvolution2dWorkload_Execute"); |
| 76 | std::unique_ptr<Decoder<float>> pBiasDecoder{}; |
| 77 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 78 | std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map()); |
| 79 | 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] | 80 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 81 | const TensorShape& inputShape = GetTensorInfo(inputs[0]).GetShape(); |
| 82 | const TensorShape& outputShape = GetTensorInfo(outputs[0]).GetShape(); |
| 83 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame^] | 84 | m_FilterDecoder->Reset(inputs[1]->Map()); |
| 85 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 86 | { |
| 87 | m_BiasDecoder->Reset(inputs[2]->Map()); |
| 88 | } |
| 89 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 90 | Convolve(inputShape, *inputDecoder, outputShape, *OutputEncoder, |
Ruomei Yan | 495852f | 2019-05-23 11:37:33 +0100 | [diff] [blame] | 91 | m_FilterShape, *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(), |
| 92 | m_Data.m_Parameters.m_DataLayout, m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft, |
| 93 | m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY, |
| 94 | m_Data.m_Parameters.m_DilationX, |
| 95 | m_Data.m_Parameters.m_DilationY, true); |
| 96 | } |
| 97 | |
| 98 | } //namespace armnn |