blob: cd785d786c85b40198bb835d81220e98f560c317 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
6#include "RefFullyConnectedUint8Workload.hpp"
7
8#include "FullyConnected.hpp"
9#include "RefWorkloadUtils.hpp"
10
11#include "Profiling.hpp"
12
13#include <vector>
14
15namespace armnn
16{
telsoa01c577f2c2018-08-31 09:22:23 +010017RefFullyConnectedUint8Workload::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) {}
telsoa014fcda012018-03-09 14:13:49 +000023
24void 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
telsoa01c577f2c2018-08-31 09:22:23 +010031 const uint8_t* weightData = m_Weight->GetConstTensor<uint8_t>();
telsoa014fcda012018-03-09 14:13:49 +000032
33 auto dequant = Dequantize(GetInputTensorDataU8(0, m_Data), inputInfo);
34
telsoa01c577f2c2018-08-31 09:22:23 +010035 auto weight = Dequantize(weightData, m_Weight->GetTensorInfo());
telsoa014fcda012018-03-09 14:13:49 +000036
telsoa01c577f2c2018-08-31 09:22:23 +010037 std::vector<float> results(outputInfo.GetNumElements());
telsoa014fcda012018-03-09 14:13:49 +000038
39 if (m_Data.m_Parameters.m_BiasEnabled)
40 {
telsoa01c577f2c2018-08-31 09:22:23 +010041 const int32_t* biasData = m_Bias->GetConstTensor<int32_t>();
42 auto bias = Dequantize(biasData, m_Bias->GetTensorInfo());
telsoa014fcda012018-03-09 14:13:49 +000043
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