[fortran-dev, patch] PR29962 - add simplifier for dot_product, matmul, transpose (F2003)
Tobias Schlüter
tobias.schlueter@physik.uni-muenchen.de
Tue Mar 24 19:58:00 GMT 2009
Dominique Dhumieres wrote:
> Daniel,
>
>> Unfortunately, this requires copying of all elements (which is still better
>> than the alternative of duplicating tons of code).
> ...
>> + /* Copying of expressions is required as operands are free'd
>> + by the gfc_arith routines. */
>
> This would not be important if users were wise enough to restrict the use
> of initialization to small values. Past records show that it is not always the
> case. It is notorious that dot and matrix products are memory bandwith limited
> and adding extra moves will make things worse (as the matrix product is written
> there will be n**3 elements copied, BTW on modern processors it is about 4 times
> faster to write the matmul base on vectors muladd rather than on dot products).
On a similar note, I have been thinking for a long time that an
infrastructure where initialization expressions need not be evaluated as
a whole during compilation would be a better idea than expanding large
array constructors (NB we still have limits on those, even though its
controlled by a command line flag).
So if you have
REAL, PARAMETER :: X(N,M) = [ ... ], Y(M,L) = [ ... ]
REAL, PARAMETER :: Z(N,L) = MATMUL(X,Y)
...
PRINT *, Z(1,1)
you would only evaluate Z(1,1) at compile time (if at all), never
expanding the MATMUL as a whole (it should be relatively easy to defer
that to the runtime, just allocate space for Z and initialize it by
building the function call). Currently this is not possible because our
way of checking for initialization expressions is to simplify them, and
then seeing if a constant expressions turns up.
Just a thought, I haven't even tried to fathom how large an overhaul
this would be.
Cheers,
- Tobi
More information about the Fortran
mailing list