ArmNN
 22.08
ClFullyConnectedWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include <cl/ClTensorHandle.hpp>
11 #include <cl/ClLayerSupport.hpp>
12 
13 #include "ClWorkloadUtils.hpp"
14 
15 namespace armnn
16 {
17 using namespace armcomputetensorutils;
18 
20  const TensorInfo& output,
21  const TensorInfo& weights,
22  const Optional<TensorInfo>& biases,
23  const FullyConnectedDescriptor& descriptor,
24  const ActivationDescriptor* activationDescriptor)
25 {
26  const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input);
27  const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output);
28  arm_compute::TensorInfo aclWeights = BuildArmComputeTensorInfo(weights);
29  aclWeights.set_are_values_constant(weights.IsConstant());
30 
31  arm_compute::TensorInfo aclBiases;
32  arm_compute::TensorInfo* optionalAclBiases = nullptr;
33  if (descriptor.m_BiasEnabled)
34  {
35  ARMNN_ASSERT(biases.has_value());
36  // 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  }
42  aclBiases = BuildArmComputeTensorInfo(biases.value());
43  aclBiases.set_are_values_constant(biases.value().IsConstant());
44  optionalAclBiases = &aclBiases;
45  }
46 
47  const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo =
48  ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor, activationDescriptor);
49  return arm_compute::CLFullyConnectedLayer::validate(&aclInput,
50  &aclWeights,
51  optionalAclBiases,
52  &aclOutput,
53  fullyConnectedLayerInfo);
54 }
55 
57  const FullyConnectedQueueDescriptor& descriptor,
58  const WorkloadInfo& info,
59  std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager,
60  const arm_compute::CLCompileContext& clCompileContext)
61  : ClBaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info), m_FullyConnectedLayer(memoryManager)
62 {
63  // Add details for profiling output
64  WorkloadInfo detailsInfo;
65 
66  detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
67  detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
69  if (descriptor.m_Parameters.m_BiasEnabled)
70  {
72  }
73 
74  // Report Profiling Details
75  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClFullyConnectedWorkload_Construct",
76  descriptor.m_Parameters,
77  detailsInfo,
78  this->GetGuid());
79 
80  m_Data.ValidateInputsOutputs("ClFullyConnectedWorkload", descriptor.m_Parameters.GetNumInputs(),
81  1);
82 
83  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
84  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
85  arm_compute::ICLTensor& weights = PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
86 
87  arm_compute::ICLTensor* bias = nullptr;
89  {
90  bias = &PolymorphicDowncast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
91  }
92 
93  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
94 
95  arm_compute::FullyConnectedLayerInfo fc_info =
97  activationInfo);
98 
99  {
100  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClFullyConnectedWorkload_configure");
101  m_FullyConnectedLayer.configure(clCompileContext,
102  &input,
103  &weights,
104  bias,
105  &output,
106  fc_info);
107  }
108 }
109 
111 {
112  ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClFullyConnectedWorkload_Execute", this->GetGuid());
113  RunClFunction(m_FullyConnectedLayer, CHECK_LOCATION());
114 }
115 
116 } //namespace armnn
bool IsConstant() const
Definition: Tensor.cpp:509
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:61
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2021 ARM Limited and Contributors.
const ConstTensorHandle * m_Bias
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
const TensorInfo & GetTensorInfo() const
std::vector< TensorInfo > m_InputTensorInfos
bool has_value() const noexcept
Definition: Optional.hpp:53
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_BiasEnabled
Enable/disable bias.
arm_compute::FullyConnectedLayerInfo ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(const FullyConnectedDescriptor &fullyConnectedDesc, const ActivationDescriptor *activationDesc)
Status
enumeration
Definition: Types.hpp:42
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
std::vector< TensorInfo > m_OutputTensorInfos
arm_compute::Status ClFullyConnectedWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &weights, const Optional< TensorInfo > &biases, const FullyConnectedDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
const ConstTensorHandle * m_Weight
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:36
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
Optional< TensorInfo > m_BiasTensorInfo
uint32_t GetNumInputs() const
Get the number of inputs.
std::vector< ITensorHandle * > m_Outputs
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
Contains information about TensorInfos of a layer.
ClFullyConnectedWorkload(const FullyConnectedQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager, const arm_compute::CLCompileContext &clCompileContext)
std::vector< ITensorHandle * > m_Inputs
Optional< TensorInfo > m_WeightsTensorInfo