ArmNN
 20.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 {
25  const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input);
26  const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output);
27  const arm_compute::TensorInfo aclWeights = BuildArmComputeTensorInfo(weights);
28 
29  arm_compute::TensorInfo aclBiases;
30  arm_compute::TensorInfo *optionalAclBiases = nullptr;
31  if (descriptor.m_BiasEnabled)
32  {
33  aclBiases = BuildArmComputeTensorInfo(biases);
34  optionalAclBiases = &aclBiases;
35  }
36 
37  const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo =
39 
40  return arm_compute::CLFullyConnectedLayer::validate(&aclInput,
41  &aclWeights,
42  optionalAclBiases,
43  &aclOutput,
44  fullyConnectedLayerInfo);
45 }
46 
48  const WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
49  : BaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info)
50  , m_FullyConnectedLayer(memoryManager)
51 {
52  m_WeightsTensor = std::make_unique<arm_compute::CLTensor>();
53  BuildArmComputeTensor(*m_WeightsTensor, m_Data.m_Weight->GetTensorInfo());
54 
56  {
57  m_BiasesTensor = std::make_unique<arm_compute::CLTensor>();
58  BuildArmComputeTensor(*m_BiasesTensor, m_Data.m_Bias->GetTensorInfo());
59  }
60 
61  m_Data.ValidateInputsOutputs("ClFullyConnectedWorkload", 1, 1);
62 
63  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
64  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
65 
66  // Construct
67  arm_compute::FullyConnectedLayerInfo fc_info;
68  fc_info.transpose_weights = m_Data.m_Parameters.m_TransposeWeightMatrix;
69  m_FullyConnectedLayer.configure(&input, m_WeightsTensor.get(), m_BiasesTensor.get(), &output, fc_info);
70 
72 
73  if (m_BiasesTensor)
74  {
76  }
77 
78  // Force Compute Library to perform the necessary copying and reshaping, after which
79  // delete all the input tensors that will no longer be needed
80  m_FullyConnectedLayer.prepare();
81  FreeUnusedTensors();
82 }
83 
85 {
86  ARMNN_SCOPED_PROFILING_EVENT_CL("ClFullyConnectedWorkload_Execute");
87  RunClFunction(m_FullyConnectedLayer, CHECK_LOCATION());
88 }
89 
90 void ClFullyConnectedWorkload::FreeUnusedTensors()
91 {
92  FreeTensorIfUnused(m_WeightsTensor);
93  FreeTensorIfUnused(m_BiasesTensor);
94 }
95 
96 } //namespace armnn
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstCpuTensorHandle *handle)
const ConstCpuTensorHandle * m_Weight
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
arm_compute::Status ClFullyConnectedWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &weights, const TensorInfo &biases, const FullyConnectedDescriptor &descriptor)
#define ARMNN_SCOPED_PROFILING_EVENT_CL(name)
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
const armnn::FullyConnectedQueueDescriptor m_Data
Definition: Workload.hpp:46
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)
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_BiasEnabled
Enable/disable bias.
Status
enumeration
Definition: Types.hpp:26
ClFullyConnectedWorkload(const armnn::FullyConnectedQueueDescriptor &descriptor, const armnn::WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
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