Use SIMD instructions for DotProductNative

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-07-14 19:07:05 +02:00
parent 12e0fb4e01
commit f0fb6809e3
3 changed files with 9 additions and 1 deletions

View File

@ -144,6 +144,9 @@ noinst_HEADERS += src/arch/simddetect.h
noinst_LTLIBRARIES += libtesseract_native.la noinst_LTLIBRARIES += libtesseract_native.la
libtesseract_native_la_CXXFLAGS = -O3 -ffast-math libtesseract_native_la_CXXFLAGS = -O3 -ffast-math
if OPENMP_SIMD
libtesseract_native_la_CXXFLAGS += -fopenmp-simd -DOPENMP_SIMD
endif
if MARCH_NATIVE_OPT if MARCH_NATIVE_OPT
libtesseract_native_la_CXXFLAGS += -march=native -mtune=native libtesseract_native_la_CXXFLAGS += -march=native -mtune=native
endif endif

View File

@ -186,6 +186,8 @@ esac
AX_CHECK_COMPILE_FLAG([-march=native], [arch_native=true], [arch_native=false], [$WERROR]) AX_CHECK_COMPILE_FLAG([-march=native], [arch_native=true], [arch_native=false], [$WERROR])
AM_CONDITIONAL([MARCH_NATIVE_OPT], $arch_native) AM_CONDITIONAL([MARCH_NATIVE_OPT], $arch_native)
AX_CHECK_COMPILE_FLAG([-fopenmp-simd], [openmp_simd=true], [openmp_simd=false], [$WERROR])
AM_CONDITIONAL([OPENMP_SIMD], $openmp_simd)
AC_ARG_WITH([extra-includes], AC_ARG_WITH([extra-includes],
[AS_HELP_STRING([--with-extra-includes=DIR], [AS_HELP_STRING([--with-extra-includes=DIR],
@ -284,7 +286,7 @@ m4_define([MY_CHECK_FRAMEWORK],
]) ])
if test "$my_cv_framework_$1"="yes"; then if test "$my_cv_framework_$1"="yes"; then
AC_DEFINE(AS_TR_CPP([HAVE_FRAMEWORK_$1]), 1, AC_DEFINE(AS_TR_CPP([HAVE_FRAMEWORK_$1]), 1,
[Define if you have the $1 framework]) [Define if you have the $1 framework])
AS_TR_CPP([FRAMEWORK_$1])="-framework $1" AS_TR_CPP([FRAMEWORK_$1])="-framework $1"
AC_SUBST(AS_TR_CPP([FRAMEWORK_$1])) AC_SUBST(AS_TR_CPP([FRAMEWORK_$1]))
fi] fi]

View File

@ -21,6 +21,9 @@ namespace tesseract {
// Computes and returns the dot product of the two n-vectors u and v. // Computes and returns the dot product of the two n-vectors u and v.
double DotProductNative(const double *u, const double *v, int n) { double DotProductNative(const double *u, const double *v, int n) {
double total = 0.0; double total = 0.0;
#if defined(OPENMP_SIMD)
#pragma omp simd reduction(+:total)
#endif
for (int k = 0; k < n; ++k) { for (int k = 0; k < n; ++k) {
total += u[k] * v[k]; total += u[k] * v[k];
} }