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

Add RISC-V V support #4346

Merged
merged 2 commits into from
Nov 7, 2024
Merged

Add RISC-V V support #4346

merged 2 commits into from
Nov 7, 2024

Conversation

hleft
Copy link
Contributor

@hleft hleft commented Nov 5, 2024

Convert riscv-v-spec-1.0.pdf into 111 PNG images,
then perform OCR on each one in sequence,
and measure the testing time on banana_f3:

old: 31m16.267s
new: 16m51.155s

src/arch/intsimdmatrixrvv.cpp Outdated Show resolved Hide resolved
src/arch/intsimdmatrixrvv.cpp Show resolved Hide resolved
@egorpugin
Copy link
Contributor

egorpugin commented Nov 5, 2024

What is default compiler (gcc/clang) risc-v flag? gcc -dM -E - < /dev/null | grep riscv
Is it __riscv__ ?
If so, I would prefer it over custom HAVE_RVV flag.

Upd.: Ok, I see you mean vector instructions specifically. Then It's ok.

@stweil
Copy link
Contributor

stweil commented Nov 7, 2024

@hleft, did you compare the results with and without your code? I tested it with the largest image (page 11) and the model tessdata_fast/eng.traineddata, but only get garbage text output.

@hleft
Copy link
Contributor Author

hleft commented Nov 7, 2024

@hleft, did you compare the results with and without your code? I tested it with the largest image (page 11) and the model tessdata_fast/eng.traineddata, but only get garbage text output.

I tested the code with and without this PR based on the documentation (https://tesseract-ocr.github.io/), under:

  • Unit test builds
  • Release Builds for Mass Production

All unit tests passed, and the built Tesseract correctly produces OCR results (if implemented incorrectly, it would yield incorrect OCR results).

I don’t quite understand why this is happening...

Update: Indeed, there is an issue on page 11...

src/arch/simddetect.cpp Outdated Show resolved Hide resolved
@stweil
Copy link
Contributor

stweil commented Nov 7, 2024

@hleft, could you please run a test with the image for page 11? It should produce this output:

Estimating resolution as 99
sel NOSE te te ee we 2:0] ng 6-11) ed ee eh SH, Begs omy

‘able 4. txampleViEN = 12855
ew] lent por wecoregter|

‘The supports lament ict may vay with MUL

Lge Sey wheat tom mci cir ragets oe conto arg MI hs cane cr ta ees once
we shaidaterotio wee trget UL ont hes tone ver gets pens © roca enter cf picrenere ot

Siech tie cole warn Te ll Stinvtype had becca chr sng vps tose ongtinie oped eden
‘Sevwic cade thstuldoe pet eat Atematysrhinco ender SW seach BNL ten

3.4.2. Vector Reiter Grouping (vimu1[2:0D

utp vector esters can beg cues together so that asingevecto:insructon can operate on mule vector regites.
‘Tha term vector regeter group's ees heren to ele toone o morsvectorepste'suaee se aengeoperanc toavect”
instucton. Veco registr group can be usec to pravice geate’executoneftengjforlonge aptcaton vectors, but the
rman reason fr thar nduson sto allow coube-wcth or Lge deren tobe opeatc on wth te same veto length as
‘Snge-weth elements. The vector length muller MUL when greater than’. ep esents the fault numberof eco:
reget that ze combines to frma vector ester oun Implementations must suppor LMUL inte values of 2.4,

se| bli sre noe’ fleets The efetne DIL EMA) of ec et eel een by he noe” fetes
ote rquredw hall ie ier. For crave ra nde nrg att costo sos ad St era pode 6D rete
(Site-adn rent cqies nice he Latin ngewe nove,

lett can so be aractonal value reusing the number of bis use in asinge vector ete Fractiond LMUL i used to
iesiee the numberof fectvevsablevactorregete Eoupe hen opersngon mmxeosveth values

Wn ey ctage MUL aan aco cern gona range zee oud ve a soe allen ne wile ect LMU)
‘Erte norasestdoatyar ad cuidcoire rte tps LMI] fotara ochre ge br ie
fectragcend Ths co Ete aanberchvecor rages gouse mele ih focal, the wee tomato oy
nite|Sayasmge vt regate hi none vu nanan atacionofe sieeve mga: ange octet

tafe tees tobe act to Gf ves a eis kop eve when heding woecraeih aves Facial MUL pet
dortonafvere eps ow nan bt nzome anes hang hres afte naden verbs mares ect wate
{ewe ings rgaerveslon eco

1mplementatons must prove Fractonal LMUL settings that alow the narovest supports type tooceupy atacton ofa
vector epsteenespencingto the atthe narrowest uperto types woth otha of helagest supported pes
let. tn gener the equrement's tosupport MUL 2SE\yy/ELEN, whee SEViqyy 8 thenarowesteuppored SEW valve
ang ELEN’ thewicest supported SEW value. tn thestancarc extensions, SEWqy=8. Fr santa vecter extensions with
ieN=32,Factoral UMulsof1/2 and 1/4 must be supported For stance vero extension wth ELEN=Sé, factional
Mus of 1/2. 16, an must be suppores

Whe MUL <$6thq/BLEN feet grate on inplenerston woddhow eng sin the ction ect ttre
{1B wad ontyprotic brie cfstmge ine errr

Fer agiven supports factional MUL setting implementation must suppot SEW stings between SEV aN6 MUL”
LEN, indusive

An sttempt tose an uneupgorts SEW ane LMUL configuration ate theVi11 bitin type.

It takes about 21 s with the released git master. Optimized C++ code and compiler options (-march=rv64gv0p10) still produce the same result, but reduce the time to 13 s.

Convert riscv-v-spec-1.0.pdf into 111 PNG images,
then perform OCR on each one in sequence,
and measure the testing time on banana_f3:

old:        31m16.267s
new:        16m51.155s
@hleft
Copy link
Contributor Author

hleft commented Nov 7, 2024

@hleft, did you compare the results with and without your code? I tested it with the largest image (page 11) and the model tessdata_fast/eng.traineddata, but only get garbage text output.

The issue seems to be that the if else, total +=, and total = parts together were causing concurrency errors. After removing the if else part, it worked correctly

Copy link
Contributor

@stweil stweil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@stweil stweil merged commit 9b909c0 into tesseract-ocr:main Nov 7, 2024
1 check passed
@stweil
Copy link
Contributor

stweil commented Nov 7, 2024

@hleft, do you want to implement dotproductrvv.cpp, too? This would accelerate the model training.

@hleft
Copy link
Contributor Author

hleft commented Nov 8, 2024

@stweil Which part is supposed to be accelerated by dotproductxxx.cpp? My test results always show no change(https://github.com/tesseract-ocr/tesstrain)

stweil added a commit to stweil/tesseract that referenced this pull request Nov 8, 2024
Convert riscv-v-spec-1.0.pdf into 111 PNG images,
then perform OCR on each one in sequence,
and measure the testing time on banana_f3:

old:        31m16.267s
new:        16m51.155s

Co-authored-by: sunyuechi <[email protected]>
Co-authored-by: Stefan Weil <[email protected]>
stweil added a commit to stweil/tesseract that referenced this pull request Nov 8, 2024
Convert riscv-v-spec-1.0.pdf into 111 PNG images,
then perform OCR on each one in sequence,
and measure the testing time on banana_f3:

old:        31m16.267s
new:        16m51.155s

Co-authored-by: sunyuechi <[email protected]>
Co-authored-by: Stefan Weil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants