blob: d9d8a87ae804dace10461392bf91311416af3f78 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
telsoa014fcda012018-03-09 14:13:49 +00002// 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#pragma once
7
8#include "RefWorkloadUtils.hpp"
narpra015f703182018-10-26 16:24:58 +01009#include "TensorBufferArrayView.hpp"
Mike Kelly9b398322019-05-22 17:21:49 +010010#include "BaseIterator.hpp"
11#include "Decoders.hpp"
12#include "Encoders.hpp"
telsoa014fcda012018-03-09 14:13:49 +000013
14#include <armnn/Tensor.hpp>
15
Matteo Martincighe011d202019-11-28 11:35:47 +000016#include <armnnUtils/DataLayoutIndexed.hpp>
Matthew Bentham8800c002018-11-19 13:19:28 +000017
telsoa014fcda012018-03-09 14:13:49 +000018#include <cmath>
19#include <limits>
20
21namespace armnn
22{
23
telsoa01c577f2c2018-08-31 09:22:23 +010024/// Performs multiplication of an integer with a multiplier which is less than one,
telsoa014fcda012018-03-09 14:13:49 +000025/// using quantized integer arithmetic which is consistent with AndroidNN's CPU executor.
26struct QuantizedMultiplierSmallerThanOne
27{
28public:
29 /// Constructs a QuantizedMultiplierSmallerThanOne which will multiply by the given multiplier.
30 /// This stores the appropriate integer quantities (derived from the given multiplier) for later use.
31 /// The implementation of this function is adapted from Android NN's QuantizeMultiplierSmallerThanOne().
32 QuantizedMultiplierSmallerThanOne(float multiplier);
33
telsoa01c577f2c2018-08-31 09:22:23 +010034 /// The implementation of this function is adapted from Android NN's MultiplyByQuantizedMultiplierSmallerThanOne().
telsoa014fcda012018-03-09 14:13:49 +000035 int32_t operator*(int32_t rhs) const;
36
37private:
telsoa01c577f2c2018-08-31 09:22:23 +010038 /// The implementation of this function is adapted from gemmlowp's SaturatingRoundingDoublingHighMul().
telsoa014fcda012018-03-09 14:13:49 +000039 static int32_t SaturatingRoundingDoublingHighMul(int32_t a, int32_t b);
40
telsoa01c577f2c2018-08-31 09:22:23 +010041 /// The implementation of this function is adapted from gemmlowp's RoundingDivideByPOT().
telsoa014fcda012018-03-09 14:13:49 +000042 static int32_t RoundingDivideByPOT(int32_t x, int exponent);
43
44 int32_t m_Multiplier;
45 int32_t m_RightShift;
46};
47
Mike Kelly9b398322019-05-22 17:21:49 +010048void Convolve(const TensorShape& rInputShape,
49 Decoder<float>& rInputDecoder,
50 const TensorShape& rOutputShape,
51 Encoder<float>& rOutputEncoder,
52 const TensorShape& rFilterShape,
53 Decoder<float>& rFilterDecoder,
54 bool biasEnabled,
55 Decoder<float>* pBiasDecoder,
56 DataLayout dataLayout,
57 unsigned int paddingTop,
58 unsigned int paddingLeft,
59 unsigned int xStride,
60 unsigned int yStride,
61 unsigned int xDilation,
62 unsigned int yDilation,
63 bool depthwise = false);
telsoa014fcda012018-03-09 14:13:49 +000064} //namespace armnn