ArmNN
 22.05
RefFullyConnectedWorkload.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 "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 
43 {
44  Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
45 }
46 
47 void RefFullyConnectedWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
48 {
49  ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFullyConnectedWorkload_Execute");
50 
51  std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map());
52  std::unique_ptr<Encoder<float>> OutputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map());
53 
54  std::unique_ptr<Decoder<float>> weightsDecoder = MakeDecoder<float>(GetTensorInfo(inputs[1]), inputs[1]->Map());
55  std::unique_ptr<Decoder<float>> biasDecoder;
56 
58  {
59  biasDecoder = MakeDecoder<float>(GetTensorInfo(inputs[2]), inputs[2]->Map());
60  }
61 
62  FullyConnected(m_InputShape,
63  *inputDecoder,
64  m_OutputShape,
65  *OutputEncoder,
66  m_WeightShape,
67  *weightsDecoder,
68  biasDecoder.get(),
70  m_NumActivations,
72 }
73 
74 } //namespace armnn
unsigned int GetNumActivations(const TensorInfo &inputInfo)
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
CPU Execution: Reference C++ kernels.
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
Copyright (c) 2021 ARM Limited and Contributors.
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
bool m_BiasEnabled
Enable/disable bias.
void ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) override
RefFullyConnectedWorkload(const FullyConnectedQueueDescriptor &descriptor, const WorkloadInfo &info)
std::vector< ITensorHandle * > m_Outputs
Contains information about TensorInfos of a layer.
std::vector< ITensorHandle * > m_Inputs
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195