tesseract  5.0.0-alpha-619-ge9db
simddetect.h
Go to the documentation of this file.
1 // 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/platform.h>
21 
22 namespace tesseract {
23 
24 // Function pointer for best calculation of dot product.
25 using DotProductFunction = double (*)(const double*, const double*, int);
27 
28 // Architecture detector. Add code here to detect any other architectures for
29 // SIMD-based faster dot product functions. Intended to be a single static
30 // object, but it does no real harm to have more than one.
31 class SIMDDetect {
32  public:
33  // Returns true if AVX is available on this system.
34  static inline bool IsAVXAvailable() {
35  return detector.avx_available_;
36  }
37  // Returns true if AVX2 (integer support) is available on this system.
38  static inline bool IsAVX2Available() {
39  return detector.avx2_available_;
40  }
41  // Returns true if AVX512 Foundation (float) is available on this system.
42  static inline bool IsAVX512FAvailable() {
43  return detector.avx512F_available_;
44  }
45  // Returns true if AVX512 integer is available on this system.
46  static inline bool IsAVX512BWAvailable() {
47  return detector.avx512BW_available_;
48  }
49  // Returns true if FMA is available on this system.
50  static inline bool IsFMAAvailable() {
51  return detector.fma_available_;
52  }
53  // Returns true if SSE4.1 is available on this system.
54  static inline bool IsSSEAvailable() {
55  return detector.sse_available_;
56  }
57 
58  // Update settings after config variable was set.
59  static TESS_API void Update();
60 
61  private:
62  // Constructor, must set all static member variables.
63  SIMDDetect();
64 
65  private:
66  // Singleton.
67  static SIMDDetect detector;
68  // If true, then AVX has been detected.
69  static TESS_API bool avx_available_;
70  static TESS_API bool avx2_available_;
71  static TESS_API bool avx512F_available_;
72  static TESS_API bool avx512BW_available_;
73  // If true, then FMA has been detected.
74  static TESS_API bool fma_available_;
75  // If true, then SSe4.1 has been detected.
76  static TESS_API bool sse_available_;
77 };
78 
79 } // namespace tesseract
80 
81 #endif // TESSERACT_ARCH_SIMDDETECT_H_
tesseract::SIMDDetect::IsAVX512FAvailable
static bool IsAVX512FAvailable()
Definition: simddetect.h:42
platform.h
tesseract::SIMDDetect
Definition: simddetect.h:31
tesseract::SIMDDetect::IsAVX512BWAvailable
static bool IsAVX512BWAvailable()
Definition: simddetect.h:46
tesseract::SIMDDetect::IsAVX2Available
static bool IsAVX2Available()
Definition: simddetect.h:38
tesstrain_utils.int
int
Definition: tesstrain_utils.py:154
tesseract::SIMDDetect::IsAVXAvailable
static bool IsAVXAvailable()
Definition: simddetect.h:34
tesseract::DotProduct
DotProductFunction DotProduct
Definition: simddetect.cpp:50
tesseract::SIMDDetect::IsFMAAvailable
static bool IsFMAAvailable()
Definition: simddetect.h:50
tesseract::DotProductFunction
double(*)(const double *, const double *, int) DotProductFunction
Definition: simddetect.h:25
tesseract
Definition: baseapi.h:65
TESS_API
#define TESS_API
Definition: platform.h:54
tesseract::SIMDDetect::Update
static TESS_API void Update()
Definition: simddetect.cpp:174
tesseract::SIMDDetect::IsSSEAvailable
static bool IsSSEAvailable()
Definition: simddetect.h:54