/src/tesseract/src/arch/simddetect.h
Line | Count | Source |
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. |
16 | | /////////////////////////////////////////////////////////////////////// |
17 | | #ifndef TESSERACT_ARCH_SIMDDETECT_H_ |
18 | | #define TESSERACT_ARCH_SIMDDETECT_H_ |
19 | | |
20 | | #include <tesseract/export.h> |
21 | | #include "tesstypes.h" |
22 | | |
23 | | namespace tesseract { |
24 | | |
25 | | // Function pointer for best calculation of dot product. |
26 | | using DotProductFunction = TFloat (*)(const TFloat *, const TFloat *, int); |
27 | | extern DotProductFunction DotProduct; |
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. |
32 | | class SIMDDetect { |
33 | | public: |
34 | | // Returns true if AVX is available on this system. |
35 | 0 | static inline bool IsAVXAvailable() { |
36 | 0 | return detector.avx_available_; |
37 | 0 | } |
38 | | // Returns true if AVX2 (integer support) is available on this system. |
39 | 0 | static inline bool IsAVX2Available() { |
40 | 0 | return detector.avx2_available_; |
41 | 0 | } |
42 | | // Returns true if AVX512 Foundation (float) is available on this system. |
43 | 0 | static inline bool IsAVX512FAvailable() { |
44 | 0 | return detector.avx512F_available_; |
45 | 0 | } |
46 | | // Returns true if AVX512 integer is available on this system. |
47 | 0 | static inline bool IsAVX512BWAvailable() { |
48 | 0 | return detector.avx512BW_available_; |
49 | 0 | } |
50 | | // Returns true if AVX512 Vector Neural Network Instructions are available. |
51 | 0 | static inline bool IsAVX512VNNIAvailable() { |
52 | 0 | return detector.avx512VNNI_available_; |
53 | 0 | } |
54 | | // Returns true if FMA is available on this system. |
55 | 0 | static inline bool IsFMAAvailable() { |
56 | 0 | return detector.fma_available_; |
57 | 0 | } |
58 | | // Returns true if SSE4.1 is available on this system. |
59 | 0 | static inline bool IsSSEAvailable() { |
60 | 0 | return detector.sse_available_; |
61 | 0 | } |
62 | | // Returns true if NEON is available on this system. |
63 | 0 | static inline bool IsNEONAvailable() { |
64 | 0 | return detector.neon_available_; |
65 | 0 | } |
66 | | // Returns true if RVV is available on this system. |
67 | 0 | static inline bool IsRVVAvailable() { |
68 | 0 | return detector.rvv_available_; |
69 | 0 | } |
70 | | |
71 | | // Update settings after config variable was set. |
72 | | static TESS_API void Update(); |
73 | | |
74 | | private: |
75 | | // Constructor, must set all static member variables. |
76 | | SIMDDetect(); |
77 | | |
78 | | private: |
79 | | // Singleton. |
80 | | static SIMDDetect detector; |
81 | | // If true, then AVX has been detected. |
82 | | static TESS_API bool avx_available_; |
83 | | static TESS_API bool avx2_available_; |
84 | | static TESS_API bool avx512F_available_; |
85 | | static TESS_API bool avx512BW_available_; |
86 | | static TESS_API bool avx512VNNI_available_; |
87 | | // If true, then FMA has been detected. |
88 | | static TESS_API bool fma_available_; |
89 | | // If true, then SSe4.1 has been detected. |
90 | | static TESS_API bool sse_available_; |
91 | | // If true, then NEON has been detected. |
92 | | static TESS_API bool neon_available_; |
93 | | // If true, then RVV has been detected. |
94 | | static TESS_API bool rvv_available_; |
95 | | }; |
96 | | |
97 | | } // namespace tesseract |
98 | | |
99 | | #endif // TESSERACT_ARCH_SIMDDETECT_H_ |