ArmNN
 22.11
RefFullyConnectedWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022 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 
43 {
44  WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
45  Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
46 }
47 
48 void RefFullyConnectedWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
49 {
50  ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFullyConnectedWorkload_Execute");
51 
52  std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map());
53  std::unique_ptr<Encoder<float>> OutputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map());
54 
55  std::unique_ptr<Decoder<float>> weightsDecoder = MakeDecoder<float>(GetTensorInfo(inputs[1]), inputs[1]->Map());
56  std::unique_ptr<Decoder<float>> biasDecoder;
57 
59  {
60  biasDecoder = MakeDecoder<float>(GetTensorInfo(inputs[2]), inputs[2]->Map());
61  }
62 
63  FullyConnected(m_InputShape,
64  *inputDecoder,
65  m_OutputShape,
66  *OutputEncoder,
67  m_WeightShape,
68  *weightsDecoder,
69  biasDecoder.get(),
71  m_NumActivations,
73 }
74 
75 } //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.
RefFullyConnectedWorkload(const FullyConnectedQueueDescriptor &descriptor, const WorkloadInfo &info)
std::vector< ITensorHandle * > m_Outputs
void ExecuteAsync(ExecutionData &executionData) override
Contains information about TensorInfos of a layer.
std::vector< ITensorHandle * > m_Inputs
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers