Skip to content

HERK and HER2K propagate an ignored imaginary diagonal into the real result #962

Open

Description

@vera-rubin

CHERK, ZHERK, CHER2K and ZHER2K return NaN real diagonal entries when the ignored imaginary diagonal of C contains an initialized quiet NaN. With finite A, B, alpha and beta, the one-element examples should return 3+0i or 4+0i.

Version and environment

BLIS commit a8037cfc4330030c726efaec1ffeb1f93d468aa3. Configure reports version 3.0. git describe reports 0.9.0-225-ga8037cfc. The pinned commit also resolved as upstream master when checked on 2026-10-11.

Reproduced on AMD EPYC 9J14, Linux 6.17.0-1020-oracle x86_64, GCC 13.3.0, glibc 2.39, GNU Make 4.3 and Bash 5.2.21. BLAS integers are 32-bit. Library flags were the configuration defaults. The caller used -std=c99 -O2 without fast-math.

Reference controls used BLAS/CBLAS built from LAPACK v3.12.0, commit 04b044e020a3560ccfa9988c8a80a1fb7083fc2e, with GCC and GNU Fortran 13.3.0.

Reproduction

Save this CC0 example as repro.c in an empty directory.

#include "blis.h"
#include <math.h>
#include <stdio.h>
int main(void) {
    const f77_int n=1,k=1,ld=1;
    const char u='U',tr='N';
    const float sf=1,bf=1;
    const double sd=1,bd=1;
    const scomplex sa={1,0};
    const dcomplex da={1,0};
    scomplex sc={2,NAN},sc2={2,NAN};
    dcomplex dc={2,NAN},dc2={2,NAN};
    cherk_(&u,&tr,&n,&k,&sf,&sa,&ld,&bf,&sc,&ld);
    zherk_(&u,&tr,&n,&k,&sd,&da,&ld,&bd,&dc,&ld);
    cher2k_(&u,&tr,&n,&k,&sa,&sa,&ld,&sa,&ld,&bf,&sc2,&ld);
    zher2k_(&u,&tr,&n,&k,&da,&da,&ld,&da,&ld,&bd,&dc2,&ld);
    /* Independent scalar formulas: 1*conj(1)+2=3; twice that product+2=4. */
    printf("cherk:  (%.9g,%.9g), expected (3,0)\n",sc.real,sc.imag);
    printf("zherk:  (%.17g,%.17g), expected (3,0)\n",dc.real,dc.imag);
    printf("cher2k: (%.9g,%.9g), expected (4,0)\n",sc2.real,sc2.imag);
    printf("zher2k: (%.17g,%.17g), expected (4,0)\n",dc2.real,dc2.imag);
    return !(sc.real==3 && sc.imag==0 && dc.real==3 && dc.imag==0 &&
             sc2.real==4 && sc2.imag==0 && dc2.real==4 && dc2.imag==0);
}

Run these Bash commands from that directory. This selects the tested generic implementation in the CBLAS-enabled x86_64 build.

git clone https://github.com/flame/blis.git blis
git -C blis checkout --detach a8037cfc4330030c726efaec1ffeb1f93d468aa3
cd blis
./configure -t pthreads --enable-cblas x86_64
make -j3
cd ..
gcc -std=c99 -O2 -I "$PWD/blis/include/x86_64" repro.c \
  -L "$PWD/blis/lib/x86_64" -Wl,-rpath,"$PWD/blis/lib/x86_64" \
  -lblis -lm -lpthread -o repro
BLIS_ARCH_TYPE=generic BLIS_NUM_THREADS=1 ./repro

The reproducer exits 1 when its expected result differs.

Expected and observed

The C argument contract says the diagonal imaginary fields "need not be set, they are assumed to be zero". It also requires zero imaginary fields on exit. See CHERK lines 131-133, ZHERK lines 131-133, CHER2K lines 155-157 and ZHER2K lines 156-158.

Here n=k=1, A=B=1, alpha=beta=1 and the real input diagonal is 2. The formulas give 1+2=3 for HERK and 1+1+2=4 for HER2K. All buffers are explicitly initialized. Observed output:

cherk:  (nan,0), expected (3,0)
zherk:  (nan,0), expected (3,0)
cher2k: (nan,0), expected (4,0)
zher2k: (nan,0), expected (4,0)

Replacing each input imaginary diagonal with zero gives the expected finite results. The same four calls linked solely to Reference BLAS also return 3+0i and 4+0i.

Callers relying on the documented ignored diagonal can receive NaN in otherwise finite Hermitian updates; subsequent numerical computations may propagate that NaN. Downstream application effects were not tested.

Source observation

HERK and HER2K in frame/3/bli_l3_oapi_ex.c call GEMMT before clearing the imaginary diagonal with bli_setid. Inference: full complex beta arithmetic uses the stored ignored field, so 0*NaN enters the real result before that cleanup. The input diagonal needs real-only treatment before this arithmetic.

Scope

The failure reproduced in both fresh source builds below, with 1 and 3 requested threads.

Configure command Selected implementation
./configure -t pthreads auto zen3
./configure -t pthreads --enable-cblas x86_64 zen3, skx, haswell, generic

Independent checks covered both triangles, NoTrans and ConjTrans, single and double complex, n=1 and n=3 with k=1, and NaN, infinity and zero imaginary diagonals. The fat build also covered CBLAS row-major and column-major calls. Disabling induced methods retained the failure. All finite controls passed. The full Reference BLAS/CBLAS check passed.

The original caller also reproduced the failure at -O0. This was not a library rebuild at -O0. These small cases do not establish that three workers execute each routine. Other hosts, build configurations and arbitrary input sizes were not covered by the independent verification.

Retained verification records

Independently reproduced on 2026-10-11; verifier commit 3b8d9e2cd7a8db0db770794ede5a3cd1c45c4d1e (verify/blis-r01, repository chiplab-research/bughunt).

Retained records at that verifier commit:

  • findings/blis/hermitian-diagonal-nan/VERIFY.md
  • findings/blis/verify-support/ENVIRONMENT.md
  • findings/blis/verify-support/results.json
  • findings/blis/verify-support/reference-results.json
  • findings/blis/verify-support/hermitian.c

BLIS focused (results.json, focused/hermitian/fat-generic-1, exit 1):

ignored-diagonal tests=192 mismatches=192; finite controls=96 failures=0

Reference BLAS original (reference-results.json, exit 0):

cherk:  (3,0), expected (3,0)
zherk:  (3,0), expected (3,0)
cher2k: (4,0), expected (4,0)
zher2k: (4,0), expected (4,0)

Reference BLAS/CBLAS focused (VERIFY.md and ENVIRONMENT.md, exit 0):

ignored-diagonal tests=192 mismatches=0; finite controls=96 failures=0

ChipLab ref: CLAB-2026-270

Found by ChipLab's AI verification agents and independently reproduced.

Activity

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