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