Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add framework for implementation of support for AVX512VNNI #3894

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ libtesseract_la_LIBADD += libtesseract_avx512.la
noinst_LTLIBRARIES += libtesseract_avx512.la
endif

if HAVE_AVX512VNNI
libtesseract_avx512vnni_la_CXXFLAGS = -mavx512vnni -mavx512vl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious: what is the use of -mavx512vl? Should it be checked in configure, too?

Copy link
Collaborator

@amitdo amitdo Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not compile without the second flag. It is needed because the code uses ymm registers (256 bit) instead of zmm registers (512 bit).

Yes, we can also add another check in configure.

Note that AFAIK all Intel's CPUs that support AVX512VNNI also support AVXVL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining. Maybe we don't need the additional check then.

libtesseract_avx512vnni_la_CXXFLAGS += -I$(top_srcdir)/src/ccutil
libtesseract_avx512vnni_la_SOURCES = src/arch/intsimdmatrixavx512vnni.cpp
libtesseract_la_LIBADD += libtesseract_avx512vnni.la
noinst_LTLIBRARIES += libtesseract_avx512vnni.la
endif

if HAVE_FMA
libtesseract_fma_la_CXXFLAGS = -mfma
libtesseract_fma_la_CXXFLAGS += -I$(top_srcdir)/src/ccutil
Expand Down
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ AX_CHECK_COMPILE_FLAG([-Werror=unused-command-line-argument], [WERROR=-Werror=un
AM_CONDITIONAL([HAVE_AVX], false)
AM_CONDITIONAL([HAVE_AVX2], false)
AM_CONDITIONAL([HAVE_AVX512F], false)
AM_CONDITIONAL([HAVE_AVX512VNNI], false)
AM_CONDITIONAL([HAVE_FMA], false)
AM_CONDITIONAL([HAVE_SSE4_1], false)
AM_CONDITIONAL([HAVE_NEON], false)
Expand All @@ -156,6 +157,12 @@ case "${host_cpu}" in
AC_DEFINE([HAVE_AVX512F], [1], [Enable AVX512F instructions])
fi

AX_CHECK_COMPILE_FLAG([-mavx512vnni], [avx512vnni=true], [avx512vnni=false], [$WERROR])
AM_CONDITIONAL([HAVE_AVX512VNNI], $avx512vnni)
if $avx512vnni; then
AC_DEFINE([HAVE_AVX512VNNI], [1], [Enable AVX512VNNI instructions])
fi

AX_CHECK_COMPILE_FLAG([-mfma], [fma=true], [fma=false], [$WERROR])
AM_CONDITIONAL([HAVE_FMA], $fma)
if $fma; then
Expand Down
1 change: 1 addition & 0 deletions src/arch/intsimdmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct TESS_API IntSimdMatrix {
static const IntSimdMatrix intSimdMatrixNEON;
// Only available with AVX2 / AVX / FMA / SSE.
static const IntSimdMatrix intSimdMatrixAVX2;
static const IntSimdMatrix intSimdMatrixAVX512VNNI;
static const IntSimdMatrix intSimdMatrixSSE;
};

Expand Down
Loading