You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Sorry submitted too early by accident, see edited description above. This issue is related to overflows when trying to pass the scipy test suite with BLIS).
Indeed. I imagine one would pay for it with performance in any case...
Scale
By using isamax to find the largest element.
Maybe the scale could only to be applied if max_value**2*n_elements>dtype.max to avoid needless calculations? Or some other way of detecting the overflow.
I think the extra calculation is probably not an issue (except division but that can be avoided). The biggest cost would be either the increased memory accesses (going through the array twice) or the loss of vectorization. My preference is method 1) for snrm2 and 2b) for dnrm2. @fgvanzee ?
This is kind of beyond my preferred level of expertise, and also hard to follow without more details / code samples. I nominate @devinamatthews to throw together a pull request.
?nrm2(), defined in frame/compat/bla_nrm2.c, is currently based on bli_?normfv(), which is defined in frame/util/bli_util_tapi.c, but is based on a helper function that is defined starting on line 313 in frame/util/bli_util_unb_var1.c. (Be sure to mind the #ifdef FE_OVERFLOW cpp branch.) That helper function currently uses another helper function that implements sumsqv, which is defined starting at line 1118 in frame/util/bli_util_unb_var1.c.
So the functions there can't have optimized implementations? Not that it really matters for nrm2 and similar but I just want to make sure this is the only place to change.
On Aug 30, 2019, at 12:27 PM, Field G. Van Zee ***@***.***> wrote:
?nrm2(), defined in frame/compat/bla_nrm2.c, is currently based on bli_?normfv(), which is defined in frame/util/bli_util_tapi.c, but is based on a helper function that is defined starting on line 313 in frame/util/bli_util_unb_var1.c. (Be sure to mind the #ifdef FE_OVERFLOW cpp branch.) That helper function currently uses another helper function that implements sumsqv, which is defined starting at line 1118 in frame/util/bli_util_unb_var1.c.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#332?email_source=notifications&email_token=ABLLYJ645LWVBFHOEXKDJZLQHFJ7FA5CNFSM4ISOVJSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5SIZLI#issuecomment-526683309>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABLLYJYVU5J2SYVZDVT5BZ3QHFJ7FANCNFSM4ISOVJSA>.
So the functions there can't have optimized implementations?
As those operations are currently classified, correct. Let me know if it becomes and problem and I can think about reclassifying those functions as level-1v, at which time they will "first-class citizens" of the cntx_t.
@rth by any chance were you testing on a Mac? I looked at the code and in fact it is already applying a scale factor, except that it tries to optimize by computing dot(x,x) first and checking for overflow exceptions. On MacOS, though, floating point exceptions are never generated.
It looks like the behavior has been the same since Nov. 2016. I pushed in a new commit ( a264132 ) to #334 that unconditionally disables the use of dot. See if that works for you.
@fgvanzee can you try and reproduce this and see if the fix in #334 works? @rth is this an array of length 1e20? Are the values drawn from some distribution?
Activity
[-]nrm2[/-][+]nrm2 overflow for large float32[/+]rth commentedon Aug 30, 2019
(Sorry submitted too early by accident, see edited description above. This issue is related to overflows when trying to pass the scipy test suite with BLIS).
[-]nrm2 overflow for large float32[/-][+]snrm2 overflow for large input floats[/+]devinamatthews commentedon Aug 30, 2019
Possible solutions:
Cast f32 to f64 before multiplication and accumulate in f64 (looks like OpenBLAS does this maybe?).
Scale:
isamaxto find the largest element.isamaxover chunks that fit in cache and normalizing each chunk individually.In each case the scale factor should be a power of two to avoid explicit division.
rth commentedon Aug 30, 2019
Indeed. I imagine one would pay for it with performance in any case...
Maybe the scale could only to be applied if
max_value**2*n_elements>dtype.maxto avoid needless calculations? Or some other way of detecting the overflow.devinamatthews commentedon Aug 30, 2019
I think the extra calculation is probably not an issue (except division but that can be avoided). The biggest cost would be either the increased memory accesses (going through the array twice) or the loss of vectorization. My preference is method 1) for
snrm2and 2b) fordnrm2. @fgvanzee ?fgvanzee commentedon Aug 30, 2019
This is kind of beyond my preferred level of expertise, and also hard to follow without more details / code samples. I nominate @devinamatthews to throw together a pull request.
devinamatthews commentedon Aug 30, 2019
@fgvanzee can you give me a list of the files I need to edit? I'm not sure I could find them all.
fgvanzee commentedon Aug 30, 2019
?nrm2(), defined inframe/compat/bla_nrm2.c, is currently based onbli_?normfv(), which is defined inframe/util/bli_util_tapi.c, but is based on a helper function that is defined starting on line 313 inframe/util/bli_util_unb_var1.c. (Be sure to mind the#ifdef FE_OVERFLOWcpp branch.) That helper function currently uses another helper function that implementssumsqv, which is defined starting at line 1118 inframe/util/bli_util_unb_var1.c.devinamatthews commentedon Aug 30, 2019
So the functions there can't have optimized implementations? Not that it really matters for nrm2 and similar but I just want to make sure this is the only place to change.
rvdg commentedon Aug 30, 2019
fgvanzee commentedon Aug 30, 2019
As those operations are currently classified, correct. Let me know if it becomes and problem and I can think about reclassifying those functions as level-1v, at which time they will "first-class citizens" of the
cntx_t.devinamatthews commentedon Aug 30, 2019
@rth by any chance were you testing on a Mac? I looked at the code and in fact it is already applying a scale factor, except that it tries to optimize by computing dot(x,x) first and checking for overflow exceptions. On MacOS, though, floating point exceptions are never generated.
rth commentedon Aug 30, 2019
No, I was testing on Linux (Gentoo), using blis 0.6.0 though -- maybe this was recently changed?
devinamatthews commentedon Aug 30, 2019
It looks like the behavior has been the same since Nov. 2016. I pushed in a new commit (
a264132 ) to #334 that unconditionally disables the use of dot. See if that works for you.
rth commentedon Aug 30, 2019
I haven't built BLIS from sources yet (and won't be able to look into it before next week).
Are you saying that you are not able to reproduce the overflow on master with a unit test applying snrm2 on an array [1e20] of dtype float (32 bit)?
devinamatthews commentedon Aug 30, 2019
@fgvanzee can you try and reproduce this and see if the fix in #334 works? @rth is this an array of length 1e20? Are the values drawn from some distribution?
fgvanzee commentedon Aug 30, 2019
@devinamatthews I think @rth means that the array has one element containing the value 1e20.
Yeah, I can try to reproduce.
rth commentedon Aug 30, 2019
Sorry for the confusion. It's a 1D array with a single element equal to 1e20, so that when you square it, float32 would overflow.
isuruf commentedon Aug 30, 2019
I can reproduce this issue on linux and can confirm that #334 works
devinamatthews commentedon Aug 30, 2019
@fgvanzee saved by the bell. I think merging #334 is the ticket then, unless you want to clean it up/add a comment or something.
fgvanzee commentedon Aug 30, 2019
I also can confirm that
snrm2_()on 1e20 doesn't work. (I actually get-nan.)I'll take a look at it. Thanks for your quick work, everyone.
rth commentedon Sep 2, 2019
For future reference, here is a python snipped reproducing the original issue,
and I can confirm that #334 fixes it.