sk-spell

podpora slovenčiny v Open Source programoch

tesseract meets the OpenCL - first test   

posledná zmena: 1. January 2014


back to tesseract-ocr-en

Intro

In svn there is first part of tesseract-ocr 3.03 code. There is new contribution coming from application engineering team at AMD that saw the significant opportunity to accelerate the compute intensive portions of the code without affecting the accuracy of the algorithm. They looked at offloading modules onto the graphical processing units (GPU). The GPU programs will run OpenCL which is platform & OS agnostic. This should enable speed-up across all supported platforms.

At the moment tesseract-ocr produces time information about overall performance and some functions (regardless OpenCL is used or not)..

Linux

My first attempt to use OpenCL was on my “AMD based” (CPU and GPU) linux computer (openSUSE 13.1 64bit). Unfortunately I found out that my video card ([AMD/ATI] RV630 PRO [Radeon HD 2600 PRO]) is not supported by AMD latest version of graphic card drivers (AMD catalyst-13.1-legacy) and I was not able to install older version of driver on openSUSE 13.1.

Anyway I decide to install Accelerated Parallel Processing (APP) SDK (AMD-APP-SDK-v2.9) to see what will happened. Installation of package is very easy and without any problem. AMD OpenCL package was installed at /opt/AMDAPP/ (lib and include).

Than I needed to configure tesseract-ocr. I like to use automake VPATH Builds for different tesseract-ocr configuration. You can use it this way (I expect that you have local svn repository at /usr/src/tesseract-ocr):

cd /usr/src/tesseract-ocr
svn up
./autogen.sh
mkdir /usr/src/tesseract-ocr.opencl
cd /usr/src/tesseract-ocr.opencl
../tesseract-ocr/configure --enable-opencl --prefix=/usr
make -j 6 
sudo make install

If you get error:

ld: cannot find -lOpenCL

than run this command before make:
export LIBRARY_PATH=/opt/AMDAPP/lib/x86_64/:$LIBRARY_PATH

In case you have installed AMD Catalyst 13.1 Legacy drivers, OpenCL library is installed in /usr/lib64, /usr/lib too, so ld should not have problem to find it (but OpenCL header files are not included in AMD Catalyst 13.1 Legacy drivers).

I installed it to /usr, just to make sure I have only one version of tesseract-ocr installed. Now lets get initial information:

tesseract -v
tesseract 3.03
 leptonica-1.69
  libgif 4.1.6 : libjpeg 8b : libpng 1.6.6 : libtiff 4.0.3 : zlib 1.2.8
 OpenCL info:
  Found 1 platforms.
  Platform name: AMD Accelerated Parallel Processing.
  Version: OpenCL 1.2 AMD-APP (1214.3).
  Found 1 devices.
    Device 1 name: AMD Athlon(tm) X2 Dual Core Processor BE-2400.

As you can see because I use opensource radeon driver for my videocard, so OpenCL is able to find /use only my CPU with two cores, but no GPU.

Linux test

For the moment I just made simple test – measure time of OCR ([Tesseract:main] lenght). I use image 8509_001.4B.tif from ISRI-OCRtk bus.4B.

Here are initial data with “noOpenCL” version of tesseract-ocr:

> tesseract 8509_001.4B.tif 8509_001.4B
[                   TessBaseAPI::Init],                    total,    0.680310
Tesseract Open Source OCR Engine v3.03 with Leptonica
[                   GetLineMasksMorph],                    total,    0.890510
[                  FindAndRemoveLines],                    total,    1.061292
[                         ProcessPage],                    total,   21.232282
[                        ProcessPages],                    total,   21.273481
[                      Tesseract:main],                    total,   21.954697

With OpenCL enabled:
 > tesseract 8509_001.4B.tif 8509_001.4B
 [DS] Profile file not available (tesseract_opencl_profile_devices.dat); performing profiling
 [DS] Device: "AMD Athlon(tm) X2 Dual Core Processor BE-2400" (OpenCL) evaluation...
 OpenCL error code is -1 at   when clGetDeviceIDs .
 [   OD::CompileKernel::clBuildProgram],                    total,    1.223780
 [OD] write binary[kernel-AMD_Athlon(tm)_X2_Dual_Core_Processor_BE-2400.bin] succesfully
 [               pixReadFromTiffKernel],                    total,    0.05976
 [                    HistogramRectOCL],                    total,    0.660465
 [               ThresholdRectToPixOCL],                    total,    0.067328
 [DS] Device: "AMD Athlon(tm) X2 Dual Core Processor BE-2400" (OpenCL) evaluated
 [DS]          composeRGBPixel: 0.059823 (w=1.2)
 [DS]            HistogramRect: 0.660525 (w=2.4)
 [DS]       ThresholdRectToPix: 0.067384 (w=4.5)
 [DS]        getLineMasksMorph: 0.205506 (w=5.0)
 [DS]                    Score: 2.987804<br/>
 [DS] Device: "(null)" (Native) evaluation...
 [                       HistogramRect],                    total,    0.023726
 [                       HistogramRect],                    total,    0.032327
 [                       HistogramRect],                    total,    0.032890
 [                       HistogramRect],                    total,    0.032501
 [DS] Device: "(null)" (Native) evaluated
 [DS]          composeRGBPixel: 0.073872 (w=1.2)
 [DS]            HistogramRect: 0.121674 (w=2.4)
 [DS]       ThresholdRectToPix: 0.050257 (w=4.5)
 [DS]        getLineMasksMorph: 0.350409 (w=5.0)
 [DS]                    Score: 2.358863
 [DS] Scores written to file (tesseract_opencl_profile_devices.dat).
 [DS] Device[1] 1:AMD Athlon(tm) X2 Dual Core Processor BE-2400 score is 2.987804
 [DS] Device[2] 0:(null) score is 2.358863
 [DS] Selected Device[2]: "(null)" (Native)
 [                  getDeviceSelection],                    total,    4.342579
 [                   TessBaseAPI::Init],                    total,    4.662863
 Tesseract Open Source OCR Engine v3.03 with Leptonica
 [                   GetLineMasksMorph],                    total,    0.864317
 [                  FindAndRemoveLines],                    total,    1.025500
 [                         ProcessPage],                    total,   11.497218
 [                        ProcessPages],                    total,   11.538741
 [                      Tesseract:main],                    total,   16.202244

Hmm, it looks like there is performed profiling at the beginning, so lets try to run command once more time:

> tesseract 8509_001.4B.tif 8509_001.4B
[DS] Profile read from file (tesseract_opencl_profile_devices.dat).
[DS] Device[1] 1:AMD Athlon(tm) X2 Dual Core Processor BE-2400 score is 2.987804
[DS] Device[2] 0:(null) score is 2.358863
[DS] Selected Device[2]: "(null)" (Native)
[                  getDeviceSelection],                    total,    0.032056
[                   TessBaseAPI::Init],                    total,    0.332594
Tesseract Open Source OCR Engine v3.03 with Leptonica
[                   GetLineMasksMorph],                    total,    0.874358
[                  FindAndRemoveLines],                    total,    1.042208
[                         ProcessPage],                    total,   11.808473
[                        ProcessPages],                    total,   11.850462
[                      Tesseract:main],                    total,   12.183789

Output is shorter ;-) and total time was improved too. 12.18 to 21.95 means 44% less time to OCR one page with enabled OpenCL support.

Windows

I have possibility to run test on Windows 7 64bit on Dell notebook which is “Intel based”: Intel® Core™ i7-4800MQ CPU @ 2.70GHz. and Intel® HD Graphics 4600. According Intel web page this graphic card is supported by their OpenCL package. OpenCL runtime and compiler should be part of driver package, but I need to install Intel® SDK for OpenCL* Applications 2013) that provides Header files and libraries, Microsoft Visual Studio* 2008-2012 IDE Integration, Kernel Builder (Design, build, and analyze OpenCL kernels).

I tried to install it several time, but there were no header files installed (just libs) and installation finished with error “…Setup Wizard ended prematurely because of error”. After looking on internet I found out error message is caused by (automatically) checked option to integrate with Microsoft Visual Studio 2010. Problem is that Intel OpenCL is not able to integrate to Express version of Visual Studio 2010… Indeed turning off integration with Visual Studio helped.

OpenCL support in tesseract-ocr on Windows platform is at the moment (svn revision 929) only for VS2010. There you can find configuration “LIB_OpenCL_Release” that is based on static linked release (“LIB_Release”) of tesseract-ocr. Even OS is 64bit I used 32 bit OpenCL library because there is no 64bit configuration for tesseract-ocr VS solution.

> tesseract-opencl.exe -v
tesseract 3.03
 leptonica-1.68 (Mar 14 2011, 10:43:03) [MSC v.1500 LIB Release 32 bit]
  libgif 4.1.6 : libjpeg 8c : libpng 1.4.3 : libtiff 3.9.4 : zlib 1.2.5<br/>
 OpenCL info:
  Found 1 platforms.
  Platform name: Intel(R) OpenCL.
  Version: OpenCL 1.2 .
  Found 2 devices.
    Device 1 name: Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz.
    Device 2 name: Intel(R) HD Graphics 4600.

Windows test

I used the same image as in linux tests. Here are the results for “noOpenCL”:

>tesseract.exe 8509_001.4B.tif 8509_001.4B
[                   TessBaseAPI::Init],                    total,    0.428550
Tesseract Open Source OCR Engine v3.03 with Leptonica
[                   GetLineMasksMorph],                    total,    0.322534
[                  FindAndRemoveLines],                    total,    0.394429
[                         ProcessPage],                    total,    3.578335
[                        ProcessPages],                    total,    3.656705
[                      Tesseract:main],                    total,    4.091411

OpenCL version 1st run:
 >tesseract-opencl.exe 8509_001.4B.tif 8509_001.4B
 [OD] Load opencl.dll successful!
 [DS] Profile file not available (tesseract_opencl_profile_devices.dat); performing profiling.
 [DS] Device: "Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz" (OpenCL) evaluation...
 [   OD::CompileKernel::clBuildProgram],                    total,    1.041619
 [OD] write binary[kernel-Intel(R)_Core(TM)_i7-4800MQ_CPU_@_2.70GHz.bin] succesfully
 [               pixReadFromTiffKernel],                    total,    0.045007
 [                    HistogramRectOCL],                    total,    0.113896
 [               ThresholdRectToPixOCL],                    total,    0.023143
 [DS] Device: "Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz" (OpenCL) evaluated
 [DS]          composeRGBPixel: 0.045170 (w=1.2)
 [DS]            HistogramRect: 0.114120 (w=2.4)
 [DS]       ThresholdRectToPix: 0.023391 (w=4.5)
 [DS]        getLineMasksMorph: 0.032764 (w=5.0)
 [DS]                    Score: 0.597172<br/>
 [DS] Device: "Intel(R) HD Graphics 4600" (OpenCL) evaluation...
 [   OD::CompileKernel::clBuildProgram],                    total,    0.954983
 [OD] write binary[kernel-Intel(R)_HD_Graphics_4600.bin] succesfully
 [               pixReadFromTiffKernel],                    total,    0.085689
 [                    HistogramRectOCL],                    total,    0.372385
 [               ThresholdRectToPixOCL],                    total,    0.055804
 [DS] Device: "Intel(R) HD Graphics 4600" (OpenCL) evaluated
 [DS]          composeRGBPixel: 0.086187 (w=1.2)
 [DS]            HistogramRect: 0.372899 (w=2.4)
 [DS]       ThresholdRectToPix: 0.056127 (w=4.5)
 [DS]        getLineMasksMorph: 0.017175 (w=5.0)
 [DS]                    Score: 1.336826<br/>
 [DS] Device: "(null)" (Native) evaluation...
 [                       HistogramRect],                    total,    0.017834
 [                       HistogramRect],                    total,    0.015073
 [                       HistogramRect],                    total,    0.015243
 [                       HistogramRect],                    total,    0.017316
 [DS] Device: "(null)" (Native) evaluated
 [DS]          composeRGBPixel: 0.048048 (w=1.2)
 [DS]            HistogramRect: 0.066408 (w=2.4)
 [DS]       ThresholdRectToPix: 0.033115 (w=4.5)
 [DS]        getLineMasksMorph: 0.129397 (w=5.0)
 [DS]                    Score: 1.013041
 [DS] Scores written to file (tesseract_opencl_profile_devices.dat).
 [DS] Device[1] 1:Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz score is 0.597172
 [DS] Device[2] 1:Intel(R) HD Graphics 4600 score is 1.336826
 [DS] Device[3] 0:(null) score is 1.013041
 [DS] Selected Device[1]: "Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz" (OpenCL)
 [                  getDeviceSelection],                    total,    3.254269
 [   OD::CompileKernel::clBuildProgram],                    total,    1.027866
 [                   TessBaseAPI::Init],                    total,    4.401662
 Tesseract Open Source OCR Engine v3.03 with Leptonica
 [                       pixReadTiffCL],                    total,    0.006628
 [                   GetLineMasksMorph],                    total,    0.033356
 [                  FindAndRemoveLines],                    total,    0.034604
 [                         ProcessPage],                    total,    3.377405
 [                        ProcessPages],                    total,    3.391607
 [                      Tesseract:main],                    total,    7.795046

OpenCL version 2nd run:
>tesseract-opencl.exe 8509_001.4B.tif 8509_001.4B
[OD] Load opencl.dll successful!
[DS] Profile read from file (tesseract_opencl_profile_devices.dat).
[DS] Device[1] 1:Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz score is 0.597172
[DS] Device[2] 1:Intel(R) HD Graphics 4600 score is 1.336826
[DS] Device[3] 0:(null) score is 1.013041
[DS] Selected Device[1]: "Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz" (OpenCL)
[                  getDeviceSelection],                    total,    0.157346
[   OD::CompileKernel::clBuildProgram],                    total,    1.040238
[                   TessBaseAPI::Init],                    total,    1.491639
Tesseract Open Source OCR Engine v3.03 with Leptonica
[                       pixReadTiffCL],                    total,    0.006641
[                   GetLineMasksMorph],                    total,    0.034659
[                  FindAndRemoveLines],                    total,    0.082480
[                         ProcessPage],                    total,    3.274738
[                        ProcessPages],                    total,    3.288972
[                      Tesseract:main],                    total,    4.782504
–--------------------------------------------------------------
[                   TessBaseAPI::Init],                    total,    0.428550
Tesseract Open Source OCR Engine v3.03 with Leptonica
[                   GetLineMasksMorph],                    total,    0.322534
[                  FindAndRemoveLines],                    total,    0.394429
[                         ProcessPage],                    total,    3.578335
[                        ProcessPages],                    total,    3.656705
[                      Tesseract:main],                    total,    4.091411

First impressions…

Well I try to avoid any conclusion, because I am not familiar with OpenCL, its implementations by AMD and INTEL, hardware effects etc. Anyway here are some remarks:


© projekt sk-spell

RSS [opensource] [w3c] [firefox] [textpattern]