blob: 5ae1af896754e1e4ee5ffb72b57010b955470f1d [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(
16 const Convolution2dQueueDescriptor& descriptor, const WorkloadInfo& info)
17 : BaseWorkload<Convolution2dQueueDescriptor>(descriptor, info)
18{
James Conroy1f58f032021-04-27 17:13:27 +010019 m_Weight = std::make_unique<ScopedTensorHandle>(*(descriptor.m_Weight));
Matthew Bentham4cefc412019-06-18 16:14:34 +010020 const TensorInfo& rFilterInfo = m_Weight->GetTensorInfo();
21
Mike Kelly9b398322019-05-22 17:21:49 +010022 m_FilterShape = rFilterInfo.GetShape();
23 m_FilterDecoder = MakeDecoder<float>(rFilterInfo, m_Weight.get()->Map(true));
24
25 if (descriptor.m_Parameters.m_BiasEnabled)
26 {
James Conroy1f58f032021-04-27 17:13:27 +010027 m_Bias = std::make_unique<ScopedTensorHandle>(*(descriptor.m_Bias));
Matthew Bentham4cefc412019-06-18 16:14:34 +010028 const TensorInfo& biasInfo = m_Bias->GetTensorInfo();
29 m_BiasDecoder = MakeDecoder<float>(biasInfo, m_Bias->Map(true));
Mike Kelly9b398322019-05-22 17:21:49 +010030 }
31}
32
Finn Williamsb8181f72021-04-07 10:23:21 +010033void RefConvolution2dWorkload::Execute() const
Mike Kelly9b398322019-05-22 17:21:49 +010034{
Finn Williamsb8181f72021-04-07 10:23:21 +010035 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
Mike Kelly9b398322019-05-22 17:21:49 +010036}
37
Finn Williamsb8181f72021-04-07 10:23:21 +010038void RefConvolution2dWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor)
39{
40 Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
41}
42
43void RefConvolution2dWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const {
Mike Kelly9b398322019-05-22 17:21:49 +010044 ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConvolution2dWorkload_Execute");
45
Finn Williamsb8181f72021-04-07 10:23:21 +010046 std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map());
47 std::unique_ptr<Encoder<float>> outputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map());
Matthew Benthamc394a6d2019-06-24 12:51:25 +010048
Finn Williamsb8181f72021-04-07 10:23:21 +010049 const TensorShape& inputShape = GetTensorInfo(inputs[0]).GetShape();
50 const TensorShape& outputShape = GetTensorInfo(outputs[0]).GetShape();
51
52 Convolve(inputShape, *inputDecoder, outputShape, *outputEncoder, m_FilterShape,
Mike Kelly9b398322019-05-22 17:21:49 +010053 *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(),
54 m_Data.m_Parameters.m_DataLayout, m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft,
55 m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY,
56 m_Data.m_Parameters.m_DilationX, m_Data.m_Parameters.m_DilationY);
57}
58
59} //namespace armnn