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
I noticed that several configurations, specifically the AMD ones, just use -O2, which means they'll have no vectorization past the optimized kernels -- just GEMM? (They also use -fomit-frame-pointer, which is redundant with gcc -O, but obviously harmless.)
It may be sensible generally to build non-critical routines with -O2 rather than O3, as O2 is generally better tested, may produce smaller code, and should build faster. However, -O3, or something like it, should presumably be in CRVECFLAGS, at least.
Also, with GCC, at least CRVECFLAGS should have -funsafe-loop-optimizations added to get the rest of the reference kernels vectorized (see #259) and minimize worries about correctness, i.e.
in all the make_defs fragments, or perhaps somewhere common.
-funsafe-loop-optimizations vectorizes all the routines -ffast-math does (on haswell) apart from frame/util/bli_util_unb_var1.c.
I could contribute the changes if they seem sensible, depending on whether common gcc flags should be duplicated in the make fragments or be abstracted somewhere.
@loveshack I agree that the optimization flags for both optimized kernels and reference kernels can be raised to -O3 for all x86_64-based configurations. I would go further and say that I'm comfortable with -O3 for general framework code. In other words, I'm okay using -O3 wherever any optimization is permitted.
I would also be open to including -funsafe-loop-optimizations when compiling reference kernels, as you have shown in your snippet above. I've played with it a little bit, combining the option with -Wunsafe-loop-optimizations and, at least with gcc 5.4.0, the only warnings come from packed and banded level-2 operations in the BLAS compatibility layer, which are currently implemented via f2c-based translations from Fortran (since BLIS does not natively implement these operations).
-funsafe-loop-optimizations vectorizes all the routines -ffast-math does (on haswell) apart from frame/util/bli_util_unb_var1.c.
Could you explain the above comment? I don't quite follow. Are you suggesting that no optimization flags be used when compiling bli_util_unb_var1.c? Or suggesting that that is already the case? (I can't find evidence in the top-level Makefile that this file is given any special treatment.)
Quick update: I'm having trouble getting the new flags through our Travis CI tests. I get the following error:
+sde-external-8.16.0-2018-01-30-lin/sde64 -cpuid_in ./travis/cpuid/piledriver.def -- ./test_libblis.x
TID 0 SDE-ERROR: Executed instruction not valid for specified chip (ICELAKE): 0x9172a5: bextr_xop rax, rcx, 0x103
Image: /home/travis/build/flame/blis/test_libblis.x+0x5172a5 (in multi-region image, region# 0)
Function: bli_dsetv_piledriver_ref
Instruction bytes are: 8f ea f8 10 c1 03 01 00 00
I'm still trying to isolate exactly what is causing the problem. At first I figured it was the addition of -funsafe-loop-optimizations, but I backed out all of those changes and the error persists. I'm now making sure this isn't being caused by a change on Travis's side by rerunning the corresponding test from a recent commit that had previously passed. (And indeed it did pass again.) The only other (seemingly) relevant changes I made are the bump from -O2 to -O3 for some configurations and removal of -fomit-frame-pointer.
Thanks for sussing that out. gcc isolates the TBM instruction set via -mtbm, and so I can probably fix this nonsense with -mno-tbm. (And maybe disable XOP and LWP while I'm at it.)
@loveshack I've reverted back to using -funsafe-loop-optimizations. Feel free to review those changes while we do further testing in the lead up to merging back into master.
If you are going to use Intel SDE to try to emulate AMD processors, I recommend setting compiler flags that limit the code generation to the union ISA (Intel & AMD) and confirm any exceptions to this with the SDE documentation.
The following seem like relevant references:
Oh heck. Sorry I've wasted your time with a typo somehow. The option should be -funsafe-math-optimizations, not loop. It must have been either some paste error or a bad Emacs expansion.
I did test the vectorization with the right flag before I found the option to treat the kernels separately. The comment was that compared with fast-math, it only missed vectorization in the one file, which isn't a ukernel.
I did try unsafe-math-optimizations, but it didn't help dgemm, and has been removed from recent gcc anyhow.
I'll look at the change when I can. Apologies for the error.
--
Sent from a pocket telegraph machine; excuse the result.
It occurs to me that changed flags should be checked with the testsuite
on other architectures than x86_64; I don't know if you (can) do that.
I can do it on the Fedora architectures by modifying the build, but I
only have access to most of them via the build system if something needs
debugging, and arm might time out. It probably makes sense to do that
with the new gemm kernel, though.
@jeffhammond I'm having trouble following your suggestion. Are you suggesting that we enable FMA4, XOP, TBM, and LWP, and then somehow ignore the invalid instruction errors that come out of the SDE?
@loveshack It's okay, these things happen. I'm just glad I didn't spend too much time on it. :) As for using -funsafe-math-optimizations, I'm a bit more wary of these kinds of optimizations than those implied by -funsafe-loop-optimizations. Let me play with it a bit and see how the BLAS test drivers and BLIS testsuite respond to them.
It occurs to me that changed flags should be checked with the testsuite on other architectures than x86_64; I don't know if you (can) do that.
@loveshack I think our way of doing this is typically to let Travis CI chew on the new build (which uses the SDE as one of the tests) and see what happens. But I may be misunderstanding your comment.
As for using
`-funsafe-math-optimizations`, I'm a bit more wary of these kinds of
optimizations than those implied by `-funsafe-loop-optimizations`. Let
me play with it a bit and see how the BLAS test drivers and BLIS
testsuite respond to them.
I think I said somewhere that I successfully ran the full testsuite with
it (actually fast-math, I think) for Haswell.
> It occurs to me that changed flags should be checked with the
testsuite on other architectures than x86_64; I don't know if you
(can) do that.
@loveshack I think our way of doing this is typically to let [Travis
CI](https://travis-ci.org/flame/blis/) chew on the new build (which
uses the SDE as one of the tests) and see what happens. But I may be
misunderstanding your comment.
That sounds like multiple x86_64 micro-architectures as opposed to, say,
aarch64, which is what I meant. (You can run under qemu emulation, but
rather slowly.) Apart from x86 and x86_64, the Fedora build system has
ppc64le, armhf, aarch64, and s390 for building packages, if that's
useful. Also I currently have access to various generations of real
x86_64 from Magny Cours (probably not for long) through to SKX.
I think I said somewhere that I successfully ran the full testsuite with it (actually fast-math, I think) for Haswell.
I must have missed that. (Sorry.) But please humor me. I am somewhat conservative when it comes to numerical issues, mostly because I am wary of issues lurking in that region just beyond my expertise. :)
That sounds like multiple x86_64 micro-architectures as opposed to, say, aarch64, which is what I meant.
Ohhh, I see what you mean. You meant other architectures such as ARM or Power. Yeah, our methods of testing changes of any sort for those non-x86_64 architectures is more limited.
Note that the Intel compiler(s?) default to something like fast-math, or some subset, so you'd need to turn that off in rules for icc if you're worried.
--
Sent from a pocket telegraph machine; excuse the result.
My assumption here is that for complex numbers, the approximation x/y = x*(1/y) is good enough, but 1/y = conj(y)/norm(y) is not. This means that the compiler should do something special to compute ialpha (i.e. gcc should use __divdc3), but the loop can be vectorized. Here are the results for different compilers and flags (all -O3 and targeting Haswell):
Compiler \ Flags
Default
-funsafe-math-optimizations or -fp-model fast=1
+ -ffinite-math-only
-ffast-math or -fp-model fast=2
gcc
Uses __divdc3 and __muldc3 in loop
Same
Same
__divdc3 optimized to conj(y)/norm(y)
clang
Same as gcc except checks for NaN outside of __muldc3
Loop vectorized but still checks for NaN
Loop fully vectorized
Same as gcc
icc
Uses __divdc3 (inlined), loop vectorized
Same
N/A
Same as gcc
So, it seems that according to the assumptions above, the "right" flags are -funsafe-math-optimizations -ffinite-math-only for clang and the default flags for icc, but there don't seem to be a single set of flags for gcc that do what I want.
Unless of course people are OK with -fcx-limited-range and then -ffast-math or -fp-model fast=2 should be fine for BLIS.
I should also mention that if you change the inner loop to:
for (inti=0;i<n;i++) x[i] /= *alpha;
then every compiler only vectorizes with the highest flags (i.e. they don't seem to separate the x/y = x*(1/y) and 1/y = conj(y)/norm(y) optimizations).
@devinamatthews Thanks for reporting these details, Devin. It sounds like your preliminary conclusion is that gcc flags should not be modified yet, but that we could begin using -funsafe-math-optimizations -ffinite-math-only for clang?
@fgvanzee do you have any comment of -fcx-limited-range?
I'm afraid I don't have anything super-intelligent to add at this time.
Forgive me if I'm reading your table incorrectly, but it sounds like while there is no one set of flags that does what you want in gcc, -funsafe-math-optimizations seems to be a step in the right direction. Is the only thing missing the vectorization of the loop?
@fgvanzee Yes. Although, I suppose since BLIS uses level-0 macros we could implement complex multiplication in terms of real multiplication which would recover vectorizability with just -funsafe-math-optimizations.
since BLIS uses level-0 macros we could implement complex multiplication in terms of real multiplication which would recover vectorizability with just -funsafe-math-optimizations.
The other thing that -ffinite-math-only affects is multiplying by zero. Most kernels special case this (e.g. beta=0), but for example if you fake real*complex as complex*complex with an imaginary zero component then this matters.
The other thing that -ffinite-math-only affects is multiplying by zero.
Then it sounds like it's not that important in our case, for either gcc or clang. BLIS's level-0 scalar macros almost always manually optimize situations where you are multiplying by real x complex to avoid the zero imaginary component entirely.
Activity
fgvanzee commentedon Feb 18, 2019
@loveshack I agree that the optimization flags for both optimized kernels and reference kernels can be raised to
-O3for all x86_64-based configurations. I would go further and say that I'm comfortable with-O3for general framework code. In other words, I'm okay using-O3wherever any optimization is permitted.I would also be open to including
-funsafe-loop-optimizationswhen compiling reference kernels, as you have shown in your snippet above. I've played with it a little bit, combining the option with-Wunsafe-loop-optimizationsand, at least with gcc 5.4.0, the only warnings come from packed and banded level-2 operations in the BLAS compatibility layer, which are currently implemented viaf2c-based translations from Fortran (since BLIS does not natively implement these operations).Could you explain the above comment? I don't quite follow. Are you suggesting that no optimization flags be used when compiling
bli_util_unb_var1.c? Or suggesting that that is already the case? (I can't find evidence in the top-level Makefile that this file is given any special treatment.)Standardized optimization flags in make_defs.mk.
fgvanzee commentedon Feb 19, 2019
Quick update: I'm having trouble getting the new flags through our Travis CI tests. I get the following error:
I'm still trying to isolate exactly what is causing the problem. At first I figured it was the addition of
-funsafe-loop-optimizations, but I backed out all of those changes and the error persists. I'm now making sure this isn't being caused by a change on Travis's side by rerunning the corresponding test from a recent commit that had previously passed. (And indeed it did pass again.) The only other (seemingly) relevant changes I made are the bump from-O2to-O3for some configurations and removal of-fomit-frame-pointer.@devinamatthews Any thoughts?
devinamatthews commentedon Feb 19, 2019
@fgvanzee it looks like an AMD "TBM" instruction whatever that is.
fgvanzee commentedon Feb 19, 2019
Thanks for sussing that out. gcc isolates the TBM instruction set via
-mtbm, and so I can probably fix this nonsense with-mno-tbm. (And maybe disable XOP and LWP while I'm at it.)Disable TBM, XOP, LWP instructions in AMD configs.
fgvanzee commentedon Feb 19, 2019
That fixed it. Extra thanks, Devin.
fgvanzee commentedon Feb 19, 2019
@loveshack I've reverted back to using
-funsafe-loop-optimizations. Feel free to review those changes while we do further testing in the lead up to merging back intomaster.jeffhammond commentedon Feb 19, 2019
If you are going to use Intel SDE to try to emulate AMD processors, I recommend setting compiler flags that limit the code generation to the union ISA (
Intel & AMD) and confirm any exceptions to this with the SDE documentation.The following seem like relevant references:
loveshack commentedon Feb 19, 2019
loveshack commentedon Feb 19, 2019
fgvanzee commentedon Feb 19, 2019
@jeffhammond I'm having trouble following your suggestion. Are you suggesting that we enable FMA4, XOP, TBM, and LWP, and then somehow ignore the invalid instruction errors that come out of the SDE?
@loveshack It's okay, these things happen. I'm just glad I didn't spend too much time on it. :) As for using
-funsafe-math-optimizations, I'm a bit more wary of these kinds of optimizations than those implied by-funsafe-loop-optimizations. Let me play with it a bit and see how the BLAS test drivers and BLIS testsuite respond to them.@loveshack I think our way of doing this is typically to let Travis CI chew on the new build (which uses the SDE as one of the tests) and see what happens. But I may be misunderstanding your comment.
loveshack commentedon Feb 20, 2019
fgvanzee commentedon Feb 20, 2019
I must have missed that. (Sorry.) But please humor me. I am somewhat conservative when it comes to numerical issues, mostly because I am wary of issues lurking in that region just beyond my expertise. :)
Ohhh, I see what you mean. You meant other architectures such as ARM or Power. Yeah, our methods of testing changes of any sort for those non-x86_64 architectures is more limited.
loveshack commentedon Feb 20, 2019
14 remaining items
devinamatthews commentedon Mar 17, 2019
Update: I compiled the following code with gcc 8.2, clang 7.0.0, and icc 19.0.1 on Godbolt,
My assumption here is that for complex numbers, the approximation
x/y = x*(1/y)is good enough, but1/y = conj(y)/norm(y)is not. This means that the compiler should do something special to computeialpha(i.e. gcc should use__divdc3), but the loop can be vectorized. Here are the results for different compilers and flags (all -O3 and targeting Haswell):-funsafe-math-optimizationsor-fp-model fast=1-ffinite-math-only-ffast-mathor-fp-model fast=2__divdc3and__muldc3in loop__divdc3optimized toconj(y)/norm(y)__divdc3(inlined), loop vectorizedSo, it seems that according to the assumptions above, the "right" flags are
-funsafe-math-optimizations -ffinite-math-onlyfor clang and the default flags for icc, but there don't seem to be a single set of flags for gcc that do what I want.Unless of course people are OK with
-fcx-limited-rangeand then-ffast-mathor-fp-model fast=2should be fine for BLIS.devinamatthews commentedon Mar 17, 2019
I should also mention that if you change the inner loop to:
then every compiler only vectorizes with the highest flags (i.e. they don't seem to separate the
x/y = x*(1/y)and1/y = conj(y)/norm(y)optimizations).fgvanzee commentedon Mar 18, 2019
@devinamatthews Thanks for reporting these details, Devin. It sounds like your preliminary conclusion is that gcc flags should not be modified yet, but that we could begin using
-funsafe-math-optimizations -ffinite-math-onlyfor clang?devinamatthews commentedon Mar 18, 2019
@fgvanzee do you have any comment of
-fcx-limited-range? @loveshack do you have any suggestions for gcc flags?fgvanzee commentedon Mar 18, 2019
I'm afraid I don't have anything super-intelligent to add at this time.
Forgive me if I'm reading your table incorrectly, but it sounds like while there is no one set of flags that does what you want in gcc,
-funsafe-math-optimizationsseems to be a step in the right direction. Is the only thing missing the vectorization of the loop?devinamatthews commentedon Mar 18, 2019
@fgvanzee Yes. Although, I suppose since BLIS uses level-0 macros we could implement complex multiplication in terms of real multiplication which would recover vectorizability with just
-funsafe-math-optimizations.fgvanzee commentedon Mar 18, 2019
Bingo. So perhaps the emerging consensus is:
-funsafe-math-optimizations-funsafe-math-optimizations -ffinite-math-onlyShould
-ffinite-math-onlybe used for gcc as well?devinamatthews commentedon Mar 18, 2019
The other thing that
-ffinite-math-onlyaffects is multiplying by zero. Most kernels special case this (e.g. beta=0), but for example if you fake real*complex as complex*complex with an imaginary zero component then this matters.fgvanzee commentedon Mar 18, 2019
Then it sounds like it's not that important in our case, for either gcc or clang. BLIS's level-0 scalar macros almost always manually optimize situations where you are multiplying by real x complex to avoid the zero imaginary component entirely.
Standardized optimization flags in make_defs.mk.
Disable TBM, XOP, LWP instructions in AMD configs.
Changed unsafe-loop to unsafe-math optimizations.
devinamatthews commentedon Aug 6, 2020
I think
-funsafe-math-optimizationsand-O3have percolated into all the configs.add support for conjugate transpose in avx512 zgemm sup kernel (flame…