Repository navigation
gesvj/gsvj0: Avoid integer overflow in EMPTSW = N*(N-1)/2 - #1454
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1454 +/- ##
==========================================
+ Coverage 69.72% 70.04% +0.32%
==========================================
Files 6204 6208 +4
Lines 497194 497409 +215
Branches 23430 23450 +20
==========================================
+ Hits 346652 348401 +1749
+ Misses 150116 148574 -1542
- Partials 426 434 +8
... and 14 files with indirect coverage changes Continue to review full report in Codecov by Harness.
|
N*(N-1) overflows 32-bit signed arithmetic for N >= 46342 even though the quotient N*(N-1)/2 still fits (up to N = 65536). The overflowed threshold corrupts the NOTROT >= EMPTSW convergence decision (and traps under -ftrapv). Halve the even factor first; one of N, N-1 is always even so the division is exact and the intermediate never exceeds the final value. Part of Reference-LAPACK#1312
b307356 to
44124b0
Compare
mohawk2
left a comment
There was a problem hiding this comment.
The actual formula to avoid overflow is a thing of beauty. It did make me think that in C, the MOD would be achieved with a bitwise & 1.
The new tests do exercise a similarly-written formula, but do not constitute a guarantee that the actual code in the routine will stay using that formula. Is there a way to get at the calculation directly? Or even make it a routine that is called by the driver, but independently callable by a test program?
mohawk2
left a comment
There was a problem hiding this comment.
The updated test code is indeed a lot clearer with if instead of +abs(value-ref). The question about the test formula's lack of direct connection to the live code remains.
|
Instead of these new unit tests, which just check the or we could just replace the 40 with 66: This could break the threshold, so we would need to test it, but this should cover all the changes. |
49e4d56 to
5803475
Compare
|
ok, done |
f5efe37 to
1cf687b
Compare
|
I think these new unit tests for a one-line change are overkill when we can use the standard testing framework. I'd just increase the 40x40 case in the input file to 65x65. |
1cf687b to
808800f
Compare
|
ok |
|
Ah, sorry, the thresholds are failing on some machines now. I didn't test them all beforehand. Let me check if we can adjust the threshold or if it's too high |
xGSVJ0 is only reached through xGESVJ's triangular blocked path for N > 64, which the SVD tests (JOBA='G') never exercise. Add per-precision drivers calling xGESVJ with N=66 'L' and N=65 'U' inputs to drive the blocked path, validating the live factorization directly (residual and orthogonality) without duplicating the EMPTSW expression. A shared svd.in size bump was tried instead (40->65/66) but rejected: it perturbs unrelated bidiagonal accuracy checks in a platform-dependent way (N=66: CBD test(10)=6400; N=65: SBD test(9) ~40 locally, over threshold on arm64/newer gfortran), failing CI. Part of Reference-LAPACK#1312
808800f to
9d260b7
Compare
|
it passed, what did you change ? |
I changed nothing. You reverted the change back to your new tests, no? It's fine by me. We can merge this for now and have a look at the threshold and testing framework at some other time. |
|
ok, lets go, do you approve ? |
|
thank you both for the feedback |
N*(N-1) overflows 32-bit signed arithmetic for N >= 46342 even though the quotient N*(N-1)/2 still fits (up to N = 65536). The overflowed threshold corrupts the NOTROT >= EMPTSW convergence decision (and traps under -ftrapv). Halve the even factor first; one of N, N-1 is always even so the division is exact and the intermediate never exceeds the final value.
Part of #1312