Skip to content

Commit 0daf18c

Browse files
committed
Detect availability of AVX512-VNNI
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 15200c6 commit 0daf18c

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/arch/simddetect.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#endif
4242

4343
#if defined(HAVE_AVX) || defined(HAVE_AVX2) || defined(HAVE_FMA) || defined(HAVE_SSE4_1)
44+
// See https://en.wikipedia.org/wiki/CPUID.
4445
# define HAS_CPUID
4546
#endif
4647

@@ -94,6 +95,7 @@ bool SIMDDetect::avx_available_;
9495
bool SIMDDetect::avx2_available_;
9596
bool SIMDDetect::avx512F_available_;
9697
bool SIMDDetect::avx512BW_available_;
98+
bool SIMDDetect::avx512VNNI_available_;
9799
// If true, then FMA has been detected.
98100
bool SIMDDetect::fma_available_;
99101
// If true, then SSe4.1 has been detected.
@@ -171,6 +173,7 @@ SIMDDetect::SIMDDetect() {
171173
avx2_available_ = (ebx & 0x00000020) != 0;
172174
avx512F_available_ = (ebx & 0x00010000) != 0;
173175
avx512BW_available_ = (ebx & 0x40000000) != 0;
176+
avx512VNNI_available_ = (ecx & 0x00000800) != 0;
174177
}
175178
# endif
176179
}
@@ -201,6 +204,7 @@ SIMDDetect::SIMDDetect() {
201204
avx2_available_ = (cpuInfo[1] & 0x00000020) != 0;
202205
avx512F_available_ = (cpuInfo[1] & 0x00010000) != 0;
203206
avx512BW_available_ = (cpuInfo[1] & 0x40000000) != 0;
207+
avx512VNNI_available_ = (cpuInfo[2] & 0x00000800) != 0;
204208
}
205209
# endif
206210
}

src/arch/simddetect.h

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class SIMDDetect {
4747
static inline bool IsAVX512BWAvailable() {
4848
return detector.avx512BW_available_;
4949
}
50+
// Returns true if AVX512 Vector Neural Network Instructions are available.
51+
static inline bool IsAVX512VNNIAvailable() {
52+
return detector.avx512VNNI_available_;
53+
}
5054
// Returns true if FMA is available on this system.
5155
static inline bool IsFMAAvailable() {
5256
return detector.fma_available_;
@@ -75,6 +79,7 @@ class SIMDDetect {
7579
static TESS_API bool avx2_available_;
7680
static TESS_API bool avx512F_available_;
7781
static TESS_API bool avx512BW_available_;
82+
static TESS_API bool avx512VNNI_available_;
7883
// If true, then FMA has been detected.
7984
static TESS_API bool fma_available_;
8085
// If true, then SSe4.1 has been detected.

src/tesseract.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ static void PrintVersionInfo() {
149149
if (tesseract::SIMDDetect::IsAVX512FAvailable()) {
150150
printf(" Found AVX512F\n");
151151
}
152+
if (tesseract::SIMDDetect::IsAVX512VNNIAvailable()) {
153+
printf(" Found AVX512VNNI\n");
154+
}
152155
if (tesseract::SIMDDetect::IsAVX2Available()) {
153156
printf(" Found AVX2\n");
154157
}

0 commit comments

Comments
 (0)