ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RefFullyConnectedWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include "FullyConnected.hpp"
9 #include "RefWorkloadUtils.hpp"
10 
11 #include "Profiling.hpp"
12 
13 namespace armnn
14 {
15 
16 unsigned int GetNumActivations(const TensorInfo& inputInfo)
17 {
18  unsigned int numActivations = 1; // Total number of activations in the input.
19  for (unsigned int i = 1; i < inputInfo.GetNumDimensions(); i++)
20  {
21  numActivations *= inputInfo.GetShape()[i];
22  }
23  return numActivations;
24 }
25 
26 
28  const FullyConnectedQueueDescriptor& descriptor, const WorkloadInfo& info)
30  , m_InputShape(info.m_InputTensorInfos[0].GetShape())
31  , m_WeightShape(info.m_InputTensorInfos[1].GetShape())
32  , m_OutputShape(info.m_OutputTensorInfos[0].GetShape())
33  , m_NumActivations(GetNumActivations(info.m_InputTensorInfos[0]))
34 {
35 }
36 
38 {
40 }
41 
42 void RefFullyConnectedWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
43 {
44  ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefFullyConnectedWorkload_Execute");
45 
46  std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map());
47  std::unique_ptr<Encoder<float>> OutputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map());
48 
49  std::unique_ptr<Decoder<float>> weightsDecoder = MakeDecoder<float>(GetTensorInfo(inputs[1]), inputs[1]->Map());
50  std::unique_ptr<Decoder<float>> biasDecoder;
51 
52  if (m_Data.m_Parameters.m_BiasEnabled)
53  {
54  biasDecoder = MakeDecoder<float>(GetTensorInfo(inputs[2]), inputs[2]->Map());
55  }
56 
57  FullyConnected(m_InputShape,
58  *inputDecoder,
59  m_OutputShape,
60  *OutputEncoder,
61  m_WeightShape,
62  *weightsDecoder,
63  biasDecoder.get(),
64  m_Data.m_Parameters.m_BiasEnabled,
65  m_NumActivations,
66  m_Data.m_Parameters.m_TransposeWeightMatrix);
67 }
68 
69 } //namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
QueueDescriptor m_Data
Definition: Workload.hpp:74
RefFullyConnectedWorkload(const FullyConnectedQueueDescriptor &descriptor, const WorkloadInfo &info)
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:197
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
Copyright (c) 2021 ARM Limited and Contributors.
unsigned int GetNumActivations(const TensorInfo &inputInfo)
void FullyConnected(const TensorShape &rInputShape, Decoder< float > &rInputDecoder, const TensorShape &rOutputShape, Encoder< float > &rOutputEncoder, const TensorShape &rWeightsShape, Decoder< float > &rWeightDecoder, Decoder< float > *pBiasDecoder, const bool biasEnabled, const unsigned int K, const bool transposeWeights)
Performs a matrix multiplication and optionally adds a bias.
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
std::vector< ITensorHandle * > m_Inputs
std::vector< ITensorHandle * > m_Outputs
Contains information about TensorInfos of a layer.