tesseract v5.3.3.20231005
simddetect.h
Go to the documentation of this file.
1
2// File: simddetect.h
3// Description: Architecture detector.
4// Author: Stefan Weil (based on code from Ray Smith)
5//
6// (C) Copyright 2014, Google Inc.
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10// http://www.apache.org/licenses/LICENSE-2.0
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
17#ifndef TESSERACT_ARCH_SIMDDETECT_H_
18#define TESSERACT_ARCH_SIMDDETECT_H_
19
20#include <tesseract/export.h>
21#include "tesstypes.h"
22
23namespace tesseract {
24
25// Function pointer for best calculation of dot product.
26using DotProductFunction = TFloat (*)(const TFloat *, const TFloat *, int);
28
29// Architecture detector. Add code here to detect any other architectures for
30// SIMD-based faster dot product functions. Intended to be a single static
31// object, but it does no real harm to have more than one.
33public:
34 // Returns true if AVX is available on this system.
35 static inline bool IsAVXAvailable() {
36 return detector.avx_available_;
37 }
38 // Returns true if AVX2 (integer support) is available on this system.
39 static inline bool IsAVX2Available() {
40 return detector.avx2_available_;
41 }
42 // Returns true if AVX512 Foundation (float) is available on this system.
43 static inline bool IsAVX512FAvailable() {
44 return detector.avx512F_available_;
45 }
46 // Returns true if AVX512 integer is available on this system.
47 static inline bool IsAVX512BWAvailable() {
48 return detector.avx512BW_available_;
49 }
50 // Returns true if AVX512 Vector Neural Network Instructions are available.
51 static inline bool IsAVX512VNNIAvailable() {
52 return detector.avx512VNNI_available_;
53 }
54 // Returns true if FMA is available on this system.
55 static inline bool IsFMAAvailable() {
56 return detector.fma_available_;
57 }
58 // Returns true if SSE4.1 is available on this system.
59 static inline bool IsSSEAvailable() {
60 return detector.sse_available_;
61 }
62 // Returns true if NEON is available on this system.
63 static inline bool IsNEONAvailable() {
64 return detector.neon_available_;
65 }
66
67 // Update settings after config variable was set.
68 static TESS_API void Update();
69
70private:
71 // Constructor, must set all static member variables.
72 SIMDDetect();
73
74private:
75 // Singleton.
76 static SIMDDetect detector;
77 // If true, then AVX has been detected.
78 static TESS_API bool avx_available_;
79 static TESS_API bool avx2_available_;
80 static TESS_API bool avx512F_available_;
81 static TESS_API bool avx512BW_available_;
82 static TESS_API bool avx512VNNI_available_;
83 // If true, then FMA has been detected.
84 static TESS_API bool fma_available_;
85 // If true, then SSe4.1 has been detected.
86 static TESS_API bool sse_available_;
87 // If true, then NEON has been detected.
88 static TESS_API bool neon_available_;
89};
90
91} // namespace tesseract
92
93#endif // TESSERACT_ARCH_SIMDDETECT_H_
TFloat(*)(const TFloat *, const TFloat *, int) DotProductFunction
Definition: simddetect.h:26
DotProductFunction DotProduct
Definition: simddetect.cpp:80
double TFloat
Definition: tesstypes.h:39
static bool IsNEONAvailable()
Definition: simddetect.h:63
static bool IsAVX512BWAvailable()
Definition: simddetect.h:47
static bool IsFMAAvailable()
Definition: simddetect.h:55
static bool IsAVXAvailable()
Definition: simddetect.h:35
static bool IsAVX512VNNIAvailable()
Definition: simddetect.h:51
static bool IsAVX512FAvailable()
Definition: simddetect.h:43
static bool IsSSEAvailable()
Definition: simddetect.h:59
static bool IsAVX2Available()
Definition: simddetect.h:39
static TESS_API void Update()
Definition: simddetect.cpp:272
#define TESS_API
Definition: export.h:32