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 | { |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 19 | m_Weight = std::make_unique<ScopedTensorHandle>(*(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 | { |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 27 | m_Bias = std::make_unique<ScopedTensorHandle>(*(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 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 33 | void RefConvolution2dWorkload::Execute() const |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 34 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 35 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 38 | void RefConvolution2dWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 39 | { |
| 40 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 41 | } |
| 42 | |
| 43 | void RefConvolution2dWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const { |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 44 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConvolution2dWorkload_Execute"); |
| 45 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 46 | 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 Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 48 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 49 | 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 Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 53 | *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 |