ArmNN
 21.05
ClFullyConnectedWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. 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 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  const arm_compute::TensorInfo aclWeights = BuildArmComputeTensorInfo(weights);
29 
30  arm_compute::TensorInfo aclBiases;
31  arm_compute::TensorInfo *optionalAclBiases = nullptr;
32  if (descriptor.m_BiasEnabled)
33  {
34  aclBiases = BuildArmComputeTensorInfo(biases);
35  optionalAclBiases = &aclBiases;
36  }
37 
38  const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo =
39  ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor, activationDescriptor);
40 
41  return arm_compute::CLFullyConnectedLayer::validate(&aclInput,
42  &aclWeights,
43  optionalAclBiases,
44  &aclOutput,
45  fullyConnectedLayerInfo);
46 }
47 
49  const FullyConnectedQueueDescriptor& descriptor,
50  const WorkloadInfo& info,
51  std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager,
52  const arm_compute::CLCompileContext& clCompileContext)
53  : BaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info)
54  , m_FullyConnectedLayer(memoryManager)
55 {
56  m_WeightsTensor = std::make_unique<arm_compute::CLTensor>();
57  BuildArmComputeTensor(*m_WeightsTensor, m_Data.m_Weight->GetTensorInfo());
58 
60  {
61  m_BiasesTensor = std::make_unique<arm_compute::CLTensor>();
62  BuildArmComputeTensor(*m_BiasesTensor, m_Data.m_Bias->GetTensorInfo());
63  }
64 
65  m_Data.ValidateInputsOutputs("ClFullyConnectedWorkload", 1, 1);
66 
67  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
68  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
69 
70  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
71 
72  arm_compute::FullyConnectedLayerInfo fc_info =
74 
75  m_FullyConnectedLayer.configure(clCompileContext,
76  &input,
77  m_WeightsTensor.get(),
78  m_BiasesTensor.get(),
79  &output,
80  fc_info);
81 
83 
84  if (m_BiasesTensor)
85  {
87  }
88 
89  // Force Compute Library to perform the necessary copying and reshaping, after which
90  // delete all the input tensors that will no longer be needed
91  m_FullyConnectedLayer.prepare();
92  FreeUnusedTensors();
93 }
94 
96 {
97  ARMNN_SCOPED_PROFILING_EVENT_CL("ClFullyConnectedWorkload_Execute");
98  RunClFunction(m_FullyConnectedLayer, CHECK_LOCATION());
99 }
100 
101 void ClFullyConnectedWorkload::FreeUnusedTensors()
102 {
103  FreeTensorIfUnused(m_WeightsTensor);
104  FreeTensorIfUnused(m_BiasesTensor);
105 }
106 
107 } //namespace armnn
arm_compute::Status ClFullyConnectedWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &weights, const TensorInfo &biases, const FullyConnectedDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
#define ARMNN_SCOPED_PROFILING_EVENT_CL(name)
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2021 ARM Limited and Contributors.
ClFullyConnectedWorkload(const armnn::FullyConnectedQueueDescriptor &descriptor, const armnn::WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager, const arm_compute::CLCompileContext &clCompileContext)
const ConstTensorHandle * m_Bias
const TensorInfo & GetTensorInfo() const
armnn::FullyConnectedQueueDescriptor m_Data
Definition: Workload.hpp:58
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:30
const ConstTensorHandle * m_Weight
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:25
#define CHECK_LOCATION()
Definition: Exceptions.hpp:197
std::vector< ITensorHandle * > m_Outputs
Contains information about inputs and outputs to a layer.
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstTensorHandle *handle)
std::vector< ITensorHandle * > m_Inputs