Re: [eigen] Eigen is slow with complex matrices |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Eigen is slow with complex matrices
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Mon, 19 Oct 2009 09:41:47 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=lBsTndErFhb04R0jgiyWfmMlxbxb1+B5u9YCbGu96Bc=; b=wkx7gSFrppiD6/X+CoK93fi4gI4839pX8AVcyVGRvsS9wt2XifvzkICrGMENQypKQJ 8Yn3GeCzZn6xD5D1KvBkwgDZEZc1nxbbg3L+Z1rEkdoBK94ExxffOGOOgI/29BmmlYFP O2FSsSyBvfhnodc98+5dYnS2FzU7DLSFz9krk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=G9pnW2OoGMzPgw5JPEa9qEbFxzEBhJU1Wk2UpqWCwz5ZBQOiTaPrAzqIjivUXfCaKR mt5gYDxYY6lcnOzpVUnwatI6r6N3AVBhW6yKlSIzLN3iCH2FMiMOzXbGusKXuXLLOHhX /QUdXcriyTVayUkKYyl9W/vuuPfM7GCA6r2No=
Hi,
2009/10/19 Robert Lupton the Good <rhl@xxxxxxxxxxxxxxxxxxx>:
> We're using eigen on a large astronomical project; it's great -- no need to
> find the proper combination du jour of optimised blas and lapack.
>
> Unfortunately, in the context of complex matrices we are having to
> reconsider the use of BLAS. The reason appears to be in the complex class
> itself (see below) Is there any way that Eigen can work around this?
There are several ways in which Eigen is currently not optimally fast
with complex numbers, some are Eigen's fault, some are the GNU STL's
fault as you mention. Perhaps in the particular case of your project,
it reduces to one precise reason;
>> A better implementation would be to have op* directly calculate both
>> components of the result, and return it as a new complex object:
>> {
>> return complex<_Tp>(
>> _x.real() * _y.real() - _x.imag() * _y.imag(),
>> _x.real() * _y.imag() + _x.imag() * _y.real());
>> }
Have you tried it? Does it fix your performance issues? If yes, you
have a pretty clear path from here: just copy this standard complex
implementation as a new class, say "ourcomplex" and make that change
there; Then add support for "ourcomplex" as explained here,
http://eigen.tuxfamily.org/dox/CustomizingEigen.html#CustomScalarType
Otherwise, here are some thoughts on the performance issues with complex.
A. Not our fault
0) What you mention --- I didn't know about it.
1) The basic operations are not vectorized by GCC as they should. For
example, an addition of two complex<double> should be trivial to
vectorize.
2) Because of that, we haven't added vectorization in Eigen (though
for complex<float> we should be able to do something)
3) So we've been considering adding our own complex class, see the
TODO. Needs someone with time to do it.
B. Our fault
4) Eigen should be modified to avoid taking abs() of complex numbers
too often, because that means a sqrt(). The idea would be to introduce
ei_abs_or_abs2 that does abs for real and abs-squared for complex, so
that no sqrt() is needed.
To check if 4) is affecting you, edit Core/MathFunctions.h and put
EIGEN_DONT_INLINE in front of the ei_abs() specializations for
complex. Then profile your program, is ei_abs() accounting for a large
part of the execution time?
Cheers,
Benoit