diff --git a/.gitignore b/.gitignore index 21bac3a7beccaf5d9713d9d71cad37c97e5071cc..e92fdeddbff50dc58e3f447f0d7f96cbcd7fb581 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,8 @@ training/wordlist2dawg *.cube.* *.tesseract_cube.* *.traineddata + +# OpenCL +tesseract_opencl_profile_devices.dat +kernel*.bin + diff --git a/api/Makefile.am b/api/Makefile.am index d6172bb05281366bcc6b12fdf1d73e7a2dfec6c1..cb9990df37f3f40b18f4c732877628fb64ab440b 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -6,9 +6,9 @@ AM_CPPFLAGS += -DLOCALEDIR=\"$(localedir)\"\ -I$(top_srcdir)/classify -I$(top_srcdir)/ccmain \ -I$(top_srcdir)/wordrec -I$(top_srcdir)/cutil \ -I$(top_srcdir)/opencl -if USE_OPENCL -AM_CPPFLAGS += -I$(OPENCL_HDR_PATH) -endif + +AM_CPPFLAGS += $(OPENCL_CPPFLAGS) + if VISIBILITY AM_CPPFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden endif @@ -78,9 +78,9 @@ endif tesseract_LDADD = libtesseract.la -if USE_OPENCL -tesseract_LDADD += $(OPENCL_LIB) -endif + +tesseract_LDFLAGS = $(OPENCL_LDFLAGS) + if OPENMP tesseract_LDADD += $(OPENMP_CFLAGS) endif diff --git a/ccmain/Makefile.am b/ccmain/Makefile.am index d6c90ac84fce8a0af42f081cbbeebbc3788a8289..e82c0031a13d7433b6a7c5439a3f1878401cb616 100644 --- a/ccmain/Makefile.am +++ b/ccmain/Makefile.am @@ -5,9 +5,9 @@ AM_CPPFLAGS += \ -I$(top_srcdir)/classify -I$(top_srcdir)/dict \ -I$(top_srcdir)/wordrec -I$(top_srcdir)/cutil \ -I$(top_srcdir)/textord -I$(top_srcdir)/opencl -if USE_OPENCL -AM_CPPFLAGS += -I$(OPENCL_HDR_PATH) -endif + +AM_CPPFLAGS += $(OPENCL_CPPFLAGS) + if VISIBILITY AM_CPPFLAGS += -DTESS_EXPORTS \ -fvisibility=hidden -fvisibility-inlines-hidden diff --git a/ccstruct/Makefile.am b/ccstruct/Makefile.am index 13fc4bd7ad88a3f865904f33aae884ac9444dfea..8a26a684d6e3f5905d989da559240666dd144442 100644 --- a/ccstruct/Makefile.am +++ b/ccstruct/Makefile.am @@ -2,9 +2,7 @@ AM_CPPFLAGS += \ -I$(top_srcdir)/ccutil -I$(top_srcdir)/cutil \ -I$(top_srcdir)/viewer \ -I$(top_srcdir)/opencl -if USE_OPENCL -AM_CPPFLAGS += -I$(OPENCL_HDR_PATH) -endif +AM_CPPFLAGS += $(OPENCL_CPPFLAGS) if VISIBILITY AM_CPPFLAGS += -DTESS_EXPORTS \ diff --git a/configure.ac b/configure.ac index 940f3c6c76d89fad0484e9c7d7c225625f88aa92..8d813b68e9aece019179249130f84bc8daff40d9 100644 --- a/configure.ac +++ b/configure.ac @@ -99,7 +99,7 @@ case "${host_os}" in AM_CONDITIONAL(ADD_RT, true) ;; *darwin*) - OPENCL_LIBS="-framework OpenCL" + OPENCL_LIBS="" OPENCL_INC="" AM_CONDITIONAL(ADD_RT, false) ;; @@ -212,6 +212,8 @@ m4_define([MY_CHECK_FRAMEWORK], ) have_opencl_lib=false +OPENCL_CPPFLAGS='' +OPENCL_LDFLAGS='' case "${host_os}" in *darwin* | *-macos10*) echo "checking for OpenCL framework" @@ -219,28 +221,37 @@ case "${host_os}" in if test $my_cv_framework_OpenCL = yes; then have_opencl_lib=true fi + if test "$enable_opencl" = "yes"; then + if !($have_opencl_lib); then + AC_MSG_ERROR(Required OpenCL library not found!) + fi + AC_SUBST([AM_CPPFLAGS], [-DUSE_OPENCL]) + OPENCL_CPPFLAGS="" + OPENCL_LDFLAGS="-framework OpenCL" + fi ;; *) # default AC_CHECK_LIB(OpenCL, clGetPlatformIDs, have_opencl_lib=true, have_opencl_lib=false) + if test "$enable_opencl" = "yes"; then + 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 + if !($have_tiff); then + AC_MSG_ERROR(Required TIFF headers not found! Try to install libtiff-dev?? package.) + fi + AC_SUBST([AM_CPPFLAGS], [-DUSE_OPENCL]) + OPENCL_CPPFLAGS="-I${OPENCL_INC}" + OPENCL_LDFLAGS="${OPENCL_LIBS}" + fi ;; esac - -if test "$enable_opencl" = "yes"; then - 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 - if !($have_tiff); then - AC_MSG_ERROR(Required TIFF headers not found! Try to install libtiff-dev?? package.) - fi - AC_SUBST([AM_CPPFLAGS], [-DUSE_OPENCL]) - AC_SUBST([OPENCL_HDR_PATH],[$OPENCL_INC]) - AC_SUBST([OPENCL_LIB],[$OPENCL_LIBS]) -fi AM_CONDITIONAL([USE_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 diff --git a/opencl/Makefile.am b/opencl/Makefile.am index b4ea562f12d365a67a59635e83e4e709682a31ca..1a7368f998bbbd493c13c1f4e3a559b7e72cb02c 100644 --- a/opencl/Makefile.am +++ b/opencl/Makefile.am @@ -1,7 +1,4 @@ -AM_CPPFLAGS += -I$(top_srcdir)/ccutil -I$(top_srcdir)/ccstruct -I$(top_srcdir)/ccmain -if USE_OPENCL -AM_CPPFLAGS += -I$(OPENCL_HDR_PATH) -endif +AM_CPPFLAGS += -I$(top_srcdir)/ccutil -I$(top_srcdir)/ccstruct -I$(top_srcdir)/ccmain $(OPENCL_CFLAGS) noinst_HEADERS = \ openclwrapper.h oclkernels.h opencl_device_selection.h @@ -9,13 +6,10 @@ if !USING_MULTIPLELIBS noinst_LTLIBRARIES = libtesseract_opencl.la else lib_LTLIBRARIES = libtesseract_opencl.la -libtesseract_opencl_la_LDFLAGS = -version-info $(GENERIC_LIBRARY_VERSION) +libtesseract_opencl_la_LDFLAGS = -version-info $(GENERIC_LIBRARY_VERSION) $(OPENCL_LDFLAGS) libtesseract_opencl_la_LIBADD = \ ../ccutil/libtesseract_ccutil.la \ ../viewer/libtesseract_viewer.la -if USE_OPENCL -libtesseract_opencl_la_LDFLAGS += $(OPENCL_LIB) -endif endif libtesseract_opencl_la_SOURCES = \ diff --git a/opencl/openclwrapper.cpp b/opencl/openclwrapper.cpp index e1d7341f6a9301a6fa3db3a8d9037250e7d13441..7c1d0c73a0d5ded51c45f9bf800d8b354ccb4f98 100644 --- a/opencl/openclwrapper.cpp +++ b/opencl/openclwrapper.cpp @@ -60,7 +60,7 @@ KernelEnv rEnv; // substitute invalid characters in device name with _ void legalizeFileName( char *fileName) { //printf("fileName: %s\n", fileName); - char *invalidChars = "/\?:*\"><| "; // space is valid but can cause headaches + const char* invalidChars = "/\?:*\"><| "; // space is valid but can cause headaches // for each invalid char for (int i = 0; i < strlen(invalidChars); i++) { char invalidStr[4]; @@ -2408,9 +2408,9 @@ PERF_COUNT_START("HistogramRectOCL") int requestedOccupancy = 10; int numWorkGroups = numCUs * requestedOccupancy; int numThreads = block_size*numWorkGroups; - size_t local_work_size[] = {block_size}; - size_t global_work_size[] = {numThreads}; - size_t red_global_work_size[] = {block_size*kHistogramSize*bytes_per_pixel}; + size_t local_work_size[] = {static_cast(block_size)}; + size_t global_work_size[] = {static_cast(numThreads)}; + size_t red_global_work_size[] = {static_cast(block_size*kHistogramSize*bytes_per_pixel)}; /* map histogramAllChannels as write only */ int numBins = kHistogramSize*bytes_per_pixel*numWorkGroups; @@ -3398,8 +3398,8 @@ PERF_COUNT_SUB("pix setup") int block_size = 256; int numWorkGroups = ((h*w+block_size-1) / block_size ); int numThreads = block_size*numWorkGroups; - size_t local_work_size[] = {block_size}; - size_t global_work_size[] = {numThreads}; + size_t local_work_size[] = {static_cast(block_size)}; + size_t global_work_size[] = {static_cast(numThreads)}; //printf("Enqueueing %i threads for %i output pixels\n", numThreads, w*h); /* compile kernel */ diff --git a/textord/Makefile.am b/textord/Makefile.am index a221ca32c9d8ad4f4a318fb50f0bfc431b8054d8..ec9d947c407a8ef3c4f1fa8a8e3928add90cbb60 100644 --- a/textord/Makefile.am +++ b/textord/Makefile.am @@ -5,9 +5,8 @@ AM_CPPFLAGS += \ -I$(top_srcdir)/ccmain -I$(top_srcdir)/wordrec -I$(top_srcdir)/api \ -I$(top_srcdir)/cutil -I$(top_srcdir)/classify -I$(top_srcdir)/dict \ -I$(top_srcdir)/opencl -if USE_OPENCL -AM_CPPFLAGS += -I$(OPENCL_HDR_PATH) -endif + +AM_CPPFLAGS += $(OPENCL_CPPFLAGS) if VISIBILITY AM_CPPFLAGS += -DTESS_EXPORTS \ diff --git a/training/Makefile.am b/training/Makefile.am index e5949555928c9baad539be165295e5598036d453..fe3d85bcdc5b376340c5ac88b9ada6dd7d64df4b 100644 --- a/training/Makefile.am +++ b/training/Makefile.am @@ -298,16 +298,14 @@ noinst_HEADERS += ../vs2010/port/strcasestr.h libtesseract_training_la_SOURCES += ../vs2010/port/strcasestr.cpp endif -if USE_OPENCL -ambiguous_words_LDADD += $(OPENCL_LIB) -classifier_tester_LDADD += $(OPENCL_LIB) -cntraining_LDADD += $(OPENCL_LIB) -combine_tessdata_LDADD += $(OPENCL_LIB) -dawg2wordlist_LDADD += $(OPENCL_LIB) -mftraining_LDADD += $(OPENCL_LIB) -set_unicharset_properties_LDADD += $(OPENCL_LIB) -shapeclustering_LDADD += $(OPENCL_LIB) -text2image_LDADD += $(OPENCL_LIB) -unicharset_extractor_LDADD += $(OPENCL_LIB) -wordlist2dawg_LDADD += $(OPENCL_LIB) -endif +ambiguous_words_LDFLAGS = $(OPENCL_LDFLAGS) +classifier_tester_LDFLAGS = $(OPENCL_LDFLAGS) +cntraining_LDFLAGS = $(OPENCL_LDFLAGS) +combine_tessdata_LDFLAGS = $(OPENCL_LDFLAGS) +dawg2wordlist_LDFLAGS = $(OPENCL_LDFLAGS) +mftraining_LDFLAGS = $(OPENCL_LDFLAGS) +set_unicharset_properties_LDFLAGS = $(OPENCL_LDFLAGS) +shapeclustering_LDFLAGS = $(OPENCL_LDFLAGS) +text2image_LDFLAGS = $(OPENCL_LDFLAGS) +unicharset_extractor_LDFLAGS = $(OPENCL_LDFLAGS) +wordlist2dawg_LDFLAGS = $(OPENCL_LDFLAGS)