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 was assuming that BLIS is generally better than reference BLAS, so substituting the latter with BLIS OS packages I'm working on would always be sensible. However, I found BLIS is more than two times slower for medium-sized dgemm on x86_64/RHEL7 for a "generic" build compared with the system reference blas package (which should be built with -O2 -mtune=generic, not -O3). I can't usefully test an architecture without a tuned implementation, but I don't see any reason to think that would be much different, though I haven't looked into the gcc optimization.
Is that expected, or might it be something worth investigating?
The generic implementation will have better cache behavior than netlib BLAS, but will also do packing which will slow things down for small and medium-sized matrices. It's not totally clear from your comment whether or not this is the configuration that BLIS is using, please correct me if I am mistaken.
The `generic` implementation will have better cache behavior than
netlib BLAS,
That's what I thought.
but will also do packing which will slow things down for
small and medium-sized matrices.
but not about that. At what sort of size would that stop hurting (and I
wonder if it could usefully be adaptive)? I tried 2000×2000 to run a
few goes in a reasonable time. I've just tried 4000 square, which looks
about the same.
It's not totally clear from your
comment whether or not this is the configuration that BLIS is using,
please correct me if I am mistaken.
I built a BLIS dynamic library with default flags and the generic
target. I took the openblas dgemm benchmark (which actually linked
against openblas), and ran it with either BLIS or reference BLAS
LD_PRELOADed. Is that clearer?
I could examine the compilation results and profiles at some stage when
I have more time, but thought it was worth asking the experts first --
thanks.
OK, I guess I'm not really clear why you care about the performance of the BLIS generic configuration. Even with cache blocking it will never be "high performance".
@cdluminate I took a look at some of the build times, as you suggest. It is true that the build time is excessive for your s390x build, for example (50 minutes, if I'm reading the output correctly). Much of that can be attributed to the fact that we do not have optimized kernels for every architecture. s390x is one of those unoptimized architectures. Still, this does feel a bit slow.
(Digression: If you would like to reduce the total build time, I recommend running the "fast" version of the BLIS testsuite, which is almost surely where most of the time is being spent. Right now, make test triggers the BLAS test drivers + the full BLIS testsuite. You can instead use make check, which runs the BLAS test drivers + a shortened version of the BLIS testsuite.)
However, strangely, your amd64 build still requires almost 19 minutes. That is still quite long. I just did a quick test on my 3.6GHz Broadwell. Targeting x86_64 at configure-time, I found that:
The library build itself takes only 55 seconds.
The full BLIS testsuite (build and run) takes about 3 minutes.
The BLAS test drivers (build and run) add another 10 seconds.
Note that no multithreading was used during the execution of any of the BLAS test drivers or BLIS testsuite, though all compilation was done with the -j4 argument to make.
Perhaps your build hardware for the amd64 build is old? Or maybe oversubscribed?
An unrelated question: I assume that the name of your amd64 build refers generically to "the build for x86_64 microarchitectures," as it does in the Gentoo Linux world, and not AMD-specific hardware. Am I correct?
Debian tries to help upstream spot problems, not to build software as fast as possible. In order to build a reliable linux distribution it's not a good idea to skip too much tests. Hence the full testsuite is preferred for packaging.
As for amd64 build, my Intel I5-7440HQ runs the full test quite fast too. It's possible that Ubuntu uses old x86-64 machine in their buildfarm, but I'm not sure "old hardware" is the cause of "20 min" build time.
Debian's term amd64 always equals to x86_64. No matter what brand the physical CPU is.
Debian tries to help upstream spot problems, not to build software as fast as possible. In order to build a reliable linux distribution it's not a good idea to skip too much tests. Hence the full testsuite is preferred for packaging.
That's fine. I often prefer the full testsuite in my own development, too, but I thought I would offer the faster alternative since many people in the past have been happy with avoiding many tests that are nearly identical to each other if it saves them 5-10x time.
As for amd64 build, my Intel I5-7440HQ runs the full test quite fast too. It's possible that Ubuntu uses old x86-64 machine in their buildfarm, but I'm not sure "old hardware" is the cause of "20 min" build time.
I'm glad you also see more normal build times. I see no need to worry, then, about the 20 minute build time on the Debian build hardware.
Debian's term amd64 always equals to x86_64. No matter what brand the physical CPU is.
I'm glad you also see more normal build times. I see no need to worry, then, about the 20 minute build time on the Debian build hardware.
Just nitpicking: The launchpad, or PPA is Ubuntu's infrastructure, supported by business company Canonical. Debian is supported by independent community that theoretically doesn't rely on Ubuntu or Canonical.
The pages you see are not powered by Debian's build hardware. What I'm doing there is abusing Ubuntu's free build machines to build stuff on Ubuntu cosmic for testing Debian packages. (Ubuntu cosmic, or Ubuntu 18.10 is very close to Debian unstable. So testing Debian packages on Ubuntu machine sometimes makes sense).
BTW, since I don't use Debian, I have to rely on people like you and @nschloe for your expertise on these topics (understanding how we fit into the Debian/Ubuntu universes). Thanks again.
Field:
Next time a vendor offers to donate hardware, you might ask for a big SSD
so you can setup a virtual machine for every Linux distro. Just a thought.
@jeffhammond In principle, I agree with you. However, this is the sort of thing that is not as practical now that our group is so small. (It also doesn't help that maintaining machines in our department comes with a non-trivial amount of cost and of red tape.) Instead, I'm going to channel you circa 2010 and say, "we look forward to your patch." And by that I mean, "someone doing it for us."
@loveshack Returning to the original question: I think one way to make the "generic" implementation faster would be to add a fully-unrolled branch and temporary storage of C to the kernel, e.g.:
...
if (m==MR&&n==NR)
{
// unroll all MR*NR FMAs into temporaries
}
else
{
// as usual
}
...
// accumulate at the end instead of along the way
and arrange for the reference kernel to be compiled with architecture-appropriate flags. The second issue means that e.g. a configuration without an optimized kernel would possibly run faster because of auto-vectorization, but that the actual generic configuration will probably still be very slow because it gets very conservative compiler flags.
Actually, that example needs to check the gcc version for support of the
specific architectures. I think such attributes are also supported by
appropriate versions of clang.
This is what I was talking about yesterday, rather long with the included
data...
I've not understood the reported issues with GCC vectorization, but
I'm not convinced by the current generic implementation with the simd
pragmas -- but thanks for re-working it. The pragmas actually hurt
performance, at least testing on an avx2 system.
I'm running Debian stable, with GCC6, on a "Intel(R) Core(TM) i5-6200U CPU @
2.30GHz" (with a full desktop, non-ideally). I'm testing serial square DGEMM
with the OpenBLAS benchmark, using LD_PRELOAD to switch libraries. Obviously
it's not really useful on x86, but I hope the target doesn't make a dramatic
difference to the vectorizer, and it's easiest to try locally before looking
at POWER8, which is the only architecture of interest I can use interactively
(though I can try to get on an aarch64 HPC system).
Using the Debian openblas package (0.2.19, i.e. rather old, pthreaded, so with
OPENBLAS_NUM_THREADS=1) as a reference I get this, with variance of a few
percent between runs:
Now without the SIMD pragma (which requires modifying configure, as
-fno-openmp-simd in CFLAGS gets overridden), but with -march=native
-ffast-math, I get an encouraging ~65% of the tuned version:
[prefetch-loop-arrays hurts performance in this case.]
I assumed the forced vectorization isn't all profitable, although
-Wopenmp-simd doesn't complain. However, thinking about it, perhaps the
pragma uses avx but not fma; I haven't tried to check.
For what it's worth, here's the difference in opt-info between using
openmp-simd and just Ofast, i.e. -O3 -ffast-math. (I don't understand the
unrolling note, as --help=optimizers say -funroll-loops is disabled.)
$ diff <(2>&1 gcc -fopt-info -O3 -march=native -fPIC -std=c99 -D_POSIX_C_SOURCE=200112L -Iinclude/generic -I./frame/3/ -I./frame/ind/ukernels/ -I./frame/1m/ -I./frame/1f/ -I./frame/1/ -I./frame/include -DBLIS_VERSION_STRING=\"0.5.1-36\" -fopenmp-simd -DBLIS_CNAME=generic -DBLIS_IS_BUILDING_LIBRARY -c ref_kernels/3/bli_gemm_ref.c -o obj/generic/ref_kernels/generic/3/bli_gemm_generic_ref.o) <(2>&1 gcc -fopt-info -Ofast -march=native -fPIC -std=c99 -D_POSIX_C_SOURCE=200112L -Iinclude/generic -I./frame/3/ -I./frame/ind/ukernels/ -I./frame/1m/ -I./frame/1f/ -I./frame/1/ -I./frame/include -DBLIS_VERSION_STRING=\"0.5.1-36\" -DBLIS_CNAME=generic -DBLIS_IS_BUILDING_LIBRARY -c ref_kernels/3/bli_gemm_ref.c -o obj/generic/ref_kernels/generic/3/bli_gemm_generic_ref.o -Wno-unknown-pragmas)
9,10c9,11
< ref_kernels/3/bli_gemm_ref.c:159:1: note: Loop 13 distributed: split to 0 loops and 1 library calls.
< ref_kernels/3/bli_gemm_ref.c:159:1: note: loop vectorized
---
> ref_kernels/3/bli_gemm_ref.c:159:1: note: loop turned into non-loop; it never loops.
> ref_kernels/3/bli_gemm_ref.c:159:1: note: loop with 17 iterations completely unrolled
> ref_kernels/3/bli_gemm_ref.c:159:1: note: Loop 1 distributed: split to 0 loops and 1 library calls.
15,16d15
< ref_kernels/3/bli_gemm_ref.c:159:1: note: loop with 2 iterations completely unrolled
< ref_kernels/3/bli_gemm_ref.c:159:1: note: loop turned into non-loop; it never loops.
18a18
> ref_kernels/3/bli_gemm_ref.c:159:1: note: basic block vectorized
27c27,31
< ref_kernels/3/bli_gemm_ref.c:160:1: note: Loop 13 distributed: split to 0 loops and 1 library calls.
---
> ref_kernels/3/bli_gemm_ref.c:160:1: note: loop turned into non-loop; it never loops.
> ref_kernels/3/bli_gemm_ref.c:160:1: note: loop with 9 iterations completely unrolled
> ref_kernels/3/bli_gemm_ref.c:160:1: note: loop turned into non-loop; it never loops.
> ref_kernels/3/bli_gemm_ref.c:160:1: note: loop with 5 iterations completely unrolled
> ref_kernels/3/bli_gemm_ref.c:160:1: note: Loop 1 distributed: split to 0 loops and 1 library calls.
40,43c44
< ref_kernels/3/bli_gemm_ref.c:160:1: note: loop turned into non-loop; it never loops.
< ref_kernels/3/bli_gemm_ref.c:160:1: note: loop with 2 iterations completely unrolled
< ref_kernels/3/bli_gemm_ref.c:160:1: note: loop turned into non-loop; it never loops.
< ref_kernels/3/bli_gemm_ref.c:160:1: note: loop with 4 iterations completely unrolled
---
> ref_kernels/3/bli_gemm_ref.c:160:1: note: basic block vectorized
53c54,55
< ref_kernels/3/bli_gemm_ref.c:161:1: note: loop vectorized
---
> ref_kernels/3/bli_gemm_ref.c:161:1: note: loop turned into non-loop; it never loops.
> ref_kernels/3/bli_gemm_ref.c:161:1: note: loop with 9 iterations completely unrolled
63,64d64
< ref_kernels/3/bli_gemm_ref.c:161:1: note: loop with 2 iterations completely unrolled
< ref_kernels/3/bli_gemm_ref.c:161:1: note: loop turned into non-loop; it never loops.
66,67d65
< ref_kernels/3/bli_gemm_ref.c:161:1: note: loop turned into non-loop; it never loops.
< ref_kernels/3/bli_gemm_ref.c:161:1: note: loop with 4 iterations completely unrolled
77c75,78
< ref_kernels/3/bli_gemm_ref.c:162:1: note: loop vectorized
---
> ref_kernels/3/bli_gemm_ref.c:162:1: note: loop turned into non-loop; it never loops.
> ref_kernels/3/bli_gemm_ref.c:162:1: note: loop with 5 iterations completely unrolled
> ref_kernels/3/bli_gemm_ref.c:162:1: note: loop turned into non-loop; it never loops.
> ref_kernels/3/bli_gemm_ref.c:162:1: note: loop with 5 iterations completely unrolled
91,92d91
< ref_kernels/3/bli_gemm_ref.c:162:1: note: loop with 2 iterations completely unrolled
< ref_kernels/3/bli_gemm_ref.c:162:1: note: loop turned into non-loop; it never loops.
94,95c93
< ref_kernels/3/bli_gemm_ref.c:162:1: note: loop turned into non-loop; it never loops.
< ref_kernels/3/bli_gemm_ref.c:162:1: note: loop with 4 iterations completely unrolled
---
> ref_kernels/3/bli_gemm_ref.c:162:1: note: basic block vectorized
I could see what MAQAO makes of the generated code in each case, but I
don't know whether it's worth the effort.
I also tried the native compiler (gcc 4.8) on EL7, which doesn't
support the simd pragma. Bizarrely, -march=native on haswell kills
performance (down to ~1500 from ~5000 without -march).
Using GCC target_clones isn't as straightforward as I hoped; I'm investigating.
Recent gcc is much better at automatic vectorization (yay)
#pragma omp simd does force vectorization, but maybe it does not play as nice with other optimizations
I wonder if the vectorization when using omp simd is tuned for BLAS L1-like kernels and gets confused by the much more computationally dense GEMM kernel? Can you send the assembly for the kernel with and without omp simd?
@loveshack Thanks for sharing these detailed results, and for going to the trouble.
Before commenting on your results, I would be curious to isolate the impact of -ffast-math, which, as of gcc 5.4.0, was shorthand for -fno-math-errno -funsafe-math-optimizations -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range. The man page description for the option warns that
This option is not turned on by any -O option besides -Ofast since
it can result in incorrect output for programs that depend on an
exact implementation of IEEE or ISO rules/specifications for math
functions. It may, however, yield faster code for programs that do
not require the guarantees of these specifications.
Generally speaking, I would consider such options to be off-limits for our purposes. Now, the increase from ~12 to ~22 GFLOPS may have been attributable to something else, e.g. the presence of the pragmas rather than the use of -ffast-math. But it would be good to isolate these so we can evaluate them independently.
It sounds like:
1) Recent gcc is much better at automatic vectorization (yay)
6 isn't terribly recent, but better than what? (Even when I used 5 from
Ubuntu 16.04 recently, it beat the hand-written intrinsics in the
how-to-optimize-blas tutorial when I added "restrict".) I wanted to
know exactly how vectorization failures were happening, especially as
they may be for versions where -fopenmp-simd isn't available anyhow.
[Unfortunately for EL7 package-building at least, the add-on recent
compilers with -fopenmp-simd aren't available for relevant architectures.]
2) `#pragma omp simd` does force vectorization, but maybe it does not
play as nice with other optimizations
It seems to be like I guessed -- the pragma uses avx, but not fma as far
as I can tell grepping for "vfm" instructions in each case.
I wonder if the vectorization when using omp simd is tuned for BLAS
L1-like kernels and gets confused by the much more computationally
dense GEMM kernel? Can you send the assembly for the kernel with and
without omp simd?
From which version of gcc and for which (x86_64) target? GCC 8 gives
different -- better, one hopes -- optimization reports from 6 in cases
I've tried, but isn't widely available.
Even when I used 5 from Ubuntu 16.04 recently, it beat the hand-written intrinsics in the how-to-optimize-blas tutorial when I added "restrict".
If this is what you are observing then we have had very different experiences... At this point, I am happy with the current reference kernels either with or without omp simd. I think the most important things are the vectorization flags, fma (using the C99 fma function or adding flags), and the way the kernel is written, which I think is close to optimal now.
Generally speaking, I would consider such options to be off-limits for
our purposes. Now, the increase from ~12 to ~22 GFLOPS may have been
attributable to something else, e.g. the presence of the pragmas
rather than the use of `-ffast-math`. But it would be good to isolate
these so we can evaluate them independently.
I can't remember if I checked in this case, but in general you need
-ffast-math for vectorization. (I think someone else also remarked on
that, and I pointed out up-thread that icc defaults to it, which is
probably a reason for its supposedly much better vectorization.) I'd
assume that the assembler kernels would have similar properties, but I
don't know. Anyhow make test passes with the generic kernels and
-Ofast. I think the factor of two is just down to fma, but I haven't
checked -mavx2 v. -march=haswell.
I can't remember if I checked in this case, but in general you need -ffast-math for vectorization. (I think someone else also remarked on that, and I pointed out up-thread that icc defaults to it, which is probably a reason for its supposedly much better vectorization.)
As for my general aversion to "fast math" style options, perhaps I am being too conservative. Hopefully others can comment on the potential numerical risk of using -ffast-math/-Ofast.
Also, in my experience, you don't need-ffast-math in order for the compiler to emit vectorized object code; even with older versions of gcc such as 5.4, I've seen AVX (though not FMA) vector code emitted via pragma omp simd. (Maybe you only meant that -ffast-math was needed for better vectorized code?)
If this is what you are observing then we have had very different
experiences...
I would like to understand why, given the range of GCC versions people
deal with. I guess I could post results to the tutorial tracker.
At this point, I am happy with the current reference
kernels either with or without `omp simd`. I think the most important
things are the vectorization flags, fma (using the C99 fma function or
adding flags), and the way the kernel is written, which I think is
close to optimal now.
Yes, this basically solves the issue; thanks. I should try to check it
on non-x86_64, though, where it's relevant. Is the remaining
performance lag relative to the tuned version likely to be down to block
size?
I think the remaining task is to get GCC target clones working, so we
can potentially optimize amongst micro-architectures, but I need to seek
advice on how to make that work in cases like this. (For what it's
worth, the problem is getting the resolver function generated and
retained in the library.) However, I suspect selecting clones is
subject to the same issues as family support for ARM, for instance.
As for my general aversion to "fast math" style options, perhaps I am
being too conservative. Hopefully others can comment on the potential
numerical risk of using `-ffast-math`/`-Ofast`.
I should perhaps have said something other than fast-math, but I'm not
sure which of the sub-options are relevant for vectorization. (Such
flags could be confined to specific kernel source with a GCC pragma.)
Also, in my experience, you don't *need* `-ffast-math` in order for
the compiler to emit vectorized object code; even with older versions
of gcc such as 5.4, I've seen AVX (though not FMA) vector code emitted
via `pragma omp simd`. (Maybe you only meant that `-ffast-math` was
needed for *better* vectorized code?)
In the case of NEON, the GCC manual says that
-funsafe-math-optimizations is required for auto-vectorization. The icc
doc lists the diagnostics for auto-vectorization, but it's tedious to
find the examples that fail with a (non-default) correct fpu-model (?)
option. I've seen reductions as the canonical example, and I thought
there were similar issues with parallelization, but I've looked
unsuccessfully for a good exposition. Probably GCC should document
better what the simd pragma does.
For bli_gemm_ref, I do see the same optimization report from -O3 and
-Ofast through "sort -u -n -k2 -t:" (to account for different message
repetitions in each case). I suppose I could do the experiment for the
rest of the code.
@fgvanzee@loveshack re -ffast-math for BLAS I think we are probably doing all of these unsafe optimizations by hand anyways ((a*b)*c=a*(b*c), FMA, complex multiplication, a/b=a*(1/b), etc.). For LAPACK I imagine there are some places where more care would be needed.
@loveshack re "the remaining performance lag relative to the tuned version", this is mostly going to be prefetch, but a little bit of unrolling, instruction reordering, etc. In my experience the one thing the compiler did not do well was vector register allocation: the AB product must be kept in registers for highest performance.
For info, here's additional vectorization that -Ofast gives with gcc-6 compared with -O3 (not implying that it's all important).
It was generated by configuring with -fopt-info-vec -march=haswell and either O3 or Ofast, grepping the output for "vectorized" through sort -u, and diffing the results.
It's just occurred to me, though, that it's actually under-counting the number of extra loops that may have been vectorized, since the line numbers reported are where macros are instantiated typically as multiple loops. At least the level 1 and 3 ref_kernels below don't get any vectorization without fast-math, c.f. optimized zen/haswell versions.
@loveshack to expand on the prefetching, this is what the hand-tuned kernel does:
prefetch C into L1 (with write hint if possible) ~200 cycles ahead of time, but not so far ahead that loads of A and/or B will flush it out, and spaced such that the prefetcher does not run out of slots. For haswell this is just a block of prefetches at the start, but for skylake and knl this it much more complicated. It is also important to prefetch the address of the last element in each row/column of C.
Prefetch A (for row-major kernels) or B (for column-major kernels) into L1 during the iterations about ~30 cycles ahead of time. The "next" panel of other operand (B or A respectively) can also be prefetched into L2--but usually only about 1/4 of the panel is "warmed-up" this way.
For skylake and knl, we can't keep anything resident in L1, so both A and B have to be prefetched into L1 during the iterations.
Activity
devinamatthews commentedon Sep 28, 2018
The
genericimplementation will have better cache behavior than netlib BLAS, but will also do packing which will slow things down for small and medium-sized matrices. It's not totally clear from your comment whether or not this is the configuration that BLIS is using, please correct me if I am mistaken.jeffhammond commentedon Sep 28, 2018
@devinamatthews It may also be that Fortran is better than C
loveshack commentedon Sep 28, 2018
loveshack commentedon Sep 28, 2018
devinamatthews commentedon Sep 28, 2018
OK, I guess I'm not really clear why you care about the performance of the BLIS
genericconfiguration. Even with cache blocking it will never be "high performance".cdluminate commentedon Sep 29, 2018
At least it is true that the builds on non-x86_64 architectures are slow due to the slow tests.
https://launchpad.net/~lumin0/+archive/ubuntu/ppa/+sourcepub/9451410/+listing-archive-extra
Click on the builds and there is time elapsed for the whole compiling+testing process.
fgvanzee commentedon Sep 29, 2018
@cdluminate I took a look at some of the build times, as you suggest. It is true that the build time is excessive for your
s390xbuild, for example (50 minutes, if I'm reading the output correctly). Much of that can be attributed to the fact that we do not have optimized kernels for every architecture. s390x is one of those unoptimized architectures. Still, this does feel a bit slow.(Digression: If you would like to reduce the total build time, I recommend running the "fast" version of the BLIS testsuite, which is almost surely where most of the time is being spent. Right now,
make testtriggers the BLAS test drivers + the full BLIS testsuite. You can instead usemake check, which runs the BLAS test drivers + a shortened version of the BLIS testsuite.)However, strangely, your
amd64build still requires almost 19 minutes. That is still quite long. I just did a quick test on my 3.6GHz Broadwell. Targetingx86_64at configure-time, I found that:Note that no multithreading was used during the execution of any of the BLAS test drivers or BLIS testsuite, though all compilation was done with the
-j4argument to make.Perhaps your build hardware for the
amd64build is old? Or maybe oversubscribed?An unrelated question: I assume that the name of your
amd64build refers generically to "the build for x86_64 microarchitectures," as it does in the Gentoo Linux world, and not AMD-specific hardware. Am I correct?cdluminate commentedon Sep 30, 2018
Debian tries to help upstream spot problems, not to build software as fast as possible. In order to build a reliable linux distribution it's not a good idea to skip too much tests. Hence the full testsuite is preferred for packaging.
As for
amd64build, my Intel I5-7440HQ runs the full test quite fast too. It's possible that Ubuntu uses old x86-64 machine in their buildfarm, but I'm not sure "old hardware" is the cause of "20 min" build time.Debian's term
amd64always equals tox86_64. No matter what brand the physical CPU is.fgvanzee commentedon Sep 30, 2018
That's fine. I often prefer the full testsuite in my own development, too, but I thought I would offer the faster alternative since many people in the past have been happy with avoiding many tests that are nearly identical to each other if it saves them 5-10x time.
I'm glad you also see more normal build times. I see no need to worry, then, about the 20 minute build time on the Debian build hardware.
Good, that's what I thought/expected. Thanks.
cdluminate commentedon Sep 30, 2018
Just nitpicking: The launchpad, or PPA is Ubuntu's infrastructure, supported by business company Canonical. Debian is supported by independent community that theoretically doesn't rely on Ubuntu or Canonical.
The pages you see are not powered by Debian's build hardware. What I'm doing there is abusing Ubuntu's free build machines to build stuff on Ubuntu cosmic for testing Debian packages. (Ubuntu cosmic, or Ubuntu 18.10 is very close to Debian unstable. So testing Debian packages on Ubuntu machine sometimes makes sense).
fgvanzee commentedon Sep 30, 2018
Unlike most people, I will almost never be bothered by nitpicking! I like and appreciate nuance. :) Thanks for those details.
fgvanzee commentedon Sep 30, 2018
BTW, since I don't use Debian, I have to rely on people like you and @nschloe for your expertise on these topics (understanding how we fit into the Debian/Ubuntu universes). Thanks again.
jeffhammond commentedon Sep 30, 2018
fgvanzee commentedon Sep 30, 2018
@jeffhammond In principle, I agree with you. However, this is the sort of thing that is not as practical now that our group is so small. (It also doesn't help that maintaining machines in our department comes with a non-trivial amount of cost and of red tape.) Instead, I'm going to channel you circa 2010 and say, "we look forward to your patch." And by that I mean, "someone doing it for us."
devinamatthews commentedon Oct 1, 2018
@loveshack Returning to the original question: I think one way to make the "generic" implementation faster would be to add a fully-unrolled branch and temporary storage of C to the kernel, e.g.:
and arrange for the reference kernel to be compiled with architecture-appropriate flags. The second issue means that e.g. a configuration without an optimized kernel would possibly run faster because of auto-vectorization, but that the actual
genericconfiguration will probably still be very slow because it gets very conservative compiler flags.90 remaining items
loveshack commentedon Jan 25, 2019
loveshack commentedon Feb 13, 2019
This is what I was talking about yesterday, rather long with the included
data...
I've not understood the reported issues with GCC vectorization, but
I'm not convinced by the current generic implementation with the simd
pragmas -- but thanks for re-working it. The pragmas actually hurt
performance, at least testing on an avx2 system.
I'm running Debian stable, with GCC6, on a "Intel(R) Core(TM) i5-6200U CPU @
2.30GHz" (with a full desktop, non-ideally). I'm testing serial square DGEMM
with the OpenBLAS benchmark, using LD_PRELOAD to switch libraries. Obviously
it's not really useful on x86, but I hope the target doesn't make a dramatic
difference to the vectorizer, and it's easiest to try locally before looking
at POWER8, which is the only architecture of interest I can use interactively
(though I can try to get on an aarch64 HPC system).
Using the Debian openblas package (0.2.19, i.e. rather old, pthreaded, so with
OPENBLAS_NUM_THREADS=1) as a reference I get this, with variance of a few
percent between runs:
With current BLIS master configured "auto", i.e. haswell in this case:
BLIS configured "generic" plus CFLAGS -march=native, in the absence of target
clones:
[Omitting -march=native, gives about 7900.]
Now without the SIMD pragma (which requires modifying configure, as
-fno-openmp-simd in CFLAGS gets overridden), but with -march=native
-ffast-math, I get an encouraging ~65% of the tuned version:
[prefetch-loop-arrays hurts performance in this case.]
I assumed the forced vectorization isn't all profitable, although
-Wopenmp-simd doesn't complain. However, thinking about it, perhaps the
pragma uses avx but not fma; I haven't tried to check.
For what it's worth, here's the difference in opt-info between using
openmp-simd and just Ofast, i.e. -O3 -ffast-math. (I don't understand the
unrolling note, as --help=optimizers say -funroll-loops is disabled.)
I could see what MAQAO makes of the generated code in each case, but I
don't know whether it's worth the effort.
I also tried the native compiler (gcc 4.8) on EL7, which doesn't
support the simd pragma. Bizarrely, -march=native on haswell kills
performance (down to ~1500 from ~5000 without -march).
Using GCC target_clones isn't as straightforward as I hoped; I'm investigating.
devinamatthews commentedon Feb 13, 2019
It sounds like:
#pragma omp simddoes force vectorization, but maybe it does not play as nice with other optimizationsI wonder if the vectorization when using omp simd is tuned for BLAS L1-like kernels and gets confused by the much more computationally dense GEMM kernel? Can you send the assembly for the kernel with and without omp simd?
fgvanzee commentedon Feb 13, 2019
@loveshack Thanks for sharing these detailed results, and for going to the trouble.
Before commenting on your results, I would be curious to isolate the impact of
-ffast-math, which, as of gcc 5.4.0, was shorthand for-fno-math-errno -funsafe-math-optimizations -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range. The man page description for the option warns thatGenerally speaking, I would consider such options to be off-limits for our purposes. Now, the increase from ~12 to ~22 GFLOPS may have been attributable to something else, e.g. the presence of the pragmas rather than the use of
-ffast-math. But it would be good to isolate these so we can evaluate them independently.loveshack commentedon Feb 13, 2019
devinamatthews commentedon Feb 13, 2019
If this is what you are observing then we have had very different experiences... At this point, I am happy with the current reference kernels either with or without
omp simd. I think the most important things are the vectorization flags, fma (using the C99 fma function or adding flags), and the way the kernel is written, which I think is close to optimal now.loveshack commentedon Feb 13, 2019
fgvanzee commentedon Feb 13, 2019
As for my general aversion to "fast math" style options, perhaps I am being too conservative. Hopefully others can comment on the potential numerical risk of using
-ffast-math/-Ofast.Also, in my experience, you don't need
-ffast-mathin order for the compiler to emit vectorized object code; even with older versions of gcc such as 5.4, I've seen AVX (though not FMA) vector code emitted viapragma omp simd. (Maybe you only meant that-ffast-mathwas needed for better vectorized code?)loveshack commentedon Feb 14, 2019
loveshack commentedon Feb 14, 2019
devinamatthews commentedon Feb 14, 2019
@fgvanzee @loveshack re
-ffast-mathfor BLAS I think we are probably doing all of these unsafe optimizations by hand anyways ((a*b)*c=a*(b*c), FMA, complex multiplication,a/b=a*(1/b), etc.). For LAPACK I imagine there are some places where more care would be needed.@loveshack re "the remaining performance lag relative to the tuned version", this is mostly going to be prefetch, but a little bit of unrolling, instruction reordering, etc. In my experience the one thing the compiler did not do well was vector register allocation: the AB product must be kept in registers for highest performance.
loveshack commentedon Feb 14, 2019
For info, here's additional vectorization that -Ofast gives with gcc-6 compared with -O3 (not implying that it's all important).
It was generated by configuring with -fopt-info-vec -march=haswell and either O3 or Ofast, grepping the output for "vectorized" through sort -u, and diffing the results.
It's just occurred to me, though, that it's actually under-counting the number of extra loops that may have been vectorized, since the line numbers reported are where macros are instantiated typically as multiple loops. At least the level 1 and 3 ref_kernels below don't get any vectorization without fast-math, c.f. optimized zen/haswell versions.
devinamatthews commentedon Feb 14, 2019
@loveshack to expand on the prefetching, this is what the hand-tuned kernel does:
prefetch C into L1 (with write hint if possible) ~200 cycles ahead of time, but not so far ahead that loads of A and/or B will flush it out, and spaced such that the prefetcher does not run out of slots. For haswell this is just a block of prefetches at the start, but for skylake and knl this it much more complicated. It is also important to prefetch the address of the last element in each row/column of C.
Prefetch A (for row-major kernels) or B (for column-major kernels) into L1 during the iterations about ~30 cycles ahead of time. The "next" panel of other operand (B or A respectively) can also be prefetched into L2--but usually only about 1/4 of the panel is "warmed-up" this way.
For skylake and knl, we can't keep anything resident in L1, so both A and B have to be prefetched into L1 during the iterations.
PoC implementation of reference gemm kernel.