telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include "RefFullyConnectedUint8Workload.hpp" |
| 7 | |
| 8 | #include "FullyConnected.hpp" |
| 9 | #include "RefWorkloadUtils.hpp" |
| 10 | |
| 11 | #include "Profiling.hpp" |
| 12 | |
| 13 | #include <vector> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 17 | RefFullyConnectedUint8Workload::RefFullyConnectedUint8Workload( |
| 18 | const FullyConnectedQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 19 | : Uint8Workload<FullyConnectedQueueDescriptor>(descriptor, info), |
| 20 | m_Weight(std::make_unique<ScopedCpuTensorHandle>(*(descriptor.m_Weight))), |
| 21 | m_Bias(descriptor.m_Parameters.m_BiasEnabled |
| 22 | ? std::make_unique<ScopedCpuTensorHandle>(*(descriptor.m_Bias)) : nullptr) {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 23 | |
| 24 | void RefFullyConnectedUint8Workload::Execute() const |
| 25 | { |
| 26 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFullyConnectedUint8Workload_Execute"); |
| 27 | |
| 28 | const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]); |
| 29 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 30 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 31 | const uint8_t* weightData = m_Weight->GetConstTensor<uint8_t>(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 32 | |
| 33 | auto dequant = Dequantize(GetInputTensorDataU8(0, m_Data), inputInfo); |
| 34 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 35 | auto weight = Dequantize(weightData, m_Weight->GetTensorInfo()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 36 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 37 | std::vector<float> results(outputInfo.GetNumElements()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 38 | |
| 39 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 40 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 41 | const int32_t* biasData = m_Bias->GetConstTensor<int32_t>(); |
| 42 | auto bias = Dequantize(biasData, m_Bias->GetTensorInfo()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 43 | |
| 44 | FullyConnected(dequant.data(), |
| 45 | results.data(), |
| 46 | inputInfo, |
| 47 | outputInfo, |
| 48 | weight.data(), |
| 49 | bias.data(), |
| 50 | m_Data.m_Parameters.m_TransposeWeightMatrix); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | FullyConnected(dequant.data(), |
| 55 | results.data(), |
| 56 | inputInfo, |
| 57 | outputInfo, |
| 58 | weight.data(), |
| 59 | nullptr, |
| 60 | m_Data.m_Parameters.m_TransposeWeightMatrix); |
| 61 | } |
| 62 | |
| 63 | Quantize(GetOutputTensorDataU8(0, m_Data), results.data(), outputInfo); |
| 64 | } |
| 65 | |
| 66 | } //namespace armnn |