Skip to content

Commit

Permalink
Remove unsupported OpenCL code and related API functions (#4220)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Apr 11, 2024
1 parent 912deb3 commit d5e000b
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 3,900 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ __pycache__
*.traineddata
tessdata_*

# OpenCL
tesseract_opencl_profile_devices.dat
kernel*.bin

# build dirs
/build*
/*.dll
Expand Down
24 changes: 0 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ option(GRAPHICS_DISABLED "Disable disable graphics (ScrollView)" OFF)
option(DISABLED_LEGACY_ENGINE "Disable the legacy OCR engine" OFF)
option(ENABLE_LTO "Enable link-time optimization" OFF)
option(FAST_FLOAT "Enable float for LSTM" ON)
option(ENABLE_OPENCL "Enable unsupported experimental OpenCL support" OFF)
option(ENABLE_NATIVE
"Enable optimization for host CPU (could break HW compatibility)" OFF)
# see
Expand Down Expand Up @@ -460,18 +459,6 @@ else()
endif(DISABLE_CURL)
endif()

if(ENABLE_OPENCL)
find_package(OpenCL)
if(OpenCL_FOUND)
include_directories(${OpenCL_INCLUDE_DIRS})
message(STATUS "OpenCL_INCLUDE_DIRS: ${OpenCL_INCLUDE_DIRS}")
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
set(USE_OPENCL ON)
else()
set(USE_OPENCL OFF)
endif(OpenCL_FOUND)
endif(ENABLE_OPENCL)

# ##############################################################################
#
# configure
Expand Down Expand Up @@ -565,11 +552,6 @@ message(STATUS "Disable the legacy OCR engine [DISABLED_LEGACY_ENGINE]: "
message(STATUS "Build training tools [BUILD_TRAINING_TOOLS]: "
"${BUILD_TRAINING_TOOLS}")
message(STATUS "Build tests [BUILD_TESTS]: ${BUILD_TESTS}")
if(ENABLE_OPENCL)
message(
STATUS
"Enable unsupported experimental OpenCL [ENABLE_OPENCL]: ${USE_OPENCL}")
endif(ENABLE_OPENCL)
message(STATUS "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}")
message(
STATUS "Install tesseract configs [INSTALL_CONFIGS]: ${INSTALL_CONFIGS}")
Expand Down Expand Up @@ -608,7 +590,6 @@ file(
src/cutil/*.cpp
src/dict/*.cpp
src/lstm/*.cpp
src/opencl/*.cpp
src/textord/*.cpp
src/viewer/*.cpp
src/wordrec/*.cpp)
Expand Down Expand Up @@ -749,7 +730,6 @@ file(
src/cutil/*.h
src/dict/*.h
src/lstm/*.h
src/opencl/*.h
src/textord/*.h
src/viewer/*.h
src/wordrec/*.h)
Expand Down Expand Up @@ -816,7 +796,6 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/cutil>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/dict>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/lstm>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/opencl>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/textord>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/viewer>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/wordrec>
Expand All @@ -832,9 +811,6 @@ target_link_libraries(libtesseract PRIVATE ${LIB_Ws2_32} ${LIB_pthread})
if(OpenMP_CXX_FOUND)
target_link_libraries(libtesseract PUBLIC OpenMP::OpenMP_CXX)
endif()
if(OpenCL_FOUND)
target_link_libraries(libtesseract PUBLIC OpenCL::OpenCL)
endif()
if(LibArchive_FOUND)
target_link_libraries(libtesseract PUBLIC ${LibArchive_LIBRARIES})
endif(LibArchive_FOUND)
Expand Down
37 changes: 4 additions & 33 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ if VISIBILITY
AM_CPPFLAGS += -DTESS_EXPORTS
AM_CPPFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden -fPIC
endif
AM_CPPFLAGS += $(OPENCL_CPPFLAGS)

AM_CXXFLAGS = $(OPENMP_CXXFLAGS)

Expand All @@ -94,17 +93,14 @@ libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/classify
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/cutil
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/dict
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/lstm
if OPENCL
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/opencl
endif
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/textord
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/training/common
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/viewer
libtesseract_la_CPPFLAGS += -I$(top_srcdir)/src/wordrec
libtesseract_la_CPPFLAGS += $(libcurl_CFLAGS)

lib_LTLIBRARIES = libtesseract.la
libtesseract_la_LDFLAGS = $(LEPTONICA_LIBS) $(OPENCL_LDFLAGS)
libtesseract_la_LDFLAGS = $(LEPTONICA_LIBS)
libtesseract_la_LDFLAGS += $(libarchive_LIBS)
libtesseract_la_LDFLAGS += $(libcurl_LIBS)
libtesseract_la_LDFLAGS += $(TENSORFLOW_LIBS)
Expand All @@ -127,9 +123,6 @@ libtesseract_la_SOURCES += src/api/wordstrboxrenderer.cpp
libtesseract_la_LIBADD = libtesseract_ccutil.la
libtesseract_la_LIBADD += libtesseract_lstm.la
libtesseract_la_LIBADD += libtesseract_native.la
if OPENCL
libtesseract_la_LIBADD += libtesseract_opencl.la
endif

# Rules for src/arch.

Expand Down Expand Up @@ -561,23 +554,6 @@ if TENSORFLOW
libtesseract_lstm_la_SOURCES += src/lstm/tfnetwork.pb.cc
endif

# Rules for src/opencl.

if OPENCL
libtesseract_opencl_la_CPPFLAGS = $(AM_CPPFLAGS)
libtesseract_opencl_la_CPPFLAGS += $(OPENCL_CFLAGS)
libtesseract_opencl_la_CPPFLAGS += -I$(top_srcdir)/src/ccutil
libtesseract_opencl_la_CPPFLAGS += -I$(top_srcdir)/src/ccstruct
libtesseract_opencl_la_CPPFLAGS += -I$(top_srcdir)/src/ccmain

noinst_HEADERS += src/opencl/openclwrapper.h
noinst_HEADERS += src/opencl/oclkernels.h

noinst_LTLIBRARIES += libtesseract_opencl.la

libtesseract_opencl_la_SOURCES = src/opencl/openclwrapper.cpp
endif

# Rules for src/textord.

noinst_HEADERS += src/textord/alignedblob.h
Expand Down Expand Up @@ -743,16 +719,12 @@ tesseract_CPPFLAGS += -I$(top_srcdir)/src/dict
tesseract_CPPFLAGS += -I$(top_srcdir)/src/textord
tesseract_CPPFLAGS += -I$(top_srcdir)/src/viewer
tesseract_CPPFLAGS += -I$(top_srcdir)/src/wordrec
if OPENCL
tesseract_CPPFLAGS += -I$(top_srcdir)/src/opencl
endif
tesseract_CPPFLAGS += $(AM_CPPFLAGS)
if VISIBILITY
tesseract_CPPFLAGS += -DTESS_IMPORTS
endif

tesseract_LDFLAGS = $(OPENCL_LDFLAGS)
tesseract_LDFLAGS += $(OPENMP_CXXFLAGS)
tesseract_LDFLAGS = $(OPENMP_CXXFLAGS)

tesseract_LDADD = libtesseract.la
tesseract_LDADD += $(LEPTONICA_LIBS)
Expand Down Expand Up @@ -927,7 +899,6 @@ EXTRA_PROGRAMS += $(trainingtools)
extralib = libtesseract.la
extralib += $(libarchive_LIBS)
extralib += $(LEPTONICA_LIBS)
extralib += $(OPENCL_LDFLAGS)
extralib += $(TENSORFLOW_LIBS)
if T_WIN
extralib += -lws2_32
Expand Down Expand Up @@ -1308,7 +1279,7 @@ TESTS = $(check_PROGRAMS)

apiexample_test_SOURCES = unittest/apiexample_test.cc
apiexample_test_CPPFLAGS = $(unittest_CPPFLAGS)
apiexample_test_LDFLAGS = $(OPENCL_LDFLAGS) $(LEPTONICA_LIBS)
apiexample_test_LDFLAGS = $(LEPTONICA_LIBS)
apiexample_test_LDADD = $(TESS_LIBS) $(LEPTONICA_LIBS)

if !DISABLED_LEGACY_ENGINE
Expand Down Expand Up @@ -1494,7 +1465,7 @@ endif # !DISABLED_LEGACY_ENGINE

progress_test_SOURCES = unittest/progress_test.cc
progress_test_CPPFLAGS = $(unittest_CPPFLAGS)
progress_test_LDFLAGS = $(OPENCL_LDFLAGS) $(LEPTONICA_LIBS)
progress_test_LDFLAGS = $(LEPTONICA_LIBS)
progress_test_LDADD = $(GTEST_LIBS) $(GMOCK_LIBS) $(TESS_LIBS) $(LEPTONICA_LIBS)

qrsequence_test_SOURCES = unittest/qrsequence_test.cc
Expand Down
3 changes: 0 additions & 3 deletions cmake/Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ set(include_files_list
unistd.h

cairo/cairo-version.h
CL/cl.h
OpenCL/cl.h
pango-1.0/pango/pango-features.h
unicode/uchar.h
)
Expand Down Expand Up @@ -121,7 +119,6 @@ file(APPEND ${AUTOCONFIG_SRC} "
#cmakedefine HAVE_NEON ${HAVE_NEON}
#cmakedefine HAVE_LIBARCHIVE ${HAVE_LIBARCHIVE}
#cmakedefine HAVE_LIBCURL ${HAVE_LIBCURL}
#cmakedefine USE_OPENCL ${USE_OPENCL}
")

if(TESSDATA_PREFIX)
Expand Down
1 change: 0 additions & 1 deletion cmake/SourceGroups.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ source_group("classify" "${SSRC}/classify/${H_CPP}")
source_group("cutil" "${SSRC}/cutil/${H_CPP}")
source_group("dict" "${SSRC}/dict/${H_CPP}")
source_group("lstm" "${SSRC}/lstm/${H_CPP}")
source_group("opencl" "${SSRC}/opencl/${H_CPP}")
source_group("textord" "${SSRC}/textord/${H_CPP}")
source_group("viewer" "${SSRC}/viewer/${H_CPP}")
source_group("wordrec" "${SSRC}/wordrec/${H_CPP}")
46 changes: 0 additions & 46 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ AC_SUBST([AM_CPPFLAGS])
# Can be overridden with `configure --disable-silent-rules` or with `make V=1`.
AM_SILENT_RULES([yes])

OPENCL_INC="/opt/AMDAPP/include"
OPENCL_LIBS="-lOpenCL"
#############################
#
# Platform specific setup
Expand All @@ -102,15 +100,12 @@ case "${host_os}" in
AM_CONDITIONAL([ADD_RT], true)
;;
*darwin*)
OPENCL_LIBS=""
OPENCL_INC=""
AM_CONDITIONAL([ADD_RT], false)
;;
*android*|openbsd*)
AM_CONDITIONAL([ADD_RT], false)
;;
powerpc-*-darwin*)
OPENCL_LIBS=""
;;
*)
# default
Expand Down Expand Up @@ -263,19 +258,6 @@ have_tiff=false
# Note that the first usage of AC_CHECK_HEADERS must be unconditional.
AC_CHECK_HEADERS([tiffio.h], [have_tiff=true], [have_tiff=false])
# check whether to build opencl version
AC_MSG_CHECKING([--enable-opencl argument])
AC_ARG_ENABLE([opencl],
AS_HELP_STRING([--enable-opencl], [enable opencl build [default=no]]))
AC_MSG_RESULT([$enable_opencl])
# check for opencl header
have_opencl=false
if test "$enable_opencl" = "yes"; then
AC_CHECK_HEADERS([CL/cl.h], [have_opencl=true], [
AC_CHECK_HEADERS(OpenCL/cl.h, [have_opencl=true], [have_opencl=false])
])
fi
# Configure arguments which allow disabling some optional libraries.
AC_ARG_WITH([archive],
AS_HELP_STRING([--with-archive],
Expand Down Expand Up @@ -323,46 +305,18 @@ m4_define([MY_CHECK_FRAMEWORK],
fi]
)
have_opencl_lib=false
OPENCL_CPPFLAGS=''
OPENCL_LDFLAGS=''
case "${host_os}" in
*darwin* | *-macos10*)
MY_CHECK_FRAMEWORK([Accelerate])
if test $my_cv_framework_Accelerate = yes; then
AM_CPPFLAGS="-DHAVE_FRAMEWORK_ACCELERATE $AM_CPPFLAGS"
AM_LDFLAGS="$AM_LDFLAGS -framework Accelerate"
fi
MY_CHECK_FRAMEWORK([OpenCL])
if test "$enable_opencl" = "yes"; then
if test $my_cv_framework_OpenCL = no; then
AC_MSG_ERROR([Required OpenCL library not found!])
fi
AM_CPPFLAGS="-DUSE_OPENCL $AM_CPPFLAGS"
OPENCL_CPPFLAGS=""
OPENCL_LDFLAGS="-framework OpenCL"
fi
;;
*)
# default
if test "$enable_opencl" = "yes"; then
AC_CHECK_LIB([OpenCL], [clGetPlatformIDs],
[have_opencl_lib=true], [have_opencl_lib=false])
if !($have_opencl); then
AC_MSG_ERROR([Required OpenCL headers not found!])
fi
if !($have_opencl_lib); then
AC_MSG_ERROR([Required OpenCL library not found!])
fi
AM_CPPFLAGS="-DUSE_OPENCL $AM_CPPFLAGS"
OPENCL_CPPFLAGS="-I${OPENCL_INC}"
OPENCL_LDFLAGS="${OPENCL_LIBS}"
fi
;;
esac
AM_CONDITIONAL([OPENCL], [test "$enable_opencl" = "yes"])
AC_SUBST([OPENCL_CPPFLAGS])
AC_SUBST([OPENCL_LDFLAGS])
# check whether to build tesseract with -fvisibility=hidden -fvisibility-inlines-hidden
# http://gcc.gnu.org/wiki/Visibility
Expand Down
9 changes: 0 additions & 9 deletions include/tesseract/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ class TESS_API TessBaseAPI {
*/
static const char *Version();

/**
* If compiled with OpenCL AND an available OpenCL
* device is deemed faster than serial code, then
* "device" is populated with the cl_device_id
* and returns sizeof(cl_device_id)
* otherwise *device=nullptr and returns 0.
*/
static size_t getOpenCLDevice(void **device);

/**
* Set the name of the input file. Needed for training and
* reading a UNLV zone file, and for searchable PDF output.
Expand Down
2 changes: 0 additions & 2 deletions include/tesseract/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ TESS_API int TessResultRendererImageNum(TessResultRenderer *renderer);
TESS_API TessBaseAPI *TessBaseAPICreate();
TESS_API void TessBaseAPIDelete(TessBaseAPI *handle);

TESS_API size_t TessBaseAPIGetOpenCLDevice(TessBaseAPI *handle, void **device);

TESS_API void TessBaseAPISetInputName(TessBaseAPI *handle, const char *name);
TESS_API const char *TessBaseAPIGetInputName(TessBaseAPI *handle);

Expand Down
28 changes: 0 additions & 28 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
#endif
#include "mutableiterator.h" // for MutableIterator
#include "normalis.h" // for kBlnBaselineOffset, kBlnXHeight
#if defined(USE_OPENCL)
# include "openclwrapper.h" // for OpenclDevice
#endif
#include "pageres.h" // for PAGE_RES_IT, WERD_RES, PAGE_RES, CR_DE...
#include "paragraphs.h" // for DetectParagraphs
#include "params.h" // for BoolParam, IntParam, DoubleParam, Stri...
Expand Down Expand Up @@ -243,27 +240,6 @@ const char *TessBaseAPI::Version() {
return TESSERACT_VERSION_STR;
}

/**
* If compiled with OpenCL AND an available OpenCL
* device is deemed faster than serial code, then
* "device" is populated with the cl_device_id
* and returns sizeof(cl_device_id)
* otherwise *device=nullptr and returns 0.
*/
size_t TessBaseAPI::getOpenCLDevice(void **data) {
#ifdef USE_OPENCL
ds_device device = OpenclDevice::getDeviceSelection();
if (device.type == DS_DEVICE_OPENCL_DEVICE) {
*data = new cl_device_id;
memcpy(*data, &device.oclDeviceID, sizeof(cl_device_id));
return sizeof(cl_device_id);
}
#endif

*data = nullptr;
return 0;
}

/**
* Set the name of the input file. Needed only for training and
* loading a UNLV zone file.
Expand Down Expand Up @@ -398,10 +374,6 @@ int TessBaseAPI::Init(const char *data, int data_size, const char *language, Ocr
delete tesseract_;
tesseract_ = nullptr;
}
#ifdef USE_OPENCL
OpenclDevice od;
od.InitEnv();
#endif
bool reset_classifier = true;
if (tesseract_ == nullptr) {
reset_classifier = false;
Expand Down
4 changes: 0 additions & 4 deletions src/api/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ void TessBaseAPIDelete(TessBaseAPI *handle) {
delete handle;
}

size_t TessBaseAPIGetOpenCLDevice(TessBaseAPI * /*handle*/, void **device) {
return TessBaseAPI::getOpenCLDevice(device);
}

void TessBaseAPISetInputName(TessBaseAPI *handle, const char *name) {
handle->SetInputName(name);
}
Expand Down
Loading

0 comments on commit d5e000b

Please sign in to comment.