blob: f5aa8f3447e61a243af55f369c584649b549bf78 [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#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 <boost/numeric/conversion/cast.hpp>
19
20#include <cmath>
21#include <limits>
22
23namespace armnn
24{
25
telsoa01c577f2c2018-08-31 09:22:23 +010026/// Performs multiplication of an integer with a multiplier which is less than one,
telsoa014fcda012018-03-09 14:13:49 +000027/// using quantized integer arithmetic which is consistent with AndroidNN's CPU executor.
28struct QuantizedMultiplierSmallerThanOne
29{
30public:
31 /// Constructs a QuantizedMultiplierSmallerThanOne which will multiply by the given multiplier.
32 /// This stores the appropriate integer quantities (derived from the given multiplier) for later use.
33 /// The implementation of this function is adapted from Android NN's QuantizeMultiplierSmallerThanOne().
34 QuantizedMultiplierSmallerThanOne(float multiplier);
35
telsoa01c577f2c2018-08-31 09:22:23 +010036 /// The implementation of this function is adapted from Android NN's MultiplyByQuantizedMultiplierSmallerThanOne().
telsoa014fcda012018-03-09 14:13:49 +000037 int32_t operator*(int32_t rhs) const;
38
39private:
telsoa01c577f2c2018-08-31 09:22:23 +010040 /// The implementation of this function is adapted from gemmlowp's SaturatingRoundingDoublingHighMul().
telsoa014fcda012018-03-09 14:13:49 +000041 static int32_t SaturatingRoundingDoublingHighMul(int32_t a, int32_t b);
42
telsoa01c577f2c2018-08-31 09:22:23 +010043 /// The implementation of this function is adapted from gemmlowp's RoundingDivideByPOT().
telsoa014fcda012018-03-09 14:13:49 +000044 static int32_t RoundingDivideByPOT(int32_t x, int exponent);
45
46 int32_t m_Multiplier;
47 int32_t m_RightShift;
48};
49
Mike Kelly9b398322019-05-22 17:21:49 +010050void Convolve(const TensorShape& rInputShape,
51 Decoder<float>& rInputDecoder,
52 const TensorShape& rOutputShape,
53 Encoder<float>& rOutputEncoder,
54 const TensorShape& rFilterShape,
55 Decoder<float>& rFilterDecoder,
56 bool biasEnabled,
57 Decoder<float>* pBiasDecoder,
58 DataLayout dataLayout,
59 unsigned int paddingTop,
60 unsigned int paddingLeft,
61 unsigned int xStride,
62 unsigned int yStride,
63 unsigned int xDilation,
64 unsigned int yDilation,
65 bool depthwise = false);
telsoa014fcda012018-03-09 14:13:49 +000066} //namespace armnn