Skip to content

Commit

Permalink
Implement fast float dotproduct for SSE IntSimdMatrix
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jul 14, 2021
1 parent 8ab9388 commit 13829cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ endif
if HAVE_SSE4_1
libtesseract_sse_la_CXXFLAGS = -msse4.1
libtesseract_sse_la_CXXFLAGS += -I$(top_srcdir)/src/ccutil
if OPENMP_SIMD
libtesseract_sse_la_CXXFLAGS += -fopenmp-simd -DOPENMP_SIMD
endif
libtesseract_sse_la_SOURCES = src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp
libtesseract_la_LIBADD += libtesseract_sse.la
noinst_LTLIBRARIES += libtesseract_sse.la
Expand Down
31 changes: 30 additions & 1 deletion src/arch/intsimdmatrixsse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,36 @@
# endif
#elif defined(FAST_FLOAT)
namespace tesseract {
const IntSimdMatrix *IntSimdMatrix::intSimdMatrixSSE = nullptr;
static void matrixDotVector(int dim1, int dim2, const int8_t *wi, const float *scales,
const int8_t *u, float *v) {
const int num_out = dim1;
const int num_in = dim2 - 1;
//#pragma omp simd collapse(2)
for (int i = 0; i < num_out; ++i) {
int total = 0;
#pragma omp simd reduction(+:total)
for (int j = 0; j < num_in; ++j) {
total += wi[j] * u[j];
}
// Add in the bias and correct for integer values.
v[i] = (total + wi[num_in] * INT8_MAX) * scales[i];
wi += dim2;
}
}

static const IntSimdMatrix simdMatrix = {
matrixDotVector,
// Number of 32 bit outputs held in each register.
1,
// Maximum number of registers that we will use to hold outputs.
1,
// Number of 8 bit inputs in the inputs register.
1,
// Number of inputs in each weight group.
1
};

const IntSimdMatrix *IntSimdMatrix::intSimdMatrixSSE = &simdMatrix;
}
#else

Expand Down

0 comments on commit 13829cd

Please sign in to comment.