blob: dad9936f1bc8bb28837bfbf989a1290b43636eb8 [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{
19 m_Weight = std::make_unique<ScopedCpuTensorHandle>(*(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 {
27 m_Bias = std::make_unique<ScopedCpuTensorHandle>(*(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
33void RefConvolution2dWorkload::PostAllocationConfigure()
34{
35 const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]);
36 m_InputShape = inputInfo.GetShape();
Matthew Benthamc394a6d2019-06-24 12:51:25 +010037 m_InputDecoder = MakeDecoder<float>(inputInfo);
Mike Kelly9b398322019-05-22 17:21:49 +010038
39 const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]);
40 m_OutputShape = outputInfo.GetShape();
Matthew Benthamc394a6d2019-06-24 12:51:25 +010041 m_OutputEncoder = MakeEncoder<float>(outputInfo);
Mike Kelly9b398322019-05-22 17:21:49 +010042}
43
44void RefConvolution2dWorkload::Execute() const {
45 ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConvolution2dWorkload_Execute");
46
Matthew Benthamc394a6d2019-06-24 12:51:25 +010047 m_InputDecoder->Reset(m_Data.m_Inputs[0]->Map());
48 m_OutputEncoder->Reset(m_Data.m_Outputs[0]->Map());
49
Mike Kelly9b398322019-05-22 17:21:49 +010050 Convolve(m_InputShape, *m_InputDecoder, m_OutputShape, *m_OutputEncoder, m_FilterShape,
51 *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(),
52 m_Data.m_Parameters.m_DataLayout, m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft,
53 m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY,
54 m_Data.m_Parameters.m_DilationX, m_Data.m_Parameters.m_DilationY);
55}
56
57} //namespace armnn