Skip to content

Incorrect result and non-deterministic hardware specific result with threaded OpenBLAS on Intel Xeon 8488C for matrix with sparse column #5267

Closed

Description

@jwasteneys-ccl

Summary
We are observing incorrect and non-deterministic results when performing matrix multiplication of the form t(X) %*% X in R when using OpenBLAS on Intel Xeon 8488C CPUs. The issue appears only when multi-threading. The bug does not occur on other CPU architectures (e.g., AMD EPYC, Intel 8259CL) and is not present when limiting OpenBLAS to a single thread or using R’s internal matrix multiplication routines.

System Information:

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Platinum 8488C
CPU family: 6
Model: 143
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
Stepping: 8
BogoMIPS: 4800.00

OS: Debian Linux

BLAS: OpenBLAS (/usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 )

Threading: pthreads

LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0

R version 4.4.1 (2024-06-14)

Reproducible Example:

Xsmall.csv

In this sample data, column 2449 is all exactly zero. When calculating X'X the element at [2448,2449] should also be exactly zero:

R
X <- as.matrix(read.csv("Xsmall.csv"))
options(matprod = "blas")
(t(X) %*% X)[2448, 2449]  # returns 0.002292634

# issue fixed with crossprod:
crossprod(X)[2448, 2449]  # returns exactly 0

# Manual sum:
sum(X[, 2448] * X[, 2449])  # returns exactly 0

# issue fixed with internal R implementation
options(matprod = "internal") 
(t(X) %*% X)[2448, 2449]  # returns exactly 0

Only on affected hardware (Intel 8488C), when using more than 1 thread, we see an incorrect value (~0.00229). Setting OPENBLAS_NUM_THREADS=1 makes the issue go away.

We have only reproduced the issue so far with the attached matrix. Note this matrix is ill-conditioned. However, this should not affect the result to this magnitude.

Here is a chart of the result we get for element [2448,2449] with respect to the OPENBLAS_NUM_THREADS setting:
Image

Observations

  • The issue does not appear on AMD EPYC 7R13 or Intel 8259CL.
  • Only observed with multithreaded OpenBLAS on AVX-512 capable hardware.
  • Dot products involving entirely zero columns behave unexpectedly under multithreading.
  • Manual dot product confirms result should be exactly 0.
  • Disabling threading (OPENBLAS_NUM_THREADS=1) makes the issue disappear.

Hypothesis
This appears to be a bug in the multithreaded dgemm implementation when using AVX-512. Potential contributing factors include:

  • Accumulation errors across SIMD lanes when computing many dot products in parallel.

  • Internal tiling and block accumulation strategies may be introducing rounding errors even when one operand is all zero.

  • The result (~0.0023) is too large to be explained by standard floating-point noise, suggesting a flaw in reduction logic.

Activity

  1. martin-frbg commented on May 16, 2025

    @martin-frbg
    Collaborator

    Both Intel systems would be using the same (AVX-512) DDOT kernel - are you sure you are using the same software versions on them ?

  2. jwasteneys-ccl commented on May 16, 2025

    @jwasteneys-ccl
    Author

    All the jobs are running on the same docker image, and I've compared all the session/environment info between them. AVX was just a hypothesis. Could it be related to Cascade lake vs Saphire rapids?

  3. martin-frbg commented on May 17, 2025

    @martin-frbg
    Collaborator

    Same DGEMM kernel code and parameters between the two Intel systems (the main difference is in BFLOAT16). But given that you seem to be using version 0.3.20 from three years ago (did not notice this initially, sorry), it is possible that it may not have identified either cpu correctly, potentially falling back to much older code. I wonder if you could rerun with environment variable OPENBLAS_VERBOSE=2 to have it print out what set of kernels it is using ?

  4. jwasteneys-ccl commented on May 20, 2025

    @jwasteneys-ccl
    Author

    When I turn on that variable I get:
    Core: Cooperlake

    I also tried setting OPENBLAS_CORETYPE=haswell, and I got the same (incorrect) results as on cooperlake

  5. jwasteneys-ccl commented on May 20, 2025

    @jwasteneys-ccl
    Author

    Actually I take that back, with multiple threads it looks like the results are different on Haswell vs Cooperlake:

    Core: Haswell
    [1] -2.660589e-10

    Core: Cooperlake
    [1] 0.002292634

  6. martin-frbg commented on May 20, 2025

    @martin-frbg
    Collaborator

    Unfortunately I cannot reproduce this (with R-4.5.0) on any system I have access to (which sadly does not include 8488C specifically), and I do not see what would single out that particular cpu.

  7. jwasteneys-ccl commented on May 21, 2025

    @jwasteneys-ccl
    Author

    Is there any other information that I could provide that would help to narrow it down?

  8. martin-frbg commented on May 21, 2025

    @martin-frbg
    Collaborator

    Just to be sure - are

    BLAS: OpenBLAS (/usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 )
    LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;

    both pointing to the same library ?

  9. jwasteneys-ccl commented on May 21, 2025

    @jwasteneys-ccl
    Author

    This is what I currently have set up (reproduces issue):

    Core: Cooperlake

    > print((t(Xsmall) %*% Xsmall)[2448, 2449] )
    [1] 0.002292634
    > sessionInfo()
    R version 4.4.1 (2024-06-14)
    Platform: x86_64-pc-linux-gnu
    Running under: Ubuntu 22.04.5 LTS
    
    Matrix products: default
    BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
    
    locale:
     [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
     [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
     [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
     [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
     [9] LC_ADDRESS=C               LC_TELEPHONE=C            
    [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
    
    time zone: Etc/UTC
    tzcode source: system (glibc)
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     
    
    loaded via a namespace (and not attached):
     [1] httr_1.4.7          compiler_4.4.1      R6_2.5.1           
     [4] cli_3.6.3           tools_4.4.1         base64enc_0.1-3    
     [7] curl_5.2.3          aws.signature_0.6.0 xml2_1.3.6         
    [10] aws.s3_0.3.21       digest_0.6.37       rlang_1.1.4 
    
  10. jwasteneys-ccl commented on May 21, 2025

    @jwasteneys-ccl
    Author

    Sorry I made a mistake for coretype=Haswell, the issue goes away.

    I had a piece of test code that set Xsmall[,2449] <- 1e-10 to see if a small number behaved differently than zero which gave me this result:

    Core: Haswell
    [1] -2.660589e-10
    

    When really the result should be:

    Core: Haswell
    [1] 0
    

    And for Cooperlake:

    Core: Cooperlake
    [1] 0.002292634
    

    I also rebuilt my docker container to be sure:

    > sessionInfo()
    R version 4.4.1 (2024-06-14)
    Platform: x86_64-pc-linux-gnu
    Running under: Ubuntu 22.04.5 LTS
    
    Matrix products: default
    BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
    LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
    

    I'm not sure what the difference between libblas.so.3 and libopenblasp-r0.3.20.so and why it switched from before.

    So it seems like it is related to Cooperlake in particular.

    I also tried with Skylake:

    Core: SkylakeX
    [1] 0
    

    So it seems like the issue is might be what you originally thought, and it's identifying the wrong kernel?

  11. martin-frbg commented on May 21, 2025

    @martin-frbg
    Collaborator

    I wonder if you could install the current OpenBLAS in your docker container to check ? The libblas.so.3 and libopenblas... in your sessioninfo output are (or should be) links to the same shared library, it is just that stock R has them as libblas.so.3 and liblapack.so.3 (and corresponding to the respective unoptimized library from the Reference-LAPACK/BLAS by default)

  12. jwasteneys-ccl commented on May 22, 2025

    @jwasteneys-ccl
    Author

    I think the version of ubuntu I'm using (ubuntu:jammy-20240125) pins the blas version, so I haven't been able to easily update it

  13. ilayn commented on Feb 27, 2026

    @ilayn
    Contributor

    In the project semicolon-lapack, I have been translating LAPACK to C on top of any CBLAS interface (but assuming OpenBLAS CBLAS as the default vendor).

    Similar to above, I've been using CBLAS interface with MSYS2 + LLVM-MINGW worker on the GitHub runners

    GitHub runner machine selection oscillates between two machines essentially; Intel Xeon and AMD EPYC.

    === CPU ===
    model name	: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
    Cores: 4
    
    === Compiler ===
    clang version 21.1.8
    
    === OpenBLAS ===
    mingw-w64-clang-x86_64-openblas 0.3.31-1
    

    This one goes fundamentally wrong with almost all tests, but passes with bit-parity on the LAPACK tests if it falls onto AMD EPYC 7763 64-Core. And since I wrote and verified the LAPACK Translations on other platforms, this gives me more confidence to speculate that this is somehow an optimization selection issue on Ice Lake or similar platforms. In fact when forced to have Haswell as the Coretype then all tests pass with no error.

    A passing test run when coretype is Haswell and a failing run with auto-select


    I compiled all the real valued failures (note that the tests are ported from Reference LAPACK) and sparred with an LLM and it spat out the following, it rings true but not sure if it is accurate enough to take action

    CLANG64 Failure Analysis — Intel Xeon 8370C (Ice Lake) + OpenBLAS 0.3.31

    153 pass, 131 fail. Both precisions affected, single much worse.

    Smoking Gun: Blocked vs Unblocked
    The clearest signal is in dchkge (double LU):

    nb=1 (unblocked dgetf2): ALL sizes, ALL matrix types fail
    nb=3 and nb=20 (blocked dgetrf): mostly pass
    Yet in single precision it's the opposite — sgetrf (blocked, uses sgemm) fails with residuals of 4.1e+05 to 6.7e+08, while dgetrf passes. And spotrf returns info=13,14,16,26,31 claiming the matrix is non-positive-definite on matrices that ARE positive definite — because ssyrk corrupts the panel update.

    Level Examples Residual
    Crash schkpo (SIGFPE), sdrvpo (signal 16) N/A — division by corrupted zero diagonal
    Garbage dchktr triangular inverse 8.9e+307 (near DBL_MAX)
    No significant digits dgeqrf Q orthogonality 4.8e+17 (~1/DBL_EPSILON)
    Completely wrong sgetrf n=50 6.7e+08 (~1/FLT_EPSILON)

    What's NOT broken

    All tridiagonal tests pass (no BLAS-3). All eigenvalue routines using only level-1/2 BLAS pass (dsterf, dsteqr, dstebz). Packed/banded with custom loops pass (dchksp). ddot, daxpy, idamax, dscal appear fine.

    Corrupted kernels

    Definite: sgemm, ssyrk, strsm (single-precision BLAS-3 — totally broken)
    Partial: dgemm (works for triangular panel updates in dgetrf, but broken for Householder reflector patterns in dlarfb)
    Partial: dgemv/dger (unblocked dgetf2 path corrupted)

    Bottom line

    The OpenBLAS Ice Lake AVX-512 kernels seem to be the culprit — not a precision issue but a "reading/writing wrong memory" issue producing results with zero significant digits. OPENBLAS_CORETYPE=Haswell forces AVX2 kernels and that's why the failures are gone.

  14. ilayn commented on Feb 27, 2026

    @ilayn
    Contributor

    Some more information, I changed the run to have MSYS2 + GCC and tested for auto-select vs. specifically choosing Prescott, again forcing the summary via the LLM but this time I manually edited the output and verified


    UCRT64 Failure Analysis

    Machine: AMD EPYC 7763 (same for all 3 jobs this run)
    OpenBLAS: 0.3.31 DYNAMIC_ARCH, selects Zen kernel

    Three distinct failure categories:

    1. ddrgev/ddrgev3/sdrgev/sdrgev3 test5 — Default Zen kernel (4 failures)

    These fail ONLY on Zen, pass on Prescott. Test5 is a bitwise eigenvalue comparison between DGGEV("V","V") (with eigenvectors) vs DGGEV("N","N") (without). The original Fortran test (ddrgev.f:780-783) also uses .NE. (bitwise). The idea is the QZ algorithm path should be identical regardless of eigenvector computation.

    The diffs reveal the mechanism — from the log:

    j=7: alphar diff=7.120e-307 alphai diff=5.340e-307 beta diff=6.924e+274
    These are near the deflation boundary: alpha0, betahuge. FMA instructions cause micro-rounding differences that push the QZ deflation criterion slightly differently in the two calls, producing different bit patterns for numerically-identical eigenvalues. Haswell kernel (what CLANG64 forces) doesn't trigger this because its FMA usage pattern is consistent across both code paths.

    1. ddrges/ddrges3 N=16_type=19 — Prescott only (2 failures)

    test(7)=4.5036e+15 (=1/ulp, catastrophic). Passes on Zen but fails on Prescott. The SSE2-only Prescott kernel has slightly worse accuracy that tips this specific edge case.

    1. sdrvrf4 n2_k50 — Prescott only (2 subcases)

    SSFRK vs cblas_ssyrk mismatch in single precision. Only 2/3136 subcases — another Prescott numerical edge case.

    Why CLANG64 differs

    CLANG64 is on the same machine (AMD EPYC 7763, Zen kernel detected), but we force OPENBLAS_CORETYPE=Haswell → 284/284 pass. The Haswell kernel produces consistent bitwise eigenvalues across DGGEV variants.

    Key question
    The default UCRT64 test uses the native Zen kernel. The simplest fix would be to also force Haswell on UCRT64's main test, like CLANG64. But this would hide a real FMA-related inconsistency. Alternatively, we could accept these 4 test 5 failures as known kernel-dependent behavior — the Fortran LAPACK test suite itself would likely show the same failures on a Zen mach

  15. martin-frbg commented on Feb 27, 2026

    @martin-frbg
    Collaborator

    Can't really look now but pretty sure "ZEN" (for AMD hardware without AVX512) uses exact same GEMM kernels as Haswell. Ice Lake uses AVX512 kernels originally written for Sky Lake.

  16. martin-frbg commented on Mar 2, 2026

    @martin-frbg
    Collaborator

    Not sure I buy the catastrophic GEMM failures seen with AVX512 kernels - unless perhaps it is a Windows-specific issue with CLANG (or with the code making dangerous assumptions about register availability or similar - at least some versions of LLVM were prone to erroring out on these kernels with "inline assembly requires more registers than available"). IMO completely broken kernels accessing the wrong parts of memory should have shown up as catastrophic errors in CI or real-world use long ago

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions