aboutsummaryrefslogtreecommitdiff
path: root/eight_bit_int_gemm/eight_bit_int_gemm.h
blob: 37586bdaa05ad3cae4af89b710def27035fda773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// eight_bit_int_gemm.h: exposes the standard EightBitIntGemm interface.

#ifndef GEMMLOWP_EIGHT_BIT_INT_GEMM_EIGHT_BIT_INT_GEMM_H_
#define GEMMLOWP_EIGHT_BIT_INT_GEMM_EIGHT_BIT_INT_GEMM_H_

#ifndef GEMMLOWP_USE_OLD_ANDROID_SDK
#include <cstdint>
#else
#include <stdint.h>
namespace std {
using ::uint8_t;
using ::int32_t;
using ::int64_t;
}
#endif

namespace gemmlowp {

namespace eight_bit_int_gemm {

// Concurrency / reentrancy notice
// ===============================
//
// This eight_bit_int_gemm has global singleton persistent state.
// A global lock ensures serialization of calls, so this library
// is fully reentrant but only one calling thread gets to actually run
// at a time, while other calling threads would wait. So it is safe
// albeit potentially slow to call the functions exposed here on
// multiple threads concurrently.
//
// Users who prefer a state-less, singleton-less interface,
// should use the main gemmlowp interface (public/gemmlowp.h) instead.

// The main entry point to compute a Gemm. This is the standard
enum class BitDepthSetting {
  A8B8,  // 8-bit a, 8-bit b
  A5B7   // 5-bit a, 7-bit b
};

// The main entry point to compute a Gemm. This is the standard
// EightBitIntGemm interface.
void EightBitIntGemm(bool transpose_a, bool transpose_b, bool transpose_c,
                     int m, int n, int k, const std::uint8_t *a,
                     std::int32_t a_offset, int lda, const std::uint8_t *b,
                     std::int32_t b_offset, int ldb, std::uint8_t *c,
                     std::int32_t c_offset, std::int32_t c_mult_int,
                     std::int32_t c_shift, int ldc, BitDepthSetting bit_depth);

// Frees any persistent resources
// (threads, thread pools, allocators, buffers, ...)
// that gemmlowp might hold. This is called automatically
// on thread exit, but one may also call it earlier, at any time.
void FreePersistentResources();

// Allows specifying the number of hardware threads, as a hint as to
// how many worker threads to use for sufficiently large Gemm's.
// We will never use more threads than that, but may use fewer,
// for instance on Gemm's that are too small to benefit from all
// available threads. The value 0 lets the implementation query
// the system to determine the number of hardware threads.
// Default value: 0.
void SetMaxNumThreads(int n);

}  // namespace eight_bit_int_gemm

}  // namespace gemmlowp

#endif  // GEMMLOWP_EIGHT_BIT_INT_GEMM_EIGHT_BIT_INT_GEMM_H_