Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 2 | // 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 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | RefFullyConnectedWorkload::RefFullyConnectedWorkload( |
| 16 | const FullyConnectedQueueDescriptor& descriptor, const WorkloadInfo& info) |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 17 | : BaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info) |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 18 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | void RefFullyConnectedWorkload::PostAllocationConfigure() |
| 22 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 23 | PostAllocationConfigure(m_Data.m_Inputs, m_Data.m_Outputs); |
| 24 | } |
| 25 | |
| 26 | void RefFullyConnectedWorkload::PostAllocationConfigure(std::vector<ITensorHandle*> inputs, |
| 27 | std::vector<ITensorHandle*> outputs) |
| 28 | { |
| 29 | const TensorInfo& inputInfo = GetTensorInfo(inputs[0]); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 30 | ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 31 | m_InputShape = inputInfo.GetShape(); |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 32 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame^] | 33 | const TensorInfo& rWeightInfo = GetTensorInfo(inputs[1]); |
| 34 | ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); |
| 35 | m_WeightShape = rWeightInfo.GetShape(); |
| 36 | m_WeightDecoder = MakeDecoder<float>(rWeightInfo); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 37 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame^] | 38 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 39 | { |
| 40 | const TensorInfo& biasInfo = GetTensorInfo(inputs[2]); |
| 41 | m_BiasDecoder = MakeDecoder<float>(biasInfo); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 44 | const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 45 | m_OutputShape = outputInfo.GetShape(); |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 46 | |
| 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 | |
| 54 | void RefFullyConnectedWorkload::Execute() const |
| 55 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 56 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
| 57 | } |
| 58 | |
| 59 | void RefFullyConnectedWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 60 | { |
| 61 | PostAllocationConfigure(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 62 | |
| 63 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 64 | } |
| 65 | |
| 66 | void RefFullyConnectedWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const |
| 67 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 68 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFullyConnectedWorkload_Execute"); |
| 69 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 70 | 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 Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame^] | 73 | m_WeightDecoder->Reset(inputs[1]->Map()); |
| 74 | if (m_Data.m_Parameters.m_BiasEnabled) |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 75 | { |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame^] | 76 | m_BiasDecoder->Reset(inputs[2]->Map()); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 77 | } |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 78 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 79 | FullyConnected(m_InputShape, |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 80 | *inputDecoder, |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 81 | m_OutputShape, |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 82 | *OutputEncoder, |
Finn Williams | b9dcfe6 | 2020-09-17 15:58:31 +0100 | [diff] [blame] | 83 | m_WeightShape, |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 84 | *m_WeightDecoder, |
Matthew Bentham | 18bf43d | 2021-07-07 09:08:48 +0100 | [diff] [blame] | 85 | m_BiasDecoder.get(), |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 86 | m_Data.m_Parameters.m_BiasEnabled, |
| 87 | m_NumActivations, |
| 88 | m_Data.m_Parameters.m_TransposeWeightMatrix); |
| 89 | } |
| 90 | |
| 91 | } //namespace armnn |