Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 1 | // |
| 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 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | RefConvolution2dWorkload::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 Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 20 | const TensorInfo& rFilterInfo = m_Weight->GetTensorInfo(); |
| 21 | |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 22 | 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 Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 28 | const TensorInfo& biasInfo = m_Bias->GetTensorInfo(); |
| 29 | m_BiasDecoder = MakeDecoder<float>(biasInfo, m_Bias->Map(true)); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | void RefConvolution2dWorkload::PostAllocationConfigure() |
| 34 | { |
| 35 | const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]); |
| 36 | m_InputShape = inputInfo.GetShape(); |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 37 | m_InputDecoder = MakeDecoder<float>(inputInfo); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 38 | |
| 39 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 40 | m_OutputShape = outputInfo.GetShape(); |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 41 | m_OutputEncoder = MakeEncoder<float>(outputInfo); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void RefConvolution2dWorkload::Execute() const { |
| 45 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConvolution2dWorkload_Execute"); |
| 46 | |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 47 | m_InputDecoder->Reset(m_Data.m_Inputs[0]->Map()); |
| 48 | m_OutputEncoder->Reset(m_Data.m_Outputs[0]->Map()); |
| 49 | |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 50 | 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 |