ArmNN
 21.02
NeonFullyConnectedWorkload.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 
8 #include "NeonWorkloadUtils.hpp"
9 
12 
14 
16 
17 #include <arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h>
18 
19 namespace armnn
20 {
21 using namespace armcomputetensorutils;
22 
24  const TensorInfo& output,
25  const TensorInfo& weights,
26  const TensorInfo& biases,
27  const FullyConnectedDescriptor& descriptor,
28  const ActivationDescriptor* activationDescriptor)
29 {
30  const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input);
31  const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output);
32  const arm_compute::TensorInfo aclWeights = BuildArmComputeTensorInfo(weights);
33 
34  arm_compute::TensorInfo aclBiases;
35  arm_compute::TensorInfo *optionalAclBiases = nullptr;
36  if (descriptor.m_BiasEnabled)
37  {
38  aclBiases = BuildArmComputeTensorInfo(biases);
39  optionalAclBiases = &aclBiases;
40  }
41 
42  const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo =
43  ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(descriptor, activationDescriptor);
44 
45  return arm_compute::NEFullyConnectedLayer::validate(&aclInput,
46  &aclWeights,
47  optionalAclBiases,
48  &aclOutput,
49  fullyConnectedLayerInfo);
50 }
51 
53  const WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
54  : BaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info)
55 {
56  m_Data.ValidateInputsOutputs("NeonFullyConnectedWorkload", 1, 1);
57 
58  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
59  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
60 
61  m_WeightsTensor = std::make_unique<arm_compute::Tensor>();
62  BuildArmComputeTensor(*m_WeightsTensor, m_Data.m_Weight->GetTensorInfo());
63 
65  {
66  m_BiasesTensor = std::make_unique<arm_compute::Tensor>();
67  BuildArmComputeTensor(*m_BiasesTensor, m_Data.m_Bias->GetTensorInfo());
68  }
69 
70  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
71 
72  arm_compute::FullyConnectedLayerInfo fc_info =
74 
75  auto layer = std::make_unique<arm_compute::NEFullyConnectedLayer>(memoryManager);
76  layer->configure(&input, m_WeightsTensor.get(), m_BiasesTensor.get(), &output, fc_info);
77  m_FullyConnectedLayer.reset(layer.release());
78 
79  // Allocate
81  {
83  }
84  else
85  {
87  }
88 
89  if (m_BiasesTensor)
90  {
92  {
94  }
95  else
96  {
98  }
99  }
100 
101  // Force Compute Library to perform the necessary copying and reshaping, after which
102  // delete all the input tensors that will no longer be needed
103  m_FullyConnectedLayer->prepare();
104  FreeUnusedTensors();
105 }
106 
108 {
109  ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonFullyConnectedWorkload_Execute");
110  m_FullyConnectedLayer->run();
111 }
112 
113 void NeonFullyConnectedWorkload::FreeUnusedTensors()
114 {
115  FreeTensorIfUnused(m_WeightsTensor);
116  FreeTensorIfUnused(m_BiasesTensor);
117 }
118 
119 } //namespace armnn
const ConstCpuTensorHandle * m_Weight
const FullyConnectedQueueDescriptor m_Data
Definition: Workload.hpp:46
#define ARMNN_SCOPED_PROFILING_EVENT_NEON(name)
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
NeonFullyConnectedWorkload(const FullyConnectedQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)
arm_compute::Status NeonFullyConnectedWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &weights, const TensorInfo &biases, const FullyConnectedDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2021 ARM Limited and Contributors.
DataType GetDataType() const
Definition: Tensor.hpp:194
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:26
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:25
void InitializeArmComputeTensorData(arm_compute::Tensor &tensor, const ConstCpuTensorHandle *handle)
std::vector< ITensorHandle * > m_Outputs
Contains information about inputs and outputs to a layer.
std::vector< ITensorHandle * > m_Inputs
const ConstCpuTensorHandle * m_Bias
const TensorInfo & GetTensorInfo() const