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 | { |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 15 | RefConvolution2dWorkload::RefConvolution2dWorkload(const Convolution2dQueueDescriptor& descriptor, |
| 16 | const WorkloadInfo& info) |
Finn Williams | 73c547d | 2022-02-15 20:47:34 +0000 | [diff] [blame] | 17 | : RefBaseWorkload<Convolution2dQueueDescriptor>(descriptor, info) |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 18 | { |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 19 | WorkloadInfo detailsInfo; |
| 20 | detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos; |
| 21 | detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos; |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 22 | |
| 23 | // Report Profiling Details |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 24 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("RefConvolution2dWorkload_Construct", |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 25 | descriptor.m_Parameters, |
| 26 | detailsInfo, |
| 27 | this->GetGuid()); |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 28 | } |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 29 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 30 | void RefConvolution2dWorkload::PostAllocationConfigure() |
| 31 | { |
| 32 | PostAllocationConfigure(m_Data.m_Inputs, m_Data.m_Outputs); |
| 33 | } |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 34 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 35 | void RefConvolution2dWorkload::PostAllocationConfigure(std::vector<ITensorHandle*> inputs, |
| 36 | std::vector<ITensorHandle*> outputs) |
| 37 | { |
| 38 | const TensorInfo& inputInfo = GetTensorInfo(inputs[0]); |
| 39 | ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); |
| 40 | m_InputShape = inputInfo.GetShape(); |
| 41 | |
| 42 | const TensorInfo& rFilterInfo = GetTensorInfo(inputs[1]); |
| 43 | ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 44 | m_FilterShape = rFilterInfo.GetShape(); |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 45 | m_FilterDecoder = MakeDecoder<float>(rFilterInfo); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 46 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 47 | if (m_Data.m_Parameters.m_BiasEnabled) |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 48 | { |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 49 | const TensorInfo& biasInfo = GetTensorInfo(inputs[2]); |
| 50 | m_BiasDecoder = MakeDecoder<float>(biasInfo); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 51 | } |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 52 | |
| 53 | const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); |
| 54 | m_OutputShape = outputInfo.GetShape(); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 57 | void RefConvolution2dWorkload::Execute() const |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 58 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 59 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 62 | void RefConvolution2dWorkload::ExecuteAsync(WorkingMemDescriptor& workingMemDescriptor) |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 63 | { |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 64 | PostAllocationConfigure(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 65 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 66 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 67 | } |
| 68 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 69 | void RefConvolution2dWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const |
| 70 | { |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 71 | ARMNN_SCOPED_PROFILING_EVENT_GUID(Compute::CpuRef, "RefConvolution2dWorkload_Execute", this->GetGuid()); |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 72 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 73 | std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map()); |
| 74 | 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] | 75 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 76 | m_FilterDecoder->Reset(inputs[1]->Map()); |
| 77 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 78 | { |
| 79 | m_BiasDecoder->Reset(inputs[2]->Map()); |
| 80 | } |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 81 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 82 | Convolve(m_InputShape, *inputDecoder, m_OutputShape, *outputEncoder, m_FilterShape, |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 83 | *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(), |
| 84 | m_Data.m_Parameters.m_DataLayout, m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft, |
| 85 | m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY, |
| 86 | m_Data.m_Parameters.m_DilationX, m_Data.m_Parameters.m_DilationY); |
| 87 | } |
| 88 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame^] | 89 | } //namespace armnn |