blob: d57040eaec2c78e598993b0ef3f8c4af3b0e7339 [file] [log] [blame]
Mike Kelly9b398322019-05-22 17:21:49 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "RefConvolution2dWorkload.hpp"
7
8#include "ConvImpl.hpp"
9#include "RefWorkloadUtils.hpp"
10
11#include "Profiling.hpp"
12
13namespace armnn
14{
15RefConvolution2dWorkload::RefConvolution2dWorkload(
Keith Davis554fa092021-07-20 11:25:22 +010016 const Convolution2dQueueDescriptor& descriptor, const WorkloadInfo& info)
Finn Williams73c547d2022-02-15 20:47:34 +000017 : RefBaseWorkload<Convolution2dQueueDescriptor>(descriptor, info)
Mike Kelly9b398322019-05-22 17:21:49 +010018{
Keith Davis554fa092021-07-20 11:25:22 +010019 WorkloadInfo detailsInfo;
20 detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
21 detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
22 detailsInfo.m_WeightsTensorInfo = armnn::Optional<armnn::TensorInfo>(descriptor.m_Weight->GetTensorInfo());
23 if (descriptor.m_Parameters.m_BiasEnabled)
24 {
25 detailsInfo.m_BiasTensorInfo = armnn::Optional<armnn::TensorInfo>(descriptor.m_Bias->GetTensorInfo());
26 }
27
28 // Report Profiling Details
Keith Davisf4874862021-08-09 16:49:18 +010029 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("RefConvolution2dWorkload_Construct",
Keith Davis5a64f222021-08-04 10:35:20 +010030 descriptor.m_Parameters,
31 detailsInfo,
32 this->GetGuid());
Keith Davis554fa092021-07-20 11:25:22 +010033
34 m_Weight = std::make_unique<ScopedTensorHandle>(*( descriptor.m_Weight ));
Matthew Bentham4cefc412019-06-18 16:14:34 +010035 const TensorInfo& rFilterInfo = m_Weight->GetTensorInfo();
36
Mike Kelly9b398322019-05-22 17:21:49 +010037 m_FilterShape = rFilterInfo.GetShape();
38 m_FilterDecoder = MakeDecoder<float>(rFilterInfo, m_Weight.get()->Map(true));
39
Keith Davis554fa092021-07-20 11:25:22 +010040 if ( descriptor.m_Parameters.m_BiasEnabled )
Mike Kelly9b398322019-05-22 17:21:49 +010041 {
Keith Davis554fa092021-07-20 11:25:22 +010042 m_Bias = std::make_unique<ScopedTensorHandle>(*( descriptor.m_Bias ));
Matthew Bentham4cefc412019-06-18 16:14:34 +010043 const TensorInfo& biasInfo = m_Bias->GetTensorInfo();
44 m_BiasDecoder = MakeDecoder<float>(biasInfo, m_Bias->Map(true));
Mike Kelly9b398322019-05-22 17:21:49 +010045 }
46}
47
Finn Williamsb8181f72021-04-07 10:23:21 +010048void RefConvolution2dWorkload::Execute() const
Mike Kelly9b398322019-05-22 17:21:49 +010049{
Finn Williamsb8181f72021-04-07 10:23:21 +010050 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
Mike Kelly9b398322019-05-22 17:21:49 +010051}
52
Keith Davis554fa092021-07-20 11:25:22 +010053void RefConvolution2dWorkload::ExecuteAsync(WorkingMemDescriptor& workingMemDescriptor)
Finn Williamsb8181f72021-04-07 10:23:21 +010054{
55 Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
56}
57
Keith Davis554fa092021-07-20 11:25:22 +010058void RefConvolution2dWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
59{
Keith Davis5a64f222021-08-04 10:35:20 +010060 ARMNN_SCOPED_PROFILING_EVENT_GUID(Compute::CpuRef, "RefConvolution2dWorkload_Execute", this->GetGuid());
Mike Kelly9b398322019-05-22 17:21:49 +010061
Finn Williamsb8181f72021-04-07 10:23:21 +010062 std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map());
63 std::unique_ptr<Encoder<float>> outputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map());
Matthew Benthamc394a6d2019-06-24 12:51:25 +010064
Finn Williamsb8181f72021-04-07 10:23:21 +010065 const TensorShape& inputShape = GetTensorInfo(inputs[0]).GetShape();
66 const TensorShape& outputShape = GetTensorInfo(outputs[0]).GetShape();
67
68 Convolve(inputShape, *inputDecoder, outputShape, *outputEncoder, m_FilterShape,
Mike Kelly9b398322019-05-22 17:21:49 +010069 *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(),
70 m_Data.m_Parameters.m_DataLayout, m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft,
71 m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY,
72 m_Data.m_Parameters.m_DilationX, m_Data.m_Parameters.m_DilationY);
73}
74
75} //namespace armnn