Skip to content

Commit

Permalink
Detect availability of AVX512-VNNI
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Aug 6, 2022
1 parent 15200c6 commit 0daf18c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/arch/simddetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#endif

#if defined(HAVE_AVX) || defined(HAVE_AVX2) || defined(HAVE_FMA) || defined(HAVE_SSE4_1)
// See https://en.wikipedia.org/wiki/CPUID.
# define HAS_CPUID
#endif

Expand Down Expand Up @@ -94,6 +95,7 @@ bool SIMDDetect::avx_available_;
bool SIMDDetect::avx2_available_;
bool SIMDDetect::avx512F_available_;
bool SIMDDetect::avx512BW_available_;
bool SIMDDetect::avx512VNNI_available_;
// If true, then FMA has been detected.
bool SIMDDetect::fma_available_;
// If true, then SSe4.1 has been detected.
Expand Down Expand Up @@ -171,6 +173,7 @@ SIMDDetect::SIMDDetect() {
avx2_available_ = (ebx & 0x00000020) != 0;
avx512F_available_ = (ebx & 0x00010000) != 0;
avx512BW_available_ = (ebx & 0x40000000) != 0;
avx512VNNI_available_ = (ecx & 0x00000800) != 0;
}
# endif
}
Expand Down Expand Up @@ -201,6 +204,7 @@ SIMDDetect::SIMDDetect() {
avx2_available_ = (cpuInfo[1] & 0x00000020) != 0;
avx512F_available_ = (cpuInfo[1] & 0x00010000) != 0;
avx512BW_available_ = (cpuInfo[1] & 0x40000000) != 0;
avx512VNNI_available_ = (cpuInfo[2] & 0x00000800) != 0;
}
# endif
}
Expand Down
5 changes: 5 additions & 0 deletions src/arch/simddetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class SIMDDetect {
static inline bool IsAVX512BWAvailable() {
return detector.avx512BW_available_;
}
// Returns true if AVX512 Vector Neural Network Instructions are available.
static inline bool IsAVX512VNNIAvailable() {
return detector.avx512VNNI_available_;
}
// Returns true if FMA is available on this system.
static inline bool IsFMAAvailable() {
return detector.fma_available_;
Expand Down Expand Up @@ -75,6 +79,7 @@ class SIMDDetect {
static TESS_API bool avx2_available_;
static TESS_API bool avx512F_available_;
static TESS_API bool avx512BW_available_;
static TESS_API bool avx512VNNI_available_;
// If true, then FMA has been detected.
static TESS_API bool fma_available_;
// If true, then SSe4.1 has been detected.
Expand Down
3 changes: 3 additions & 0 deletions src/tesseract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ static void PrintVersionInfo() {
if (tesseract::SIMDDetect::IsAVX512FAvailable()) {
printf(" Found AVX512F\n");
}
if (tesseract::SIMDDetect::IsAVX512VNNIAvailable()) {
printf(" Found AVX512VNNI\n");
}
if (tesseract::SIMDDetect::IsAVX2Available()) {
printf(" Found AVX2\n");
}
Expand Down

0 comments on commit 0daf18c

Please sign in to comment.