blob: 0b6606f3606347e0cb82909dee44ec1af85c15b0 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Colm Donelanb4ef1632024-02-01 15:00:43 +00002// Copyright © 2017-2018,2020-2024 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
Matthew Benthamab8cdc12018-09-17 11:17:41 +01006#include "ClFullyConnectedWorkload.hpp"
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00007#include <cl/ClTensorHandle.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +00008#include <armnn/backends/TensorHandle.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00009#include <aclCommon/ArmComputeTensorUtils.hpp>
10#include <aclCommon/ArmComputeUtils.hpp>
11#include <cl/ClLayerSupport.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Matthew Bentham14e46692018-09-20 15:35:30 +010013#include "ClWorkloadUtils.hpp"
14
telsoa014fcda012018-03-09 14:13:49 +000015namespace armnn
16{
17using namespace armcomputetensorutils;
18
telsoa01c577f2c2018-08-31 09:22:23 +010019arm_compute::Status ClFullyConnectedWorkloadValidate(const TensorInfo& input,
20 const TensorInfo& output,
21 const TensorInfo& weights,
Matthew Bentham67d63902022-02-08 15:03:07 +000022 const Optional<TensorInfo>& biases,
Mike Kelly07810fc2020-11-12 10:58:48 +000023 const FullyConnectedDescriptor& descriptor,
24 const ActivationDescriptor* activationDescriptor)
telsoa01c577f2c2018-08-31 09:22:23 +010025{
26 const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input);
27 const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output);
Cathal Corbett4452baf2022-05-13 09:55:59 +010028 arm_compute::TensorInfo aclWeights = BuildArmComputeTensorInfo(weights);
29 aclWeights.set_are_values_constant(weights.IsConstant());
telsoa01c577f2c2018-08-31 09:22:23 +010030
31 arm_compute::TensorInfo aclBiases;
Keith Davisbcd860a2021-08-05 14:20:33 +010032 arm_compute::TensorInfo* optionalAclBiases = nullptr;
telsoa01c577f2c2018-08-31 09:22:23 +010033 if (descriptor.m_BiasEnabled)
34 {
Colm Donelanb4ef1632024-02-01 15:00:43 +000035 ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(
36 biases.has_value(),
37 "ClFullyConnectedWorkload: Bias was enabled in the descriptor but no value was supplied.");
Matthew Bentham67d63902022-02-08 15:03:07 +000038 aclBiases = BuildArmComputeTensorInfo(biases.value());
Cathal Corbett4452baf2022-05-13 09:55:59 +010039 aclBiases.set_are_values_constant(biases.value().IsConstant());
telsoa01c577f2c2018-08-31 09:22:23 +010040 optionalAclBiases = &aclBiases;
41 }
42
43 const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo =
Mike Kelly07810fc2020-11-12 10:58:48 +000044 ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor, activationDescriptor);
Teresa Charlinee1497c2023-03-30 13:56:34 +010045
telsoa01c577f2c2018-08-31 09:22:23 +010046 return arm_compute::CLFullyConnectedLayer::validate(&aclInput,
47 &aclWeights,
48 optionalAclBiases,
49 &aclOutput,
50 fullyConnectedLayerInfo);
51}
52
Sadik Armagane9444752020-12-02 11:28:58 +000053ClFullyConnectedWorkload::ClFullyConnectedWorkload(
54 const FullyConnectedQueueDescriptor& descriptor,
55 const WorkloadInfo& info,
56 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager,
57 const arm_compute::CLCompileContext& clCompileContext)
Teresa Charlin588cbdf2022-01-19 15:55:37 +000058 : ClBaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info), m_FullyConnectedLayer(memoryManager)
telsoa014fcda012018-03-09 14:13:49 +000059{
Teresa Charlinee1497c2023-03-30 13:56:34 +010060 m_Data.ValidateInputsOutputs("ClFullyConnectedWorkload", descriptor.m_Parameters.GetNumInputs(), 1);
Keith Davisbcd860a2021-08-05 14:20:33 +010061
Teresa Charlinee1497c2023-03-30 13:56:34 +010062 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 Corbett4452baf2022-05-13 09:55:59 +010064 arm_compute::ICLTensor& weights = PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
65
Teresa Charlinee1497c2023-03-30 13:56:34 +010066 weights.info()->set_are_values_constant(info.m_InputTensorInfos[1].IsConstant());
67
Cathal Corbett4452baf2022-05-13 09:55:59 +010068 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 Charlinee1497c2023-03-30 13:56:34 +010072 bias->info()->set_are_values_constant(info.m_InputTensorInfos[2].IsConstant());
Cathal Corbett4452baf2022-05-13 09:55:59 +010073 }
telsoa01c577f2c2018-08-31 09:22:23 +010074
Mike Kelly07810fc2020-11-12 10:58:48 +000075 const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
76
77 arm_compute::FullyConnectedLayerInfo fc_info =
Cathal Corbett4452baf2022-05-13 09:55:59 +010078 ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor.m_Parameters,
79 activationInfo);
Mike Kelly07810fc2020-11-12 10:58:48 +000080
Kevin May9f6862d2021-10-22 15:42:28 +010081 {
Mike Kelly7cbe7812023-07-25 17:37:33 +010082 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClFullyConnectedWorkload_configure");
Kevin May9f6862d2021-10-22 15:42:28 +010083 m_FullyConnectedLayer.configure(clCompileContext,
84 &input,
Cathal Corbett4452baf2022-05-13 09:55:59 +010085 &weights,
86 bias,
Kevin May9f6862d2021-10-22 15:42:28 +010087 &output,
88 fc_info);
89 }
Teresa Charlinee1497c2023-03-30 13:56:34 +010090
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 Charlinee1497c2023-03-30 13:56:34 +010096
97 // Report Profiling Details
98 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClFullyConnectedWorkload_Construct",
99 descriptor.m_Parameters,
100 detailsInfo,
101 this->GetGuid());
telsoa014fcda012018-03-09 14:13:49 +0000102}
103
Matthew Benthamab8cdc12018-09-17 11:17:41 +0100104void ClFullyConnectedWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +0000105{
Mike Kelly7cbe7812023-07-25 17:37:33 +0100106 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClFullyConnectedWorkload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +0100107 RunClFunction(m_FullyConnectedLayer, CHECK_LOCATION());
telsoa01c577f2c2018-08-31 09:22:23 +0100108}
109
surmeh013537c2c2018-05-18 16:31:43 +0100110} //namespace armnn