telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
Colm Donelan | b4ef163 | 2024-02-01 15:00:43 +0000 | [diff] [blame^] | 2 | // Copyright © 2017-2018,2020-2024 Arm Ltd and Contributors. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
Matthew Bentham | ab8cdc1 | 2018-09-17 11:17:41 +0100 | [diff] [blame] | 6 | #include "ClFullyConnectedWorkload.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include <cl/ClTensorHandle.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 8 | #include <armnn/backends/TensorHandle.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | #include <aclCommon/ArmComputeUtils.hpp> |
| 11 | #include <cl/ClLayerSupport.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 13 | #include "ClWorkloadUtils.hpp" |
| 14 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | namespace armnn |
| 16 | { |
| 17 | using namespace armcomputetensorutils; |
| 18 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 19 | arm_compute::Status ClFullyConnectedWorkloadValidate(const TensorInfo& input, |
| 20 | const TensorInfo& output, |
| 21 | const TensorInfo& weights, |
Matthew Bentham | 67d6390 | 2022-02-08 15:03:07 +0000 | [diff] [blame] | 22 | const Optional<TensorInfo>& biases, |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 23 | const FullyConnectedDescriptor& descriptor, |
| 24 | const ActivationDescriptor* activationDescriptor) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 25 | { |
| 26 | const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input); |
| 27 | const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output); |
Cathal Corbett | 4452baf | 2022-05-13 09:55:59 +0100 | [diff] [blame] | 28 | arm_compute::TensorInfo aclWeights = BuildArmComputeTensorInfo(weights); |
| 29 | aclWeights.set_are_values_constant(weights.IsConstant()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 30 | |
| 31 | arm_compute::TensorInfo aclBiases; |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 32 | arm_compute::TensorInfo* optionalAclBiases = nullptr; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 33 | if (descriptor.m_BiasEnabled) |
| 34 | { |
Colm Donelan | b4ef163 | 2024-02-01 15:00:43 +0000 | [diff] [blame^] | 35 | ARMNN_THROW_INVALIDARG_MSG_IF_FALSE( |
| 36 | biases.has_value(), |
| 37 | "ClFullyConnectedWorkload: Bias was enabled in the descriptor but no value was supplied."); |
Matthew Bentham | 67d6390 | 2022-02-08 15:03:07 +0000 | [diff] [blame] | 38 | aclBiases = BuildArmComputeTensorInfo(biases.value()); |
Cathal Corbett | 4452baf | 2022-05-13 09:55:59 +0100 | [diff] [blame] | 39 | aclBiases.set_are_values_constant(biases.value().IsConstant()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 40 | optionalAclBiases = &aclBiases; |
| 41 | } |
| 42 | |
| 43 | const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo = |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 44 | ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor, activationDescriptor); |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 45 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 46 | return arm_compute::CLFullyConnectedLayer::validate(&aclInput, |
| 47 | &aclWeights, |
| 48 | optionalAclBiases, |
| 49 | &aclOutput, |
| 50 | fullyConnectedLayerInfo); |
| 51 | } |
| 52 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 53 | ClFullyConnectedWorkload::ClFullyConnectedWorkload( |
| 54 | const FullyConnectedQueueDescriptor& descriptor, |
| 55 | const WorkloadInfo& info, |
| 56 | std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager, |
| 57 | const arm_compute::CLCompileContext& clCompileContext) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 58 | : ClBaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info), m_FullyConnectedLayer(memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 59 | { |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 60 | m_Data.ValidateInputsOutputs("ClFullyConnectedWorkload", descriptor.m_Parameters.GetNumInputs(), 1); |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 61 | |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 62 | arm_compute::ICLTensor& input = PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 63 | arm_compute::ICLTensor& output = PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
Cathal Corbett | 4452baf | 2022-05-13 09:55:59 +0100 | [diff] [blame] | 64 | arm_compute::ICLTensor& weights = PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor(); |
| 65 | |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 66 | weights.info()->set_are_values_constant(info.m_InputTensorInfos[1].IsConstant()); |
| 67 | |
Cathal Corbett | 4452baf | 2022-05-13 09:55:59 +0100 | [diff] [blame] | 68 | arm_compute::ICLTensor* bias = nullptr; |
| 69 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 70 | { |
| 71 | bias = &PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor(); |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 72 | bias->info()->set_are_values_constant(info.m_InputTensorInfos[2].IsConstant()); |
Cathal Corbett | 4452baf | 2022-05-13 09:55:59 +0100 | [diff] [blame] | 73 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 74 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 75 | const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor); |
| 76 | |
| 77 | arm_compute::FullyConnectedLayerInfo fc_info = |
Cathal Corbett | 4452baf | 2022-05-13 09:55:59 +0100 | [diff] [blame] | 78 | ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor.m_Parameters, |
| 79 | activationInfo); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 80 | |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 81 | { |
Mike Kelly | 7cbe781 | 2023-07-25 17:37:33 +0100 | [diff] [blame] | 82 | ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClFullyConnectedWorkload_configure"); |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 83 | m_FullyConnectedLayer.configure(clCompileContext, |
| 84 | &input, |
Cathal Corbett | 4452baf | 2022-05-13 09:55:59 +0100 | [diff] [blame] | 85 | &weights, |
| 86 | bias, |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 87 | &output, |
| 88 | fc_info); |
| 89 | } |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 90 | |
| 91 | // Add details for profiling output |
| 92 | WorkloadInfo detailsInfo; |
| 93 | |
| 94 | detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos; |
| 95 | detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos; |
Teresa Charlin | ee1497c | 2023-03-30 13:56:34 +0100 | [diff] [blame] | 96 | |
| 97 | // Report Profiling Details |
| 98 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClFullyConnectedWorkload_Construct", |
| 99 | descriptor.m_Parameters, |
| 100 | detailsInfo, |
| 101 | this->GetGuid()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Matthew Bentham | ab8cdc1 | 2018-09-17 11:17:41 +0100 | [diff] [blame] | 104 | void ClFullyConnectedWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 105 | { |
Mike Kelly | 7cbe781 | 2023-07-25 17:37:33 +0100 | [diff] [blame] | 106 | ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClFullyConnectedWorkload_Execute"); |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 107 | RunClFunction(m_FullyConnectedLayer, CHECK_LOCATION()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 108 | } |
| 109 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 110 | } //namespace armnn |