Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCL segfault #53

Closed
jbreiden opened this issue Jul 19, 2015 · 14 comments
Closed

OpenCL segfault #53

jbreiden opened this issue Jul 19, 2015 · 14 comments

Comments

@jbreiden
Copy link
Contributor

Hardware is a Ubuntu 14.04 laptop with integrated Intel graphics.

./configure --enable-opencl --enable-debug
...
gdb api/.libs/lt-tesseract

(gdb) run testing/phototest.tif -

Starting program: api/.libs/lt-tesseract testing/phototest.tif -
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[DS] Profile file not available (tesseract_opencl_profile_devices.dat); performing profiling.

Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/x86_64/strlen.S:106
106 ../sysdeps/x86_64/strlen.S: No such file or directory.
(gdb) backtrace
#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x00007ffff77fe549 in writeProfileToFile (profile=0x81c810, 
    serializer=0x7ffff780752f <serializeScore(ds_device*, void**, unsigned int*)>, file=0x7ffff78aa5e0 "tesseract_opencl_profile_devices.dat")
    at opencl_device_selection.h:268
#2  0x00007ffff7807a09 in OpenclDevice::getDeviceSelection ()
    at openclwrapper.cpp:3427
#3  0x00007ffff7800356 in OpenclDevice::InitOpenclRunEnv_DeviceSelection (
    argc=0) at openclwrapper.cpp:527
#4  0x00007ffff7800074 in OpenclDevice::InitEnv () at openclwrapper.cpp:431
#5  0x00007ffff75f01af in tesseract::TessBaseAPI::Init (this=0x7fffffffda40, 
    datapath=0x0, language=0x405a13 "eng", oem=tesseract::OEM_DEFAULT, 
    configs=0x7fffffffe6a0, configs_size=0, vars_vec=0x7fffffffda00, 
    vars_values=0x7fffffffda20, set_only_non_debug_params=false)
    at baseapi.cpp:299
#6  0x0000000000404317 in main (argc=3, argv=0x7fffffffe688)
    at tesseractmain.cpp:181
...
@jbreiden
Copy link
Contributor Author

Ray says,

I think there is a bug in InitDSProfile.

I suspect if you change if (status == SUCCESS) to if (status == SUCCESS && profile->numDevices > 0)
at openclwrapper.cpp:3426
then it will work. (You have no devices, and unlike the code here: https://docs.libreoffice.org/opencl/html/opencl__device__selection_8h_source.html
it doesn't correctly always add the native CPU as a device, and therefore attempts to write a null buffer, even though it has no devices.)

@jbreiden
Copy link
Contributor Author

still trouble

@jbreiden
Copy link
Contributor Author

note that if we get through this, I will probably enable OpenCL by default for Debian/Ubuntu

@spSerg
Copy link
Contributor

spSerg commented Jul 28, 2015

I'm in stuck. How this code (located at oclkernels.h:1086) can work:

pixels.v[i] = imageData[
    w*(BURSTS_PER_WORD*(PIXELS_PER_BURST*NUM_CHANNELS)/CHAR_VEC_WIDTH) + 
    b*((PIXELS_PER_BURST*NUM_CHANNELS)/CHAR_VEC_WIDTH)  + i];

where maximum value of index can be 4x higher that size of imageData array
Variables are:
w in range [0 .. count of DWORDS in image),
b in range [0 .. BURSTS_PER_WORD),
i in range [0 .. (PIXELS_PER_BURST*NUM_CHANNELS)/CHAR_VEC_WIDTH )
Constants values:

#define NUM_CHANNELS 4
#define CHAR_VEC_WIDTH 8
#define PIXELS_PER_WORD 32
#define PIXELS_PER_BURST 8
#define BURSTS_PER_WORD (PIXELS_PER_WORD/PIXELS_PER_BURST)

@jbreiden
Copy link
Contributor Author

I get a similar looking segfault (but I didn't confirm with gdb) even on a computer that contains a discrete graphics card. Is OpenCL working for anyone at all?

@zdenop
Copy link
Contributor

zdenop commented Jul 30, 2015

it worked for me on some images (there are some issues reported already - IMO 2 color tiff should work). Last week it segfault on linux. I will try windows today...
Also on forum there are some experiments[1]
[1] https://mail.google.com/mail/u/0/#search/opencl

@spSerg
Copy link
Contributor

spSerg commented Jul 30, 2015

I can't get fully worked OpenCL configuration. But I have a much different environment (without any other dependencies except leptonica). I've got errors like:
Access violation reading location 0x58B87000
That's a position after imageData host's buffer.

@zdenop
Copy link
Contributor

zdenop commented Jul 30, 2015

I am not sure what do you mean with "any other dependencies except leptonica" - to run tesseract with opencl support you need libtiff and opencl sdk that support your hardware...

@zdenop
Copy link
Contributor

zdenop commented Jul 30, 2015

@jbreiden:
it works for me on windows:
tesseract-opencl.exe ....\testing\phototest.tif -
[OD] Load opencl.dll successful!
[DS] Profile file not available (tesseract_opencl_profile_devices.dat); performi
ng profiling.

[DS] Device: "Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz" (OpenCL) evaluation...
[OD] write binary[kernel-Intel(R)_Core(TM)i7-4800MQ_CPU@_2.70GHz.bin] succesfully
[DS] Device: "Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz" (OpenCL) evaluated
[DS] composeRGBPixel: 0.038657 (w=1.2)
[DS] HistogramRect: 0.325462 (w=2.4)
[DS] ThresholdRectToPix: 0.042622 (w=4.5)
[DS] getLineMasksMorph: 0.119543 (w=5.0)
[DS] Score: 1.617007

[DS] Device: "Intel(R) HD Graphics 4600" (OpenCL) evaluation...
[OD] write binary[kernel-Intel(R)_HD_Graphics_4600.bin] succesfully
[DS] Device: "Intel(R) HD Graphics 4600" (OpenCL) evaluated
[DS] composeRGBPixel: 0.153912 (w=1.2)
[DS] HistogramRect: 0.449184 (w=2.4)
[DS] ThresholdRectToPix: 0.048737 (w=4.5)
[DS] getLineMasksMorph: 0.027403 (w=5.0)
[DS] Score: 1.619068

[DS] Device: "(null)" (Native) evaluation...
[DS] Device: "(null)" (Native) evaluated
[DS] composeRGBPixel: 0.088750 (w=1.2)
[DS] HistogramRect: 0.388795 (w=2.4)
[DS] ThresholdRectToPix: 0.182945 (w=4.5)
[DS] getLineMasksMorph: 0.613772 (w=5.0)
[DS] Score: 4.931717
[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 1.617007
[DS] Device[2] 1:Intel(R) HD Graphics 4600 score is 1.619068
[DS] Device[3] 0:(null) score is 4.931717
[DS] Selected Device[1]: "Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz" (OpenCL)
Page 1
This is a lot of 12 point text to test the
ocr code and see if it works on all types
of file format.

The quick brown dog jumped over the
lazy fox. The quick brown dog jumped
over the lazy fox. The quick brown dog
jumped over the lazy fox. The quick
brown dog jumped over the lazy fox.

@spSerg
Copy link
Contributor

spSerg commented Jul 30, 2015

Just made a bit changes to exclude libtiff dependency.
I have my own input and output streams.
I see, that I can't request any attention without prepare reproducible error in your environment.

@jbreiden
Copy link
Contributor Author

jbreiden commented Aug 7, 2015

spSerg: you can request attention, but if we can't reproduce you need to supply more information, such as a backtrace from gdb or the output of valgrind (either works much better when ./configure is run with --enable-debug)

@jbreiden
Copy link
Contributor Author

I'm having an unexpectedly hard time with this.

@jbreiden
Copy link
Contributor Author

#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x00007ffff77d3c5f in writeProfileToFile (profile=0x80ac20, 
    serializer=0x7ffff77dcc45 <serializeScore(ds_device*, void**, unsigned int*)>, 
    file=0x7ffff78a0b20 "tesseract_opencl_profile_devices.dat") at opencl_device_selection.h:268
#2  0x00007ffff77dd11f in OpenclDevice::getDeviceSelection () at openclwrapper.cpp:3427
#3  0x00007ffff77d5a6c in OpenclDevice::InitOpenclRunEnv_DeviceSelection (argc=0) at openclwrapper.cpp:527
#4  0x00007ffff77d578a in OpenclDevice::InitEnv () at openclwrapper.cpp:431
#5  0x00007ffff75efb2f in tesseract::TessBaseAPI::Init (this=0x7fffffffd9f0, datapath=0x0, 
    language=0x405a13 "eng", oem=tesseract::OEM_DEFAULT, configs=0x7fffffffe650, configs_size=0, 
    vars_vec=0x7fffffffd9b0, vars_values=0x7fffffffd9d0, set_only_non_debug_params=false) at baseapi.cpp:299
#6  0x0000000000404327 in main (argc=3, argv=0x7fffffffe638) at tesseractmain.cpp:181

@zdenop
Copy link
Contributor

zdenop commented Oct 27, 2016

Please check master branch or commits f46dfdc and 5db7602.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants