• 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 const int kMinValue = tMinValue;
26   static const int kMaxValue = tMaxValue;
27   static_assert(0 <= kMinValue, "");
28   static_assert(kMinValue < kMaxValue, "");
29   static_assert(kMaxValue <= 255, "");
30 };
31 
32 using Uint8Range = OperandRange<0, 255>;
33 using Uint8RangeExcludingZero = OperandRange<1, 255>;
34 
35 template <typename tLhsRange, typename tRhsRange>
36 struct BitDepthParams {
37   using LhsRange = tLhsRange;
38   using RhsRange = tRhsRange;
39 };
40 
41 // Default: LHS and RHS are 8bit.
42 using DefaultL8R8BitDepthParams = BitDepthParams<Uint8Range, Uint8Range>;
43 
44 // Variant: LHS may not take the value 0. This allows using
45 // faster kernels using signed arithmetic, see
46 // NEON_64bit_GEMM_Int8Operands_Int32Accumulators_AccumTwoWithin16Bits
47 using L8R8WithLhsNonzeroBitDepthParams =
48     BitDepthParams<Uint8RangeExcludingZero, Uint8Range>;
49 
50 // Deprecated: when gemmlowp used to allow requantizing 8bit
51 // inputs to less-than-8-bit depths, the public setting allowing
52 // that was DefaultL7R5BitDepthParams. That requantization
53 // feature has been removed, but as the whole point of that
54 // requantization was to make less-than-8-bit an internal
55 // optimization without any impact on the API (other than lowering
56 // accuracy), we can temporarily support users who were using it
57 // by mapping it to the default 8bit behavior.
58 using DefaultL7R5BitDepthParams = DefaultL8R8BitDepthParams;
59 
60 }  // namespace gemmlowp
61 
62 #endif  // GEMMLOWP_PUBLIC_BIT_DEPTH_H_
63