Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 1 | // |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 2 | // Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved. |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClConvolution2dWorkload.hpp" |
| 7 | |
| 8 | #include "ClWorkloadUtils.hpp" |
| 9 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <cl/ClLayerSupport.hpp> |
| 11 | #include <cl/ClTensorHandle.hpp> |
| 12 | #include <cl/ClLayerSupport.hpp> |
| 13 | #include <aclCommon/ArmComputeUtils.hpp> |
| 14 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 15 | #include <armnn/backends/TensorHandle.hpp> |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 16 | |
| 17 | #include <arm_compute/runtime/CL/functions/CLConvolutionLayer.h> |
| 18 | |
| 19 | namespace armnn |
| 20 | { |
| 21 | using namespace armcomputetensorutils; |
| 22 | |
| 23 | arm_compute::Status ClConvolution2dWorkloadValidate(const TensorInfo& input, |
| 24 | const TensorInfo& output, |
| 25 | const Convolution2dDescriptor& descriptor, |
| 26 | const TensorInfo& weights, |
Sadik Armagan | 045f6be | 2020-09-10 13:37:32 +0100 | [diff] [blame] | 27 | const Optional<TensorInfo>& biases, |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 28 | bool isFastMathEnabled, |
| 29 | const ActivationDescriptor* activationDescriptor) |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 30 | { |
| 31 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 32 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 33 | arm_compute::TensorInfo aclWeightsInfo = BuildArmComputeTensorInfo(weights, descriptor.m_DataLayout); |
| 34 | aclWeightsInfo.set_are_values_constant(weights.IsConstant()); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 35 | |
Jan Eilers | 4b961d3 | 2019-07-11 09:19:35 +0100 | [diff] [blame] | 36 | const arm_compute::Size2D aclDilationInfo = BuildArmComputeSize2D(descriptor.m_DilationX, |
| 37 | descriptor.m_DilationY); |
| 38 | |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 39 | arm_compute::TensorInfo aclBiasesInfo; |
| 40 | arm_compute::TensorInfo *optionalAclBiasesInfo = nullptr; |
| 41 | |
| 42 | if (descriptor.m_BiasEnabled) |
| 43 | { |
Kevin May | 8eece0a | 2023-06-06 17:19:06 +0100 | [diff] [blame^] | 44 | if (!biases.has_value()) |
TeresaARM | acedd85 | 2023-05-11 15:16:39 +0000 | [diff] [blame] | 45 | { |
| 46 | return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, |
Kevin May | 8eece0a | 2023-06-06 17:19:06 +0100 | [diff] [blame^] | 47 | "ArmNN ClConvolution2dWorkload has empty bias value."}; |
TeresaARM | acedd85 | 2023-05-11 15:16:39 +0000 | [diff] [blame] | 48 | } |
David Beck | 5eec11d | 2018-10-04 15:43:17 +0100 | [diff] [blame] | 49 | aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout); |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 50 | aclBiasesInfo.set_are_values_constant(biases.value().IsConstant()); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 51 | optionalAclBiasesInfo = &aclBiasesInfo; |
| 52 | } |
| 53 | |
| 54 | arm_compute::PadStrideInfo layerInfo = BuildArmComputePadStrideInfo(descriptor); |
| 55 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 56 | const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo( |
| 57 | activationDescriptor); |
| 58 | |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 59 | return arm_compute::CLConvolutionLayer::validate(&aclInputInfo, |
| 60 | &aclWeightsInfo, |
| 61 | optionalAclBiasesInfo, |
| 62 | &aclOutputInfo, |
Jan Eilers | 4b961d3 | 2019-07-11 09:19:35 +0100 | [diff] [blame] | 63 | layerInfo, |
| 64 | arm_compute::WeightsInfo(), |
Sadik Armagan | 045f6be | 2020-09-10 13:37:32 +0100 | [diff] [blame] | 65 | aclDilationInfo, |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 66 | activationInfo, |
Sadik Armagan | 045f6be | 2020-09-10 13:37:32 +0100 | [diff] [blame] | 67 | isFastMathEnabled); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | ClConvolution2dWorkload::ClConvolution2dWorkload(const Convolution2dQueueDescriptor& descriptor, |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 71 | const WorkloadInfo& info, |
| 72 | std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager, |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 73 | const arm_compute::CLCompileContext& clCompileContext, |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 74 | const bool isFastMathEnabled) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 75 | : ClBaseWorkload<Convolution2dQueueDescriptor>(descriptor, info) |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 76 | , m_ConvolutionLayer(memoryManager) |
| 77 | { |
Kevin May | 4692e11 | 2021-10-18 14:41:50 +0100 | [diff] [blame] | 78 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClConvolution2dWorkload"); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 79 | |
Jan Eilers | 4b961d3 | 2019-07-11 09:19:35 +0100 | [diff] [blame] | 80 | const arm_compute::Size2D aclDilationInfo = BuildArmComputeSize2D(m_Data.m_Parameters.m_DilationX, |
| 81 | m_Data.m_Parameters.m_DilationY); |
| 82 | |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 83 | uint32_t numInputs = m_Data.m_Parameters.m_BiasEnabled ? 3: 2; |
| 84 | m_Data.ValidateInputsOutputs("ClConvolution2dWorkload", numInputs, 1); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 85 | |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 86 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 87 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 88 | arm_compute::ICLTensor& weights = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor(); |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 89 | weights.info()->set_are_values_constant(info.m_InputTensorInfos[1].IsConstant()); |
| 90 | |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 91 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 92 | { |
Mike Kelly | ec67a0f | 2022-11-25 13:55:24 +0000 | [diff] [blame] | 93 | arm_compute::ICLTensor& bias = static_cast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor(); |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 94 | bias.info()->set_are_values_constant(info.m_InputTensorInfos[2].IsConstant()); |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 95 | |
Mike Kelly | ec67a0f | 2022-11-25 13:55:24 +0000 | [diff] [blame] | 96 | m_BiasProxy = std::make_unique<ICLTensorProxy>(&bias); |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 97 | } |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 98 | |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 99 | // Create Proxy tensor and set the initial tensor handle to it |
| 100 | m_InputProxy = std::make_unique<ICLTensorProxy>(&input); |
| 101 | m_OutputProxy = std::make_unique<ICLTensorProxy>(&output); |
Mike Kelly | ec67a0f | 2022-11-25 13:55:24 +0000 | [diff] [blame] | 102 | m_WeightsProxy = std::make_unique<ICLTensorProxy>(&weights); |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 103 | |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 104 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 105 | input.info()->set_data_layout(aclDataLayout); |
| 106 | output.info()->set_data_layout(aclDataLayout); |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 107 | weights.info()->set_data_layout(aclDataLayout); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 108 | |
Aron Virginas-Tar | 6f3785d | 2019-07-22 15:30:22 +0100 | [diff] [blame] | 109 | arm_compute::PadStrideInfo padStrideInfo = BuildArmComputePadStrideInfo(m_Data.m_Parameters); |
| 110 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 111 | const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor); |
| 112 | |
Kevin May | 4692e11 | 2021-10-18 14:41:50 +0100 | [diff] [blame] | 113 | { |
| 114 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClConvolution2dWorkload_configure"); |
| 115 | m_ConvolutionLayer.configure(clCompileContext, |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 116 | m_InputProxy.get(), |
Mike Kelly | ec67a0f | 2022-11-25 13:55:24 +0000 | [diff] [blame] | 117 | m_WeightsProxy.get(), |
| 118 | m_BiasProxy.get(), |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 119 | m_OutputProxy.get(), |
Kevin May | 4692e11 | 2021-10-18 14:41:50 +0100 | [diff] [blame] | 120 | padStrideInfo, |
| 121 | arm_compute::WeightsInfo(), |
| 122 | aclDilationInfo, |
| 123 | activationInfo, |
| 124 | isFastMathEnabled); |
| 125 | } |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 126 | |
| 127 | m_ConvolutionMethod = |
| 128 | m_ConvolutionLayer.get_convolution_method(input.info(), |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 129 | weights.info(), |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 130 | output.info(), |
| 131 | padStrideInfo, |
| 132 | arm_compute::WeightsInfo(), |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 133 | activationInfo, |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 134 | arm_compute::CLScheduler::get().target(), |
| 135 | aclDilationInfo, |
| 136 | isFastMathEnabled); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 137 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 138 | // Add details for profiling output |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 139 | WorkloadInfo detailsInfo; |
| 140 | |
| 141 | detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos; |
| 142 | detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos; |
Mike Kelly | ec67a0f | 2022-11-25 13:55:24 +0000 | [diff] [blame] | 143 | detailsInfo.m_WeightsTensorInfo = armnn::Optional<armnn::TensorInfo>(info.m_InputTensorInfos[1]); |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 144 | detailsInfo.m_ConvolutionMethod = armnn::Optional<std::string>(GetConvolutionMethodString(m_ConvolutionMethod)); |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 145 | if (descriptor.m_Parameters.m_BiasEnabled) |
| 146 | { |
Mike Kelly | ec67a0f | 2022-11-25 13:55:24 +0000 | [diff] [blame] | 147 | detailsInfo.m_BiasTensorInfo = armnn::Optional<armnn::TensorInfo>(info.m_InputTensorInfos[2]); |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // Report Profiling Details |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 151 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClConvolution2dWorkload_Construct", |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 152 | descriptor.m_Parameters, |
| 153 | detailsInfo, |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 154 | GetGuid()); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void ClConvolution2dWorkload::Execute() const |
| 158 | { |
Cathal Corbett | 8bd5360 | 2022-05-12 15:54:58 +0100 | [diff] [blame] | 159 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConvolution2dWorkload_Execute", GetGuid()); |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 160 | RunClFunction(m_ConvolutionLayer, CHECK_LOCATION()); |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 163 | arm_compute::ConvolutionMethod ClConvolution2dWorkload::GetConvolutionMethod() const |
| 164 | { |
| 165 | return m_ConvolutionMethod; |
| 166 | } |
| 167 | |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 168 | void ClConvolution2dWorkload::Reconfigure() |
| 169 | { |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 170 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 171 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
David Monahan | ec81999 | 2022-02-10 14:47:13 +0000 | [diff] [blame] | 172 | |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 173 | m_InputProxy->set(&input); |
| 174 | m_OutputProxy->set(&output); |
| 175 | } |
| 176 | |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 177 | } //namespace armnn |