ArmNN
 20.11
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 WorkloadInfo& info, std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
50  : BaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info)
51  , m_FullyConnectedLayer(memoryManager)
52 {
53  m_WeightsTensor = std::make_unique<arm_compute::CLTensor>();
54  BuildArmComputeTensor(*m_WeightsTensor, m_Data.m_Weight->GetTensorInfo());
55 
57  {
58  m_BiasesTensor = std::make_unique<arm_compute::CLTensor>();
59  BuildArmComputeTensor(*m_BiasesTensor, m_Data.m_Bias->GetTensorInfo());
60  }
61 
62  m_Data.ValidateInputsOutputs("ClFullyConnectedWorkload", 1, 1);
63 
64  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
65  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
66 
67  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
68 
69  arm_compute::FullyConnectedLayerInfo fc_info =
71 
72  m_FullyConnectedLayer.configure(&input, m_WeightsTensor.get(), m_BiasesTensor.get(), &output, fc_info);
73 
75 
76  if (m_BiasesTensor)
77  {
79  }
80 
81  // Force Compute Library to perform the necessary copying and reshaping, after which
82  // delete all the input tensors that will no longer be needed
83  m_FullyConnectedLayer.prepare();
84  FreeUnusedTensors();
85 }
86 
88 {
89  ARMNN_SCOPED_PROFILING_EVENT_CL("ClFullyConnectedWorkload_Execute");
90  RunClFunction(m_FullyConnectedLayer, CHECK_LOCATION());
91 }
92 
93 void ClFullyConnectedWorkload::FreeUnusedTensors()
94 {
95  FreeTensorIfUnused(m_WeightsTensor);
96  FreeTensorIfUnused(m_BiasesTensor);
97 }
98 
99 } //namespace armnn
arm_compute::Status ClFullyConnectedWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &weights, const TensorInfo &biases, const FullyConnectedDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
void InitializeArmComputeClTensorData(arm_compute::CLTensor &clTensor, const ConstCpuTensorHandle *handle)
const ConstCpuTensorHandle * m_Weight
#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
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2020 ARM Limited.
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
ClFullyConnectedWorkload(const armnn::FullyConnectedQueueDescriptor &descriptor, const armnn::WorkloadInfo &info, std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
#define CHECK_LOCATION()
Definition: Exceptions.hpp:197
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