• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 Google Inc. 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 // eight_bit_int_gemm.h: exposes the standard EightBitIntGemm interface.
16 
17 #ifndef GEMMLOWP_EIGHT_BIT_INT_GEMM_EIGHT_BIT_INT_GEMM_H_
18 #define GEMMLOWP_EIGHT_BIT_INT_GEMM_EIGHT_BIT_INT_GEMM_H_
19 
20 #ifndef GEMMLOWP_USE_STLPORT
21 #include <cstdint>
22 #else
23 #include <stdint.h>
24 namespace std {
25 using ::uint8_t;
26 using ::int32_t;
27 }
28 #endif
29 
30 namespace gemmlowp {
31 
32 namespace eight_bit_int_gemm {
33 
34 // Concurrency / reentrancy notice
35 // ===============================
36 //
37 // This eight_bit_int_gemm has global singleton persistent state.
38 // A global lock ensures serialization of calls, so this library
39 // is fully reentrant but only one calling thread gets to actually run
40 // at a time, while other calling threads would wait. So it is safe
41 // albeit potentially slow to call the functions exposed here on
42 // multiple threads concurrently.
43 //
44 // Users who prefer a state-less, singleton-less interface,
45 // should use the main gemmlowp interface (public/gemmlowp.h) instead.
46 
47 // The BitDepthSetting enum lists supported a/b bit-depth combinations.
48 enum class BitDepthSetting {
49   A8B8,  // 8-bit a, 8-bit b
50   A5B7   // 5-bit a, 7-bit b
51 };
52 
53 // The main entry point to compute a Gemm. This is the standard
54 // EightBitIntGemm interface.
55 void EightBitIntGemm(bool transpose_a, bool transpose_b, bool transpose_c,
56                      int m, int n, int k, const std::uint8_t *a,
57                      std::int32_t a_offset, int lda, const std::uint8_t *b,
58                      std::int32_t b_offset, int ldb, std::uint8_t *c,
59                      std::int32_t c_offset, std::int32_t c_mult_int,
60                      std::int32_t c_shift, int ldc, BitDepthSetting bit_depth);
61 
62 void EightBitIntGemm(bool transpose_a, bool transpose_b, bool transpose_c,
63                      int m, int n, int k, const std::uint8_t *a,
64                      std::int32_t a_offset, int lda, const std::uint8_t *b,
65                      std::int32_t b_offset, int ldb, float *c, float c_offset,
66                      int ldc, BitDepthSetting bit_depth);
67 
68 // Frees any persistent resources
69 // (threads, thread pools, allocators, buffers, ...)
70 // that gemmlowp might hold. This is called automatically
71 // on thread exit, but one may also call it earlier, at any time.
72 void FreePersistentResources();
73 
74 // Allows specifying the number of hardware threads, as a hint as to
75 // how many worker threads to use for sufficiently large Gemm's.
76 // We will never use more threads than that, but may use fewer,
77 // for instance on Gemm's that are too small to benefit from all
78 // available threads. The value 0 lets the implementation query
79 // the system to determine the number of hardware threads.
80 // Default value: 0.
81 void SetMaxNumThreads(int n);
82 
83 }  // namespace eight_bit_int_gemm
84 
85 }  // namespace gemmlowp
86 
87 #endif  // GEMMLOWP_EIGHT_BIT_INT_GEMM_EIGHT_BIT_INT_GEMM_H_
88