blob: 5a7951ec48a5c804de485d15fb05972c2a7dc015 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Francis Murtagh43aec582019-05-27 12:14:10 +01002// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "RefFullyConnectedWorkload.hpp"
7
8#include "FullyConnected.hpp"
9#include "RefWorkloadUtils.hpp"
10
11#include "Profiling.hpp"
12
13namespace armnn
14{
15RefFullyConnectedWorkload::RefFullyConnectedWorkload(
16 const FullyConnectedQueueDescriptor& descriptor, const WorkloadInfo& info)
Sadik Armaganf0a6dec2021-03-25 07:46:55 +000017 : BaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info)
Francis Murtagh43aec582019-05-27 12:14:10 +010018{
Francis Murtagh43aec582019-05-27 12:14:10 +010019}
20
21void RefFullyConnectedWorkload::PostAllocationConfigure()
22{
Finn Williamsb8181f72021-04-07 10:23:21 +010023 PostAllocationConfigure(m_Data.m_Inputs, m_Data.m_Outputs);
24}
25
26void RefFullyConnectedWorkload::PostAllocationConfigure(std::vector<ITensorHandle*> inputs,
27 std::vector<ITensorHandle*> outputs)
28{
29 const TensorInfo& inputInfo = GetTensorInfo(inputs[0]);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010030 ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1);
Francis Murtagh43aec582019-05-27 12:14:10 +010031 m_InputShape = inputInfo.GetShape();
Francis Murtagh43aec582019-05-27 12:14:10 +010032
Matthew Sloyan81beae32021-07-13 19:46:11 +010033 const TensorInfo& rWeightInfo = GetTensorInfo(inputs[1]);
34 ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1);
35 m_WeightShape = rWeightInfo.GetShape();
36 m_WeightDecoder = MakeDecoder<float>(rWeightInfo);
Sadik Armaganf0a6dec2021-03-25 07:46:55 +000037
Matthew Sloyan81beae32021-07-13 19:46:11 +010038 if (m_Data.m_Parameters.m_BiasEnabled)
39 {
40 const TensorInfo& biasInfo = GetTensorInfo(inputs[2]);
41 m_BiasDecoder = MakeDecoder<float>(biasInfo);
Sadik Armaganf0a6dec2021-03-25 07:46:55 +000042 }
43
Finn Williamsb8181f72021-04-07 10:23:21 +010044 const TensorInfo& outputInfo = GetTensorInfo(outputs[0]);
Francis Murtagh43aec582019-05-27 12:14:10 +010045 m_OutputShape = outputInfo.GetShape();
Francis Murtagh43aec582019-05-27 12:14:10 +010046
47 m_NumActivations = 1; // Total number of activations in the input.
48 for (unsigned int i = 1; i < inputInfo.GetNumDimensions(); i++)
49 {
50 m_NumActivations *= inputInfo.GetShape()[i];
51 }
52}
53
54void RefFullyConnectedWorkload::Execute() const
55{
Finn Williamsb8181f72021-04-07 10:23:21 +010056 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
57}
58
59void RefFullyConnectedWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor)
60{
61 PostAllocationConfigure(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
62
63 Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
64}
65
66void RefFullyConnectedWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
67{
Francis Murtagh43aec582019-05-27 12:14:10 +010068 ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFullyConnectedWorkload_Execute");
69
Finn Williamsb8181f72021-04-07 10:23:21 +010070 std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map());
71 std::unique_ptr<Encoder<float>> OutputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map());
72
Matthew Sloyan81beae32021-07-13 19:46:11 +010073 m_WeightDecoder->Reset(inputs[1]->Map());
74 if (m_Data.m_Parameters.m_BiasEnabled)
Sadik Armaganf0a6dec2021-03-25 07:46:55 +000075 {
Matthew Sloyan81beae32021-07-13 19:46:11 +010076 m_BiasDecoder->Reset(inputs[2]->Map());
Sadik Armaganf0a6dec2021-03-25 07:46:55 +000077 }
Matthew Benthamc394a6d2019-06-24 12:51:25 +010078
Francis Murtagh43aec582019-05-27 12:14:10 +010079 FullyConnected(m_InputShape,
Finn Williamsb8181f72021-04-07 10:23:21 +010080 *inputDecoder,
Francis Murtagh43aec582019-05-27 12:14:10 +010081 m_OutputShape,
Finn Williamsb8181f72021-04-07 10:23:21 +010082 *OutputEncoder,
Finn Williamsb9dcfe62020-09-17 15:58:31 +010083 m_WeightShape,
Francis Murtagh43aec582019-05-27 12:14:10 +010084 *m_WeightDecoder,
Matthew Bentham18bf43d2021-07-07 09:08:48 +010085 m_BiasDecoder.get(),
Francis Murtagh43aec582019-05-27 12:14:10 +010086 m_Data.m_Parameters.m_BiasEnabled,
87 m_NumActivations,
88 m_Data.m_Parameters.m_TransposeWeightMatrix);
89}
90
91} //namespace armnn