[Bug fortran/26025] Optionally use BLAS for matmul
Janne Blomqvist
Janne.Blomqvist@tkk.fi
Wed Sep 27 07:54:00 GMT 2006
On Mon, Sep 25, 2006 at 08:58:08AM +0000, fxcoudert at gcc dot gnu dot org wrote:
>
>
> ------- Comment #3 from fxcoudert at gcc dot gnu dot org 2006-09-25 08:58 -------
> Patch proposed here: http://gcc.gnu.org/ml/fortran/2006-09/msg00325.html
>
> Janne, as I know you were interested in that feature, could you look at my
> patch if you have some time?
Sorry, I'm pretty busy with real life at the moment, and I haven't
been able to devote as much time to gfortran as I would have liked to.
I briefly looked at the patch, and as such I didn't see any obvious
fundamental deficiency in the implementation. I'll try to find some
time to test it on the weekend.
However, one thing that I think is absolutely critical if we want to
see this feature used, is to allow the user to link to the BLAS
library at compile time. Noone will recompile libgfortran just to link
in some specific BLAS library, especially as gcc 4.x is starting to
become the system compiler for most modern Linux distributions. If I
read your patch correctly, there is indeed no such requirement to
recompile libgfortran, so congratulations!
Also, doing the test whether to use blas or not in the library is, I
guess, necessary in practice. When I thought about implementing this
myself, I mostly concentrated on calling blas directly from the
frontend, and that gets pretty complicated as you can make a sure
decision only when everything is known statically, or then use some
heuristics which might or then might not be any good. So I think I
prefer our approach, although I guess there is a small performance
penalty due to extra runtime tests and an extra function pointer call.
Well, enough general rambling for now. All in all, I think your patch
is pretty clever. Some questions based on my quick skimming:
1) I think you have a bug in libgfortran/m4/matmul.m4; The line
&& (xcount > POW3(blas_limit) || xcount > POW3(blas_limit)
i.e. you're doing the same test twice. I guess the second xcount is
supposed to be ycount.
1b) Actually, I don't really understand the above test at all. Why are
you taking the third power of blas_limit? And what's with the float
conversions? As I see it, what you want is the number of elements in
the destination matrix, i.e. xcount * ycount, and check whether that
number is larger than blas_limit. Or blas_limit**2, as usually people
seem to mean matrix side length when they say "matrix size". I.e. the
entire test whether to use BLAS could be something like
+ if (try_blas && rxstride == 1 && (axstride == 1 || aystride == 1)
+ && (bxstride == 1 || bystride == 1)
+ && (xcount * ycount > blas_limit * blas_limit))
Or what am I missing?
2) Instead of passing a pointer to the appropriate blas routine to the
library, perhaps it would be simpler/cleaner/marginally faster/ to
call them directly in the library, but use weak symbols so that it
works also without a blas library?
--
Janne Blomqvist
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20060927/2af2f470/attachment.sig>
More information about the Fortran
mailing list