• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Gemmlowp Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // bit_depth.h: defines the settins controlling LHS/RHS bit depth
16 
17 #ifndef GEMMLOWP_PUBLIC_BIT_DEPTH_H_
18 #define GEMMLOWP_PUBLIC_BIT_DEPTH_H_
19 
20 namespace gemmlowp {
21 
22 // The range of allowed values for an operand.
23 template <int tMinValue, int tMaxValue>
24 struct OperandRange {
25   static constexpr int kMinValue = tMinValue;
26   static constexpr int kMaxValue = tMaxValue;
27   static_assert(kMinValue < kMaxValue, "");
28 };
29 
30 using Uint8Range = OperandRange<0, 255>;
31 using Uint8RangeExcludingZero = OperandRange<1, 255>;
32 
33 using Int8Range = OperandRange<-128, 127>;
34 using Int8RangeExcludingLow = OperandRange<-127, 127>;
35 
36 template <typename tLhsRange, typename tRhsRange>
37 struct BitDepthParams {
38   using LhsRange = tLhsRange;
39   using RhsRange = tRhsRange;
40 };
41 
42 // Default: LHS and RHS are 8bit.
43 using DefaultL8R8BitDepthParams = BitDepthParams<Uint8Range, Uint8Range>;
44 
45 // Variant: LHS may not take the value 0. This allows using
46 // faster kernels using signed arithmetic, see
47 // NEON_64bit_GEMM_Int8Operands_Int32Accumulators_AccumTwoWithin16Bits
48 using L8R8WithLhsNonzeroBitDepthParams =
49     BitDepthParams<Uint8RangeExcludingZero, Uint8Range>;
50 
51 // Signed Variant: This allows using faster kernels using signed arithmetic, see
52 // NEON_64bit_GEMM_Int8Operands_Int32Accumulators_AccumTwoWithin16Bits
53 using SignedL8R8WithLhsNonzeroBitDepthParams =
54     BitDepthParams<Int8RangeExcludingLow, Int8Range>;
55 
56 // Deprecated: when gemmlowp used to allow requantizing 8bit
57 // inputs to less-than-8-bit depths, the public setting allowing
58 // that was DefaultL7R5BitDepthParams. That requantization
59 // feature has been removed, but as the whole point of that
60 // requantization was to make less-than-8-bit an internal
61 // optimization without any impact on the API (other than lowering
62 // accuracy), we can temporarily support users who were using it
63 // by mapping it to the default 8bit behavior.
64 using DefaultL7R5BitDepthParams = DefaultL8R8BitDepthParams;
65 
66 }  // namespace gemmlowp
67 
68 #endif  // GEMMLOWP_PUBLIC_BIT_DEPTH_H_
69