blob: 7dba760d87ca50e2071fdf5b5d85f7639c23a2d0 [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 Martincigh21350152018-11-28 16:22:22 +000016#include <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
Matteo Martincigh46315822018-11-28 16:22:36 +000021#include <DataLayoutIndexed.hpp>
22
telsoa014fcda012018-03-09 14:13:49 +000023#include <cmath>
24#include <limits>
25
26namespace armnn
27{
28
telsoa01c577f2c2018-08-31 09:22:23 +010029/// Performs multiplication of an integer with a multiplier which is less than one,
telsoa014fcda012018-03-09 14:13:49 +000030/// using quantized integer arithmetic which is consistent with AndroidNN's CPU executor.
31struct QuantizedMultiplierSmallerThanOne
32{
33public:
34 /// Constructs a QuantizedMultiplierSmallerThanOne which will multiply by the given multiplier.
35 /// This stores the appropriate integer quantities (derived from the given multiplier) for later use.
36 /// The implementation of this function is adapted from Android NN's QuantizeMultiplierSmallerThanOne().
37 QuantizedMultiplierSmallerThanOne(float multiplier);
38
telsoa01c577f2c2018-08-31 09:22:23 +010039 /// The implementation of this function is adapted from Android NN's MultiplyByQuantizedMultiplierSmallerThanOne().
telsoa014fcda012018-03-09 14:13:49 +000040 int32_t operator*(int32_t rhs) const;
41
42private:
telsoa01c577f2c2018-08-31 09:22:23 +010043 /// The implementation of this function is adapted from gemmlowp's SaturatingRoundingDoublingHighMul().
telsoa014fcda012018-03-09 14:13:49 +000044 static int32_t SaturatingRoundingDoublingHighMul(int32_t a, int32_t b);
45
telsoa01c577f2c2018-08-31 09:22:23 +010046 /// The implementation of this function is adapted from gemmlowp's RoundingDivideByPOT().
telsoa014fcda012018-03-09 14:13:49 +000047 static int32_t RoundingDivideByPOT(int32_t x, int exponent);
48
49 int32_t m_Multiplier;
50 int32_t m_RightShift;
51};
52
Mike Kelly9b398322019-05-22 17:21:49 +010053void Convolve(const TensorShape& rInputShape,
54 Decoder<float>& rInputDecoder,
55 const TensorShape& rOutputShape,
56 Encoder<float>& rOutputEncoder,
57 const TensorShape& rFilterShape,
58 Decoder<float>& rFilterDecoder,
59 bool biasEnabled,
60 Decoder<float>* pBiasDecoder,
61 DataLayout dataLayout,
62 unsigned int paddingTop,
63 unsigned int paddingLeft,
64 unsigned int xStride,
65 unsigned int yStride,
66 unsigned int xDilation,
67 unsigned int yDilation,
68 bool depthwise = false);
telsoa014fcda012018-03-09 14:13:49 +000069} //namespace armnn