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

Tfloat float and double coexistance -- working towards that goal #7

Closed

Commits on Jul 15, 2021

  1. Add TFloat data type for neural network

    Up to now Tesseract used double for training and recognition
    with "best" models.
    
    This commit replaces double by a new data type TFloat which
    is double by default, but float if FAST_FLOAT is defined.
    
    Ideally this should allow faster training.
    
    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    731726a View commit details
    Browse the repository at this point in the history
  2. Fix some compiler warnings

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    fa1850f View commit details
    Browse the repository at this point in the history
  3. Optimize DotProductStdInnerProduct for float

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    507b8cb View commit details
    Browse the repository at this point in the history
  4. Avoid double / float conversion

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    0f9acea View commit details
    Browse the repository at this point in the history
  5. Implement TFloat for IntSimdMatrix

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    16437ca View commit details
    Browse the repository at this point in the history
  6. Test more implementations of DotProduct

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    8e77429 View commit details
    Browse the repository at this point in the history
  7. Add unittest for dotproduct

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    c7034f0 View commit details
    Browse the repository at this point in the history
  8. Support Apple Accelerate framework for training and best models

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    f497c18 View commit details
    Browse the repository at this point in the history
  9. Fix TFloat builds for Apple M1

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    4676d22 View commit details
    Browse the repository at this point in the history
  10. Fix DotProductNative for TFloat

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    82236f6 View commit details
    Browse the repository at this point in the history
  11. bugfix of FMA port to FAST_FLOAT: 8 float FPs fit in a single 256bit …

    …vector (8x32) (contrasting 4 double FPs: 4*64)
    GerHobbelt authored and stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    1402521 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    00feac2 View commit details
    Browse the repository at this point in the history
  13. bugfixing the AVX2 Extract8+16 codes, where there's lines like `__m25…

    …6d scale01234567 = _mm256_loadu_ps(scales)`, i.e. loading float vectors into double vector types. Extract from tesseract-ocr#3490.
    GerHobbelt authored and stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    dd3b5f2 View commit details
    Browse the repository at this point in the history
  14. Improve build code for native dotproduct

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    a9ff366 View commit details
    Browse the repository at this point in the history
  15. Enhance unittest/dotproduct_test

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    9c6503b View commit details
    Browse the repository at this point in the history
  16. Remove test code for fast float dotproduct

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    284fdb0 View commit details
    Browse the repository at this point in the history
  17. Implement fast float dotproduct for SSE IntSimdMatrix

    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    a71edc9 View commit details
    Browse the repository at this point in the history
  18. Partially revert "Merge pull request tesseract-ocr#3330 from Sintun/m…

    …aster"
    
    This partially reverts commit 122daf1,
    reversing changes made to 4cd56dc.
    
    This fixes a fatal assertion for certain images:
    
        cell_y_.size() >= 2 && cell_x_.size() >= 2:Error:Assert failed:in file ../../../src/textord/tablerecog.cpp, line 363
    
    Signed-off-by: Stefan Weil <[email protected]>
    stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    ffea0f2 View commit details
    Browse the repository at this point in the history
  19. Place TFloat type in the tesseract namespace, same as has been done w…

    …ith all other tesseract defined types, to prevent collisions with thirdparty software.
    GerHobbelt authored and stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    77cd861 View commit details
    Browse the repository at this point in the history
  20. just a couple of 'shadowed local variables' compiler warning fixes th…

    …at got through while I manually extracted the template work from my mainline (warnings due to running MSVC at Level 4)
    
    [sw]: Use different fix for blamer.cpp
    
    Signed-off-by: Stefan Weil <[email protected]>
    GerHobbelt authored and stweil committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    8d1c1e1 View commit details
    Browse the repository at this point in the history
  21. This is how the idea expressed in tesseract-ocr#3490 looks like: usin…

    …g function templates for TFloat float & double implementations to co-exist in the run-time without cluttering the code with #if/#else and no run-time switches (yet).
    
    ## Observations thus far
    
    - DRY? Check!
    - the whole function template (and let the C++ compiler do the heavy lifting) idea of stops somewhere. This regrettably happens to be at the weightmatrix.cpp code, where the code calls the CPU+configuration-selected SIMD implementation via function pointer: `intSimdMatrix->matrixDotVectorFunction` -- this would require code duplication of some kind (e.g. a FP32 callback pointer co-existing with a FP64 callback ptr in the struct and then have the code pick the right one, depending on current TFloat size, for example) and is thus deemed unsatisfactory (my opinion).
    - So far, and very probably independent of any solutions for the co-existence issue at higher levels in the code, this template approach works out well, with the compiler smartly picking the one matching the current float/double choice.
    - while we have double the number of specialized SIMD implementations (obviously), these do not need #if/#else checks as we can let the C++ compiler do its prototype matching job --> cleaner code.
    - the template functions also help clean up the serialization/de-serialization code as the `<T, ST>` dual-type approach there allows one to specify the run-time type (TFloat) and the file-storage type at the same time: also do note how this cleans up the 'Old' scales deserialization code, as the old file storage is simply 'float' instead of 'double'.
    - the added cost there is a double copy of file data when T==ST, but that turned out negligible in the preliminary tests as that bit of code didn't even reach the Top20 CPU Guzzlers Chart, so that extra copy can wait for smarter C++ template writers to take care of when microtuning is called for.
    GerHobbelt committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    97834d0 View commit details
    Browse the repository at this point in the history