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