Repository navigation
Conversation
The scaled sum of squares divides by the running maximum. Once an infinite element becomes that maximum, inf/inf = NaN enters the sum and the result is NaN instead of +Inf (OpenBLAS's dnrm2_inf utest only covers an infinity among zeros, where the division is skipped). When the result is NaN, rescan the input: return a NaN element if there is one, +Inf otherwise. Finite inputs do not take this path.
nrm2_rvv.c (already used by RISCV64_ZVL128B and x280) is 23%/9%/8% faster for SNRM2 and 10%/6%/6% faster for DNRM2 than nrm2_vector.c on the SpacemiT X100 (n = 1024 / 32768 / 4M), and it propagates NaN inputs, which nrm2_vector.c can drop.
|
An additional data point before you review this. I ran the netlib LAPACK tests (
The DOUBLE failure is the same test in both builds. In The cause looks like sensitivity to rounding in the Householder norms, rather than a wrong norm:
Options: I can reduce this PR to the Inf fix in Update. I checked a DNRM2-only version of that rewrite, which leaves SNRM2 as in this PR, on top of this PR.
I can push it to this PR or open it separately after this one, whichever you prefer. |
Summary
This PR has two commits.
nrm2_rvv.creturns +Inf for an infinite element.maximum. Once an infinite element becomes that maximum,
inf/inf = NaNenters the sum, so the result is NaN instead of +Inf.
dnrm2_infutest places the infinity among zeros, where thedivision is skipped, so it does not catch this.
returns a NaN element if there is one, and +Inf otherwise. Finite inputs
never take this path.
nrm2_rvv.c.nrm2_rvv.cfor SNRM2 and DNRM2, instead ofnrm2_vector.c.nrm2_vector.ccan return a finite valuewhen the input contains a NaN.
Performance
Platform: SpacemiT K3, one X100 core (2.2 GHz), single thread, GCC 15.2. Each
number is the median ns per call for unit stride.
RISCV64_ZVL256B, develop vs this PR:
At every size, all patched processes were faster than all develop processes.
An exploratory job and a separate confirmation job (4 processes per build,
alternating) gave the same speed-ups within 0.1 percentage points.
The fix in commit 1 costs nothing. On RISCV64_ZVL128B, SNRM2 and DNRM2 with
and without it differ by at most 0.1% at every size.
Testing
OpenBLAS tests. The default
makegoal's tests give identical resultsbefore and after the patch, on both RISCV64_ZVL256B and RISCV64_ZVL128B:
utest 141/141, extension tests 1479/1479, and all BLAS/CBLAS tests PASSED.
Edge-case check against a long-double reference, 1224 cases. It covers
SNRM2/DNRM2/DSDOT with:
Disclosure: an AI coding agent (Anthropic Claude) prepared this patch, its
validation runs and this description on behalf of the account owner. All
numbers above come from archived runs on the board.