Skip to content

Errors when using OpenBLAS through NumPy on Windows 10 2004 #2709

Closed

Description

@bashtage

This issue only appears on Windows 10 2004 (19041). It does not appear on Windows 10 1909 (18363).

On a fresh install of NumPy from pip on a 2004 machine, e.g,

pip install numpy ipython

open ipython and enter

import numpy as np
a = np.arange(13 * 13, dtype=np.float64)
a.shape = (13, 13)
a = a % 17
va, ve = np.linalg.eig(a)

This produces an error:

 ** On entry to DGEBAL parameter number  3 had an illegal value
 ** On entry to DGEHRD  parameter number  2 had an illegal value
 ** On entry to DORGHR DORGQR parameter number  2 had an illegal value
 ** On entry to DHSEQR parameter number  4 had an illegal value
---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
<ipython-input-1-bad305f0dfc7> in <module>
      3 a.shape = (13, 13)
      4 a = a % 17
----> 5 va, ve = np.linalg.eig(a)

<__array_function__ internals> in eig(*args, **kwargs)

c:\anaconda\envs\py-pip\lib\site-packages\numpy\linalg\linalg.py in eig(a)
   1322         _raise_linalgerror_eigenvalues_nonconvergence)
   1323     signature = 'D->DD' if isComplexType(t) else 'd->DD'
-> 1324     w, vt = _umath_linalg.eig(a, signature=signature, extobj=extobj)
   1325
   1326     if not isComplexType(t) and all(w.imag == 0.0):

c:\anaconda\envs\py-pip\lib\site-packages\numpy\linalg\linalg.py in _raise_linalgerror_eigenvalues_nonconvergence(err, flag)
     92
     93 def _raise_linalgerror_eigenvalues_nonconvergence(err, flag):
---> 94     raise LinAlgError("Eigenvalues did not converge")
     95
     96 def _raise_linalgerror_svd_nonconvergence(err, flag):

LinAlgError: Eigenvalues did not converge

What makes me suspect that it is OpenBLAS related is:

  1. It does not happen when using MKL.
  2. It does not happen when using LAPACK-lite that ships with NumPy and is used as a fallback.

On the other hand, it may likely be a Windows bug since:

  1. It does not occur before 2004.
  2. It does not occur when using 32-bit Python on the same system.
  3. It does not occur when running Pythin in WSL on the same machine whether using WSL1, which runs Linux binaries directly on Windows, or WSL2, which runs them in a hypervisor.

Any help is appreciated.

The related NumPy issue is numpy/numpy#16744.

Activity

  1. martin-frbg commented on Jul 8, 2020

    @martin-frbg
    Collaborator

    While I agree that it looks "OpenBLAS related", I am not yet convinced it is a bug in OpenBLAS itself, particularly if it only happens with/after the Win10 update. The error messages look as if argument passing from C (BLAS) to FORTRAN (LAPACK) functions took a hit.
    Perhaps it would make sense to try and build OpenBLAS on a Win10-2004 system (assuming that your pip install just pulled a precompiled binary). Btw it might also be relevant if this affects only particular cpu generations.

  2. bashtage commented on Jul 8, 2020

    @bashtage
    Author

    I ran openblas_utext.exe without any issues. Is there an equivalent to the lapack-test directive in the *nix make file?

  3. martin-frbg commented on Jul 8, 2020

    @martin-frbg
    Collaborator

    The executables in test (if you have them) are at least fortran files calling into C routines, but the lapack-test is currently not available in the cmake build. I'll see if it is sufficient to add its subdirectory to the main CMakeLists.txt but I suspect some things may need adjusting compared to the stock cmake support in Reference-LAPACK.

  4. brada4 commented on Jul 9, 2020

    @brada4
    Contributor

    Indeed pip will install binary by default.
    It needs parameter --no-binary :all: to force compilation of all module libraries.

    The illegal value parameters are all integers. This might mean that LAPACK and BLAS has different idea of integer sizes. Could you copy numpy directory from working version and test again?It just looks as broken wheel package pulled from pypi.

  5. bashtage commented on Jul 9, 2020

    @bashtage
    Author

    I tried the nightly from 5/7/20 but this also failed. It has a different version than 1.19 although it isn't obvious how it differs other than it has a different hash.

    I'll try to build myself in the next few days.

  6. brada4 commented on Jul 9, 2020

    @brada4
    Contributor

    It is not directly made by OpenBLAS, could you point to hashes you talk about so that we can have a look at package content?

    https://pypi.org/project/numpy/#files

  7. brada4 commented on Jul 10, 2020

    @brada4
    Contributor

    @bashtage what would be interesting to compare numpy wheels (' hashes) in pip caches. Looking into archives they include 0.3.9-dev version which is anything from development tree (maybe known broken) between 0.3.9 and 0.3.10.
    I think we need to add git tag as once proposed out of fact that downstreams do not stick to the releases.

  8. bashtage commented on Jul 10, 2020

    @bashtage
    Author

    From NumPy 1.19.0:

    libopenblas.NOIJJG62EMASZI6NYURL6JBKM4EVBGM7.gfortran-win_amd64.dll

    strings indicates this is 3.9

    From NumPy nightly 5/7/2020:

    libopenblas.VN4TFHCG6GCB7E53NOJHJWQ4PL7VXRV3.gfortran-win_amd64

    strings indicates this is 3.10

    [It is my assumption that the large string is a hash]

  9. martin-frbg commented on Jul 10, 2020

    @martin-frbg
    Collaborator

    numpy should know which hash they packaged, most likely it is a snapshot from just a few days before the 0.3.10 release to get the fix for inadvertent use of avx512 on haswell (in dynamic_arch builds created on skx). most likely a red herring when the issue seems so closely tied with a microsoft patch.

  10. brada4 commented on Jul 10, 2020

    @brada4
    Contributor

    Is the hash on the working system matching any of these two?

  11. martin-frbg commented on Jul 23, 2020

    @martin-frbg
    Collaborator

    There is a (small) chance that #2729 may have fixed this (inconsistent declarations of the size of the GEMM buffer in DYNAMIC_ARCH builds)

  12. martin-frbg commented on Jul 29, 2020

    @martin-frbg
    Collaborator

    @bashtage Any news on this ?

  13. bashtage commented on Jul 29, 2020

    @bashtage
    Author

    NumPy is using head in their latest nightlies and it is still producing the same issues.

    Edit: I do think it is more and more likely a Windows bug. It even appears when coretype is set to Prescott. I had planned to reach out to a Microsoft Python advocate to see if I can get any bandwidth beyond reporting it through standard channels. It won't show up in CI for a very long time since most CI instances are using build 17xxx of Windows, while 19041+ is required for the bug to appear.

  14. brada4 commented on Jul 29, 2020

    @brada4
    Contributor

    Prescott

    What is your CPU? Like CPU-Z screenshot would be nice
    Should be fixable setting OPENBLAS_CORETYPE= SKYLAKEX/HASWELL/SANDYBRIDGE for AVX512/AVX2/AVX respectively.

  15. bashtage commented on Jul 29, 2020

    @bashtage
    Author
  16. 55 remaining items

  17. carlkl commented on Oct 8, 2020

    @carlkl

    @brada, yes, MSVC does not emit MMX or FPU in 64bit mode. But the MS runtime libraries are using FPU code and the use it in an unexpected way, hence the problems. As long as OpenBLAS is using FPU or MMX code itself in Win64 in the gcc builds OpenBLAS must care about this problem.
    FCLEX and EMMS instructions are not harmful and costs only some cycles. So why not add them in the right place?

  18. martin-frbg commented on Oct 8, 2020

    @martin-frbg
    Collaborator

    Do we know by know that the FCLEX (or FNCLEX) plut EMMS combo is sufficient to clear this sorry state ?

  19. carlkl commented on Oct 8, 2020

    @carlkl

    I will try it as soon as I can. I have to setup my development machine first.

  20. martin-frbg commented on Oct 8, 2020

    @martin-frbg
    Collaborator

    Further to this, do we know that routines using only MMX are definitely affected by this DLL bug as well, or is this just an assumption based on them sharing the same registers ? (Thinking MMX is a bit more likely to still be in use than x87, so there should be more users and programs affected by the bug)

  21. carlkl commented on Oct 8, 2020

    @carlkl

    I will try it as soon as I can. I have to setup my development machine first.

  22. carlkl commented on Oct 8, 2020

    @carlkl

    @martin-frbg, I'm not a assembler guru. My idee what happens with this crazy issue are described here: #2709 (comment) and are the results of reflection after scamming numerous documents, stackoverflow/blog contributions. A huge time sink btw. EDIT: we should file MS an invoice :-(

    I have an idea about why MMX is not affected: Maybe because MMX uses the registers as is and not as a circulating stack. But this is speculation. So from the MMX point of view the registers can be simply used and erroneous values will be overwritten.

    The documentation says:

    The EMMS instruction must be used to clear the MMX technology state at the end of all MMX technology procedures or subroutines and before calling other procedures or subroutines that may execute x87 floating-point instructions. If a floating-point instruction loads one of the registers in the x87 FPU data register stack before the x87 FPU tag word has been reset by the EMMS instruction, an x87 floating-point register stack overflow can occur that will result in an x87 floating-point exception or incorrect result.

    EMMS operation is the same in non-64-bit modes and 64-bit mode.

    I have drawn two conclusions from that:

    1. Before using the FPU EMMS can heal the the FPU state.
    2. This instruction is not needed for MMX usage

    But again: I'm not an assembler guru.

  23. brada4 commented on Oct 9, 2020

    @brada4
    Contributor

    ---, yes, MSVC does not emit MMX or FPU in 64bit mode. But the MS runtime libraries are using FPU code and the use it in an unexpected way, hence the problems. As long as OpenBLAS is using FPU or MMX code itself in Win64 in the gcc builds OpenBLAS must care about this problem.
    FCLEX and EMMS instructions are not harmful and costs only some cycles. So why not add them in the right place?

    It looks like somehow the stuf that applied to userspace WDM (printer drivers) that mmx state is corrupted over context switch, came to generic applications too. Would be interesting to see if windows vista compatibility layer fixes this.

  24. martin-frbg commented on Oct 9, 2020

    @martin-frbg
    Collaborator

    @carlkl think you may be tagging an unrelated user in your replies to brada4 here. @brada4 from your suggestions I am not sure if you have been following this thread...

  25. carlkl commented on Oct 9, 2020

    @carlkl

    @martin-frbg, I think you are right.

  26. mattip commented on Oct 13, 2020

    @mattip
    Contributor

    Commenting on this closed issue to update that in numpy/numpy#17547 I added code to call emms after a call to fmod in windows, so now we have both a belt and suspenders (does that work in English?)

  27. bashtage commented on Oct 13, 2020

    @bashtage
    Author

    @mattip Belt and bracers</uk translation>

  28. added a commit that references this issue on Feb 5, 2021
  29. added a commit that references this issue on Sep 20, 2021
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

    Bug in other softwareCompiler, Virtual Machine, etc. bug affecting OpenBLAS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions