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