robertknight / ocrs

Rust library and CLI tool for OCR (extracting text from images)
Apache License 2.0
1.09k stars 44 forks source link

[CLI] Illegal instruction (core dumped) under Proxmox VM #52

Closed pythcoiner closed 4 months ago

pythcoiner commented 4 months ago

Installed w/ cargo install ocrs-cli trying to run ocr <filename> on this 2 images (png) return a Illegal instruction (core dumped) output:

cropped

gray_img

robertknight commented 4 months ago

Can you provide details of:

Previous reports of this error have involved some kind of CPU virtualization (https://github.com/robertknight/ocrs/issues/49, https://github.com/robertknight/rten/issues/35).

I was able to run Ocrs on the two images you provided and got the correct output, so there isn't an issue with the image itself.

pythcoiner commented 4 months ago

right, it's happend under ubuntu 22.04 w/ a Proxmox VM, here the config:

image

robertknight commented 4 months ago

Can you confirm the CPU model being used by the VM? It doesn't appear in that screenshot. See https://github.com/robertknight/ocrs/issues/49#issuecomment-2081670270. For the best performance, you want something that supports AVX-2 / FMA. I'm not familiar with Proxmox, but it sounds like the "host" option is the easiest way to get this. If there is a x86-64-v3 or x86-64-v4 CPU option, that should include it.

There is a bug as Ocrs shouldn't just crash if the capability is not present, but the fallback without these CPU features will be somewhat slower.

robertknight commented 4 months ago

Thanks for the report. I was able to trigger an Illegal Instruction error using an Ubuntu 24.04 VM running under emulation in UTM (qemu), with the CPU set to Intel Nehalem (see https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels), which is a pre-AVX2 CPU.

The issue is fixed upstream by https://github.com/robertknight/rten/pull/131 and should be in the next Ocrs release.

Backtrace:

Thread 2 "ocrs" received signal SIGILL, Illegal instruction.
[Switching to Thread 0x7ffff7a006c0 (LWP 2789)]
0x0000555555862320 in rten_vecmath::exp::simd_sigmoid ()
(gdb) bt
#0  0x0000555555862320 in rten_vecmath::exp::simd_sigmoid ()
#1  0x000055555586254b in rten_vecmath::exp::vec_sigmoid_in_place ()
#2  0x00005555558482b3 in rayon::iter::plumbing::bridge_producer_consumer::helper ()
#3  0x00005555557bee26 in rayon_core::join::join_context::{{closure}} ()
#4  0x00005555558483af in rayon::iter::plumbing::bridge_producer_consumer::helper ()
#5  0x00005555557bee26 in rayon_core::join::join_context::{{closure}} ()
#6  0x00005555558483af in rayon::iter::plumbing::bridge_producer_consumer::helper ()
#7  0x0000555555764d29 in rayon_core::join::join_context::{{closure}} ()
#8  0x000055555576e7bc in <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute ()
#9  0x000055555559a82f in rayon_core::registry::WorkerThread::wait_until_cold
    ()
#10 0x0000555555865d62 in rayon_core::registry::ThreadBuilder::run ()
#11 0x00005555558692da in std::sys_common::backtrace::__rust_begin_short_backtrace ()
#12 0x000055555586a44f in core::ops::function::FnOnce::call_once{{vtable.shim}}
    ()
robertknight commented 4 months ago

ocrs-cli v0.6.0 has been released which should fix the issue. I would still recommend configuring your VM to use a newer CPU, as using one that supports AVX2 will be 2-4x faster.

pythcoiner commented 4 months ago

Just try w/ 0.6.0, works well, thanks for quick response!