blob: 0e1efe0239f266b35007d6e94695a0677edc1a35 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Teresa Charlin588cbdf2022-01-19 15:55:37 +00002// Copyright © 2017 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 {
Matthew Bentham67d63902022-02-08 15:03:07 +000035 ARMNN_ASSERT(biases.has_value());
Cathal Corbett4452baf2022-05-13 09:55:59 +010036 // Same for bias as weights. We don't currently support non const.
37 if (!biases.value().IsConstant())
38 {
39 return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR,
40 "Arm NN ClFullyConnectedWorkload does not support non constant bias."};
41 }
Matthew Bentham67d63902022-02-08 15:03:07 +000042 aclBiases = BuildArmComputeTensorInfo(biases.value());
Cathal Corbett4452baf2022-05-13 09:55:59 +010043 aclBiases.set_are_values_constant(biases.value().IsConstant());
telsoa01c577f2c2018-08-31 09:22:23 +010044 optionalAclBiases = &aclBiases;
45 }
46
47 const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo =
Mike Kelly07810fc2020-11-12 10:58:48 +000048 ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor, activationDescriptor);
telsoa01c577f2c2018-08-31 09:22:23 +010049 return arm_compute::CLFullyConnectedLayer::validate(&aclInput,
50 &aclWeights,
51 optionalAclBiases,
52 &aclOutput,
53 fullyConnectedLayerInfo);
54}
55
Sadik Armagane9444752020-12-02 11:28:58 +000056ClFullyConnectedWorkload::ClFullyConnectedWorkload(
57 const FullyConnectedQueueDescriptor& descriptor,
58 const WorkloadInfo& info,
59 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager,
60 const arm_compute::CLCompileContext& clCompileContext)
Teresa Charlin588cbdf2022-01-19 15:55:37 +000061 : ClBaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info), m_FullyConnectedLayer(memoryManager)
telsoa014fcda012018-03-09 14:13:49 +000062{
Keith Davisbcd860a2021-08-05 14:20:33 +010063 // Add details for profiling output
64 WorkloadInfo detailsInfo;
65
66 detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
67 detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
68 detailsInfo.m_WeightsTensorInfo = armnn::Optional<armnn::TensorInfo>(descriptor.m_Weight->GetTensorInfo());
69 if (descriptor.m_Parameters.m_BiasEnabled)
70 {
71 detailsInfo.m_BiasTensorInfo = armnn::Optional<armnn::TensorInfo>(descriptor.m_Bias->GetTensorInfo());
72 }
73
74 // Report Profiling Details
75 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClFullyConnectedWorkload_Construct",
76 descriptor.m_Parameters,
77 detailsInfo,
78 this->GetGuid());
79
Cathal Corbett4452baf2022-05-13 09:55:59 +010080 m_Data.ValidateInputsOutputs("ClFullyConnectedWorkload", descriptor.m_Parameters.GetNumInputs(),
81 1);
telsoa014fcda012018-03-09 14:13:49 +000082
Keith Davisbcd860a2021-08-05 14:20:33 +010083 arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
telsoa014fcda012018-03-09 14:13:49 +000084 arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
Cathal Corbett4452baf2022-05-13 09:55:59 +010085 arm_compute::ICLTensor& weights = PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
86
87 arm_compute::ICLTensor* bias = nullptr;
88 if (m_Data.m_Parameters.m_BiasEnabled)
89 {
90 bias = &PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
91 }
telsoa01c577f2c2018-08-31 09:22:23 +010092
Mike Kelly07810fc2020-11-12 10:58:48 +000093 const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
94
95 arm_compute::FullyConnectedLayerInfo fc_info =
Cathal Corbett4452baf2022-05-13 09:55:59 +010096 ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor.m_Parameters,
97 activationInfo);
Mike Kelly07810fc2020-11-12 10:58:48 +000098
Kevin May9f6862d2021-10-22 15:42:28 +010099 {
100 ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClFullyConnectedWorkload_configure");
101 m_FullyConnectedLayer.configure(clCompileContext,
102 &input,
Cathal Corbett4452baf2022-05-13 09:55:59 +0100103 &weights,
104 bias,
Kevin May9f6862d2021-10-22 15:42:28 +0100105 &output,
106 fc_info);
107 }
telsoa014fcda012018-03-09 14:13:49 +0000108}
109
Matthew Benthamab8cdc12018-09-17 11:17:41 +0100110void ClFullyConnectedWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +0000111{
Keith Davisbcd860a2021-08-05 14:20:33 +0100112 ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClFullyConnectedWorkload_Execute", this->GetGuid());
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +0100113 RunClFunction(m_FullyConnectedLayer, CHECK_LOCATION());
telsoa01c577f2c2018-08-31 09:22:23 +0100114}
115
surmeh013537c2c2018-05-18 16:31:43 +0100116} //namespace armnn