patches for increased performance of matmul, dotprod, transpose

Tim Prince tprince@myrealbox.com
Tue Aug 30 13:20:00 GMT 2005


Tobias Schlüter wrote:

>Hi Tim,
>  
>
>If the manual loop unrolling is really helpful, I think an optimizer bug
>should be filed.  On IRC our optimizer guys told me that at least the
>modification to matmul should already be done automatically, so I'm wondering,
>  if you have any benchmark numbers supporting this modification?  Can't the
>same effect be obtained by building libgfortran with -funroll-loops?
>
>A procedural point: your patch doesn't conform to the GNU coding style
>(comments should begin with a capital letter and end in "punctuation + two
>spaces + */", always put blanks before and after operators, indent comments to
>code); also if you find you really need to hand-optimize code, please add a
>comment explaining why, adding "FIXME" and a PR number if you think you're
>working around an optimizer bug.
>
>WRT your mail:  paragraphs make reading and also responding to emails much
>easier.  ChangeLogs are also useful for referencing parts when discussing the
>patch.
>
>- Tobi
>  
>
These changes are complementary to -funroll-loops.  That optimization 
does not duplicate any of these source changes.  gcc might be considered 
deficient in that it does not automatically perform scalar reductions 
(to move store instructions out of a loop, where there is more than one 
sum) or strength reduction (to move integer multiplication out of a 
loop), where it is dictated in the matmul patch.  I did not change the 
existing usage of * (multiplication) without spaces surrounding the 
operator, but included the spaces in my additional copies of those 
expressions.

Performance of Livermore Fortran Kernels 3 and 21 on Pentium D x86-64 
exceeds ifort with these patches.  Performance of Kernel 4 is doubled 
from previous libgfortran, and Kernel 6 is speeded up significantly.  
This assumes those kernels are written using dotprod() and matmul().
I verified performance gain also on ia64 linux and Pentium-m cygwin.

changelog
gcc/fortran
          * transpose.m4:  Swap inner and outer loops, to make the 
destination stride 1, taking advantage of             Write Combine 
buffering architectures.
          * dotprod.m4:  Accumulate sum by pairs, to permit up to double 
the operations in the pipeline.
          Optimization primarily to speed up floating point (not complex).
          * matmul.m4:  Swap inner loops, moving store instructions out 
of inner loop.  Calculate results
          in pairs, combining operations with a common multiplier.  
Dictate scalar reduction of sums and
          strength reduction of index multiplication, where not 
optimized automatically by gcc.  Net 50%
          reduction in memory traffic.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: matmul.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050830/036f9e26/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: transpose.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050830/036f9e26/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dotprod.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050830/036f9e26/attachment-0002.ksh>


More information about the Fortran mailing list