GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: Lapack lite is not thread-safe (need to guard) · Issue #22509 · numpy/numpy

BUG: Lapack lite is not thread-safe (need to guard) #22509

New issue
Copy link
New issue
Copy link
Closed
#26750
Closed
BUG: Lapack lite is not thread-safe (need to guard)#22509
#26750
Copy link
Labels
00 - Bugcomponent: numpy.linalg
Milestone
2.1.0 release

Description

@seberg
seberg
opened on Nov 1, 2022
Issue body actions

skimage found an issue probably related to eigvalsh or generally threaded calls to linalg_umath.cpp.

Unfortunately, I have not yet narrowed it down further, and the test is slightly flaky (on my machine). For example, it seems to easier reproduce running the full file, rather than just the test.

To reproduce, I have to explicitly use NPY_BLAS_ORDER= (disable blas use), then run current main of skimage tests:

python3 -m pytest skimage/feature/tests/test_basic_features.py::test_multiscale_basic_features_deprecated_multichannel

I have a gdb traceback of a crash (the actual crash fluctuates a bit, so it may well be elsewhere):

#5  0x00007fffb7ef3f7f in release_evd<double> (params=0x7fffda26e940) at numpy/linalg/umath_linalg.cpp:1482
#6  eigh_wrapper<double> (JOBZ=<optimized out>, UPLO=<optimized out>, args=<optimized out>, dimensions=<optimized out>, 
    steps=<optimized out>) at numpy/linalg/umath_linalg.cpp:1555
#7  0x00007ffff639eed5 in generic_wrapped_legacy_loop (__NPY_UNUSED_TAGGEDcontext=<optimized out>, data=<optimized out>, 
    dimensions=<optimized out>, strides=<optimized out>, auxdata=0x7fffd19e9b30)
    at numpy/core/src/umath/legacy_array_method.c:87

So it seems eigvalsh and threading related. I need to dig further eventually, but maybe someone else has an idea what to look into (the umath code, the blas/lapack fallback code?).

Activity

  1. seberg commented on Nov 2, 2022

    @seberg
    seberg
    on Nov 2, 2022
    MemberAuthor
    More actions

    Ah... should have checked the code first. https://github.com/numpy/numpy/blob/main/numpy/linalg/lapack_lite/f2c_d_lapack.c includes lines such as:

        /* Local variables */
        static integer i__, j, k;
        static doublereal p, r__;
        static integer z__, ic, ii, kk;
        static doublereal cs;
        static integer is, iu;
        static doublereal sn;
        static integer nm1;
        static doublereal eps;
        static integer ivt, difl, difr, ierr, perm, mlvl, sqre;
    

    which is clearly not threadable. I suspect that some of the functions probably need state because they are called repeatedly or recurse (not sure).

    Nobody should use lapack-lite of course, so locking seems OK to me, but I am unsure at which level we should introduce the lock.

    We could tell the ufunc to never release the GIL if compiled without external BLAS. Or add some custom lock to all entry-points to lapack lite?
    Or can we update lapack lite or our C wrappers to be safe?

  2. seberg
    changed the title [-]BUG: Threading related issue in linalg (probably `eigvalsh`)[/-] [+]BUG: Lapack lite is not thread-safe (need to guard)[/+] on Nov 2, 2022
  3. seberg
    added
    00 - Bug
    component: numpy.linalg
    on Nov 3, 2022
  4. ngoldbaum commented on Jun 12, 2024

    @ngoldbaum
    ngoldbaum
    on Jun 12, 2024
    Member
    More actions

    We could tell the ufunc to never release the GIL if compiled without external BLAS. Or add some custom lock to all entry-points to lapack lite?
    Or can we update lapack lite or our C wrappers to be safe?

    Given how pervasive the use of global state in lapack_lite is, I don't think it's tenable to update it to be thread-safe. I think we could initialize a global lock in the lapack lite module initialization code and then acquire the global lock every time we call into the low-level fortran-translated code. Looking at the code, I doubt it's even reentrant, so we'd need to lock around every library call.

    Obviously this is terrible for the free-threaded build, so I think I'll detect the free-threaded build in meson.build and then force users in that build to use a real BLAS.

    Does that sound reasonable to you @seberg?

  5. seberg commented on Jun 13, 2024

    @seberg
    seberg
    on Jun 13, 2024
    MemberAuthor
    More actions

    Locking sounds fine to me. Forcing blas with freethreaded builds seems OK, no strong opinion. We could also force you to configure BLAS=none and print an error explaining that it is terrible (and maybe more so in free-threaded builds, although I am not sure it even is worse since the GIL was never sufficient to begin with).

    We had discussed sunsetting lapacklite before, so we could even consider forcing explicitly choosing it for all builds, but I am happy either way. (We even discussed sunsetting it completely, since I think wasm figured out how to build a proper BLAS.)

  6. rgommers
    closed this as completedin #26750on Jun 27, 2024
  7. rgommers
    added this to the 2.1.0 release milestone on Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bugcomponent: numpy.linalg

    Type

    No type

    Projects

    No projects

      Milestone

      • 2.1.0 release

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.