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 | { |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 19 | if (descriptor.m_Parameters.m_ConstantWeights) |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 20 | { |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 21 | m_Weight = std::make_unique<ScopedCpuTensorHandle>(*(descriptor.m_Weight)); |
| 22 | const TensorInfo& rWeightInfo = m_Weight->GetTensorInfo(); |
| 23 | m_WeightShape = rWeightInfo.GetShape(); |
| 24 | m_WeightDecoder = MakeDecoder<float>(rWeightInfo, m_Weight->Map(true)); |
| 25 | |
| 26 | if (descriptor.m_Parameters.m_BiasEnabled) |
| 27 | { |
| 28 | m_Bias = std::make_unique<ScopedCpuTensorHandle>(*(descriptor.m_Bias)); |
| 29 | const TensorInfo& biasInfo = m_Bias->GetTensorInfo(); |
| 30 | m_BiasDecoder = MakeDecoder<float>(biasInfo, m_Bias->Map(true)); |
| 31 | } |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
| 35 | void RefFullyConnectedWorkload::PostAllocationConfigure() |
| 36 | { |
| 37 | const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 38 | ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 39 | m_InputShape = inputInfo.GetShape(); |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 40 | m_InputDecoder = MakeDecoder<float>(inputInfo); |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 41 | |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 42 | if (!m_Data.m_Parameters.m_ConstantWeights) |
| 43 | { |
| 44 | const TensorInfo& rWeightInfo = GetTensorInfo(m_Data.m_Inputs[1]); |
| 45 | ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); |
| 46 | m_WeightShape = rWeightInfo.GetShape(); |
| 47 | m_WeightDecoder = MakeDecoder<float>(rWeightInfo); |
| 48 | |
| 49 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 50 | { |
| 51 | const TensorInfo& biasInfo = GetTensorInfo(m_Data.m_Inputs[2]); |
| 52 | m_BiasDecoder = MakeDecoder<float>(biasInfo); |
| 53 | } |
| 54 | } |
| 55 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 56 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 57 | m_OutputShape = outputInfo.GetShape(); |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 58 | m_OutputEncoder = MakeEncoder<float>(outputInfo); |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 59 | |
| 60 | m_NumActivations = 1; // Total number of activations in the input. |
| 61 | for (unsigned int i = 1; i < inputInfo.GetNumDimensions(); i++) |
| 62 | { |
| 63 | m_NumActivations *= inputInfo.GetShape()[i]; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void RefFullyConnectedWorkload::Execute() const |
| 68 | { |
| 69 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFullyConnectedWorkload_Execute"); |
| 70 | |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 71 | m_InputDecoder->Reset(m_Data.m_Inputs[0]->Map()); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 72 | if (!m_Data.m_Parameters.m_ConstantWeights) |
| 73 | { |
| 74 | m_WeightDecoder->Reset(m_Data.m_Inputs[1]->Map()); |
| 75 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 76 | { |
| 77 | m_BiasDecoder->Reset(m_Data.m_Inputs[2]->Map()); |
| 78 | } |
| 79 | } |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 80 | m_OutputEncoder->Reset(m_Data.m_Outputs[0]->Map()); |
| 81 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 82 | FullyConnected(m_InputShape, |
| 83 | *m_InputDecoder, |
| 84 | m_OutputShape, |
| 85 | *m_OutputEncoder, |
Finn Williams | b9dcfe6 | 2020-09-17 15:58:31 +0100 | [diff] [blame] | 86 | m_WeightShape, |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 87 | *m_WeightDecoder, |
| 88 | *m_BiasDecoder, |
| 89 | m_Data.m_Parameters.m_BiasEnabled, |
| 90 | m_NumActivations, |
| 91 | m_Data.m_Parameters.m_TransposeWeightMatrix); |
| 92 | } |
| 93 | |
| 94 | } //namespace armnn |