ArmNN
 20.05
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"
13 
14 #include <arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h>
15 
16 namespace armnn
17 {
18 using namespace armcomputetensorutils;
19 
21  const TensorInfo& output,
22  const TensorInfo& weights,
23  const TensorInfo& biases,
24  const FullyConnectedDescriptor& descriptor)
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 =
40 
41 
42  return arm_compute::NEFullyConnectedLayer::validate(&aclInput,
43  &aclWeights,
44  optionalAclBiases,
45  &aclOutput,
46  fullyConnectedLayerInfo);
47 }
48 
50  const WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
51  : BaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info)
52 {
53  m_Data.ValidateInputsOutputs("NeonFullyConnectedWorkload", 1, 1);
54 
55  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
56  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
57 
58  m_WeightsTensor = std::make_unique<arm_compute::Tensor>();
59  BuildArmComputeTensor(*m_WeightsTensor, m_Data.m_Weight->GetTensorInfo());
60 
62  {
63  m_BiasesTensor = std::make_unique<arm_compute::Tensor>();
64  BuildArmComputeTensor(*m_BiasesTensor, m_Data.m_Bias->GetTensorInfo());
65  }
66 
67  // Construct
68  arm_compute::FullyConnectedLayerInfo fc_info;
69  fc_info.transpose_weights = m_Data.m_Parameters.m_TransposeWeightMatrix;
70 
71  auto layer = std::make_unique<arm_compute::NEFullyConnectedLayer>(memoryManager);
72  layer->configure(&input, m_WeightsTensor.get(), m_BiasesTensor.get(), &output, fc_info);
73  m_FullyConnectedLayer.reset(layer.release());
74 
75  // Allocate
77  {
79  }
80  else
81  {
83  }
84 
85  if (m_BiasesTensor)
86  {
88  {
90  }
91  else
92  {
94  }
95  }
96 
97  // Force Compute Library to perform the necessary copying and reshaping, after which
98  // delete all the input tensors that will no longer be needed
99  m_FullyConnectedLayer->prepare();
100  FreeUnusedTensors();
101 }
102 
104 {
105  ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonFullyConnectedWorkload_Execute");
106  m_FullyConnectedLayer->run();
107 }
108 
109 void NeonFullyConnectedWorkload::FreeUnusedTensors()
110 {
111  FreeTensorIfUnused(m_WeightsTensor);
112  FreeTensorIfUnused(m_BiasesTensor);
113 }
114 
115 } //namespace armnn
const ConstCpuTensorHandle * m_Weight
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
const FullyConnectedQueueDescriptor m_Data
Definition: Workload.hpp:46
#define ARMNN_SCOPED_PROFILING_EVENT_NEON(name)
NeonFullyConnectedWorkload(const FullyConnectedQueueDescriptor &descriptor, const WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2020 ARM Limited.
arm_compute::FullyConnectedLayerInfo ConvertFullyConnectedDescriptorToAclFullyConnectedLayerInfo(const FullyConnectedDescriptor &fullyConnectedDesc)
DataType GetDataType() const
Definition: Tensor.hpp:95
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_BiasEnabled
Enable/disable bias.
Status
enumeration
Definition: Types.hpp:26
arm_compute::Status NeonFullyConnectedWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &weights, const TensorInfo &biases, const FullyConnectedDescriptor &descriptor)
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