[patch,libgfortran] PR51119 - MATMUL slow for large matrices
Jerry DeLisle
jvdelisle@charter.net
Mon Nov 14 00:09:00 GMT 2016
Hi all,
Attached patch implements a fast blocked matrix multiply. The basic algorithm is
derived from netlib.org tuned blas dgemm. See matmul.m4 for reference.
The matmul() function is compiled with -Ofast -funroll-loops. This can be
customized further if there is an undesired optimization being used. This is
accomplished using #pragma optimize ( string ).
My results on 3.8 GHz machine with single core:
$ gfc -Ofast -funroll-loops -finline-matmul-limit=32 compare.f90
$ ./a.out
=========================================================
================ MEASURED GIGAFLOPS =
=========================================================
Matmul Matmul
fixed Matmul variable
Size Loops explicit refMatmul assumed explicit
=========================================================
2 2000 23.810 0.058 0.116 0.191
4 2000 1.979 0.294 0.437 0.421
8 2000 3.089 0.826 0.928 0.993
16 2000 4.115 3.262 2.600 3.381
32 2000 6.066 5.201 3.008 4.873
64 2000 6.596 4.847 6.624 6.603
128 2000 8.389 5.965 8.370 8.375
256 477 9.520 6.003 9.449 9.452
512 59 8.563 2.783 8.359 8.500
1024 7 8.672 1.537 8.457 8.604
2048 1 8.586 1.753 8.371 8.511
Results may vary, but I found 32 is the right place to set the limit on inlining.
Regression tested on x86-64-linux power8 (gcc112)
Special thanks to Thomas for helping me test and debug. An additional test case
as well.
OK for trunk?
Best regards,
Jerry
2016-11-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
Thomas Koenig <tkoenig@gcc.gnu.org>
PR libgfortran/51119
* m4/matmul.m4: For the case of all strides = 1, implement a
fast blocked matrix multiply. Fix some whitespace.
* generated/matmul_c10.c: Regenerate.
* generated/matmul_c16.c: Regenerate.
* generated/matmul_c4.c: Regenerate.
* generated/matmul_c8.c: Regenerate.
* generated/matmul_i1.c: Regenerate.
* generated/matmul_i16.c: Regenerate.
* generated/matmul_i2.c: Regenerate.
* generated/matmul_i4.c: Regenerate.
* generated/matmul_i8.c: Regenerate.
* generated/matmul_r10.c: Regenerate.
* generated/matmul_r16.c: Regenerate.
* generated/matmul_r4.c: Regenerate.
* generated/matmul_r8.c: Regenerate.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr51119.diff
Type: text/x-patch
Size: 220149 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20161114/33129268/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: matmul_12.f90
Type: text/x-fortran
Size: 625 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20161114/33129268/attachment-0001.bin>
More information about the Fortran
mailing list