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 | { |
Finn Williams | d0420cb | 2022-05-18 13:24:14 +0100 | [diff] [blame] | 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 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 27 | RefFullyConnectedWorkload::RefFullyConnectedWorkload( |
| 28 | const FullyConnectedQueueDescriptor& descriptor, const WorkloadInfo& info) |
Finn Williams | 73c547d | 2022-02-15 20:47:34 +0000 | [diff] [blame] | 29 | : RefBaseWorkload<FullyConnectedQueueDescriptor>(descriptor, info) |
Finn Williams | d0420cb | 2022-05-18 13:24:14 +0100 | [diff] [blame] | 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])) |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 34 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 37 | void RefFullyConnectedWorkload::Execute() const |
| 38 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 39 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
| 40 | } |
| 41 | |
| 42 | void RefFullyConnectedWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 43 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 44 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 45 | } |
| 46 | |
| 47 | void RefFullyConnectedWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const |
| 48 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 49 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFullyConnectedWorkload_Execute"); |
| 50 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 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 | |
Finn Williams | d0420cb | 2022-05-18 13:24:14 +0100 | [diff] [blame] | 54 | std::unique_ptr<Decoder<float>> weightsDecoder = MakeDecoder<float>(GetTensorInfo(inputs[1]), inputs[1]->Map()); |
| 55 | std::unique_ptr<Decoder<float>> biasDecoder; |
| 56 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 57 | if (m_Data.m_Parameters.m_BiasEnabled) |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 58 | { |
Finn Williams | d0420cb | 2022-05-18 13:24:14 +0100 | [diff] [blame] | 59 | biasDecoder = MakeDecoder<float>(GetTensorInfo(inputs[2]), inputs[2]->Map()); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 60 | } |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 61 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 62 | FullyConnected(m_InputShape, |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 63 | *inputDecoder, |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 64 | m_OutputShape, |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 65 | *OutputEncoder, |
Finn Williams | b9dcfe6 | 2020-09-17 15:58:31 +0100 | [diff] [blame] | 66 | m_WeightShape, |
Finn Williams | d0420cb | 2022-05-18 13:24:14 +0100 | [diff] [blame] | 67 | *weightsDecoder, |
| 68 | biasDecoder.get(), |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 69 | m_Data.m_Parameters.m_BiasEnabled, |
| 70 | m_NumActivations, |
| 71 | m_Data.m_Parameters.m_TransposeWeightMatrix); |
| 72 | } |
| 73 | |
| 74 | } //namespace armnn |