Hi, I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems to take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason? Cheers, Hagen
Perhaps the ndarrays have different ordering (C vs Fortran order)? On Fri, Sep 10, 2010 at 10:36 AM, Hagen Fürstenau <hagen@zhuliguan.net>wrote:
Hi,
I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems to take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason?
Cheers, Hagen
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Fri, Sep 10, 2010 at 10:36 AM, Hagen Fürstenau <hagen@zhuliguan.net> wrote:
I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems to take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason?
I don't see a difference on my computer. Could you post an example?
I don't see a difference on my computer. Could you post an example?
I'm attaching a small benchmark script. It multiplies two example arrays loaded from the file "data" (which you can download from http://zhuliguan.net/data (157K)), and compares this with multiplying two random arrays. On two different machines I get an output like the following: $ python mm.py 0.0121581554413 0.000909090042114 So the example arrays take more than 10 times as long! Hope this helps in understanding what's going on... Cheers, Hagen
On Fri, Sep 10, 2010 at 11:36 AM, Hagen Fürstenau <hagen@zhuliguan.net>wrote:
Hi,
I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems to take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason?
Multiplication by zero used to be faster than multiplication by random numbers. However, modern hardware and compilers may have changed that to pretty much a wash. More likely you are seeing cache issues due to data localization or even variations in the time given the thread running the multiplication. Chuck
On Sat, Sep 11, 2010 at 2:57 AM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Fri, Sep 10, 2010 at 11:36 AM, Hagen Fürstenau <hagen@zhuliguan.net> wrote:
Hi,
I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems to take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason?
Multiplication by zero used to be faster than multiplication by random numbers. However, modern hardware and compilers may have changed that to pretty much a wash. More likely you are seeing cache issues due to data localization or even variations in the time given the thread running the multiplication.
That's actually most likely a denormal issue. The a and b matrix (from mm.py) have many very small numbers, which could cause numbers to be denormal. Maybe a has more denormals than b. Denormal cause significant performance issues on Intel hardware at least. Unfortunately, we don't have a way in numpy to check for denormal that I know of. cheers, David
On Fri, Sep 10, 2010 at 6:41 PM, David Cournapeau <cournape@gmail.com>wrote:
On Sat, Sep 11, 2010 at 2:57 AM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Fri, Sep 10, 2010 at 11:36 AM, Hagen Fürstenau <hagen@zhuliguan.net> wrote:
Hi,
I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems to take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason?
Multiplication by zero used to be faster than multiplication by random numbers. However, modern hardware and compilers may have changed that to pretty much a wash. More likely you are seeing cache issues due to data localization or even variations in the time given the thread running the multiplication.
That's actually most likely a denormal issue. The a and b matrix (from mm.py) have many very small numbers, which could cause numbers to be denormal. Maybe a has more denormals than b. Denormal cause significant performance issues on Intel hardware at least.
Unfortunately, we don't have a way in numpy to check for denormal that I know of.
The matrices could be scaled up to check that. Chuck
On Sat, Sep 11, 2010 at 9:47 AM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Fri, Sep 10, 2010 at 6:41 PM, David Cournapeau <cournape@gmail.com> wrote:
On Sat, Sep 11, 2010 at 2:57 AM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Fri, Sep 10, 2010 at 11:36 AM, Hagen Fürstenau <hagen@zhuliguan.net> wrote:
Hi,
I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems to take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason?
Multiplication by zero used to be faster than multiplication by random numbers. However, modern hardware and compilers may have changed that to pretty much a wash. More likely you are seeing cache issues due to data localization or even variations in the time given the thread running the multiplication.
That's actually most likely a denormal issue. The a and b matrix (from mm.py) have many very small numbers, which could cause numbers to be denormal. Maybe a has more denormals than b. Denormal cause significant performance issues on Intel hardware at least.
Unfortunately, we don't have a way in numpy to check for denormal that I know of.
The matrices could be scaled up to check that.
Indeed - and I misread the script anyway, I should not investigate this kind of things after waking up :) Anyway, seems it is indeed a denormal issue, as adding a small (1e-10) constant gives same speed for both timings. cheers, David
On Fri, Sep 10, 2010 at 7:04 PM, David Cournapeau <cournape@gmail.com>wrote:
On Sat, Sep 11, 2010 at 9:47 AM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Fri, Sep 10, 2010 at 6:41 PM, David Cournapeau <cournape@gmail.com> wrote:
On Sat, Sep 11, 2010 at 2:57 AM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Fri, Sep 10, 2010 at 11:36 AM, Hagen Fürstenau <
wrote:
Hi,
I'm multiplying two 1000x1000 arrays with numpy.dot() and seeing significant performance differences depending on the data. It seems
to
take much longer on matrices with many zeros than on random ones. I don't know much about optimized MM implementations, but is this normal behavior for some reason?
Multiplication by zero used to be faster than multiplication by random numbers. However, modern hardware and compilers may have changed that to pretty much a wash. More likely you are seeing cache issues due to data localization or even variations in the time given the thread running
hagen@zhuliguan.net> the
multiplication.
That's actually most likely a denormal issue. The a and b matrix (from mm.py) have many very small numbers, which could cause numbers to be denormal. Maybe a has more denormals than b. Denormal cause significant performance issues on Intel hardware at least.
Unfortunately, we don't have a way in numpy to check for denormal that I know of.
The matrices could be scaled up to check that.
Indeed - and I misread the script anyway, I should not investigate this kind of things after waking up :)
Anyway, seems it is indeed a denormal issue, as adding a small (1e-10) constant gives same speed for both timings.
Ah, that's probably one of the reasons the lapack lstsqr's routine scales the matrices to a nice range. I was wondering. Chuck
Denormal numbers are a tricky beast. You may have to change the clip or the shift depending on the processor you have. It's no wonder that processors and thus compilers have options to round denormals to zero. Matthieu 2010/9/11 Hagen Fürstenau <hagen@zhuliguan.net>:
Anyway, seems it is indeed a denormal issue, as adding a small (1e-10) constant gives same speed for both timings.
With adding 1e-10 or clipping to 0 at 1e-150, I still get a slowdown of about 30% compared with the random arrays. Any explanation for that?
Cheers, Hagen
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
-- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher
participants (6)
-
Charles R Harris -
David Cournapeau -
Hagen Fürstenau -
John Salvatier -
Keith Goodman -
Matthieu Brucher