Boris Lau | 29 May 14:45 2011
Picon

Problem with g++-4.4 -O2 and Eigen3

Hi folks,

after updating Eigen to the newest version in the repository, I now 
compile my code with Eigen including the "no inlining of the GEBP 
product kernel" change by Gael.

However, still a simple matrix multiplication goes awfully wrong when 
using -O2 in g++-4.4:

// a code snipped
Eigen::Matrix<double,3,9> J;
J.fill(1.0);
Eigen::Matrix<double,3,9> Jprime = Eigen::Matrix3d::Identity() * J;
std::cout << "J\n" << J << std::endl;
std::cout << "Jprime\n" << Jprime << std::endl;

// output
J
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
Jprime
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1

As for Hauke, this only occurs only when used deeper inside a project, 
in the main function it works alright. The problem also occurs for a 
matrix size of 3x8, and disappears for 3x7 and smaller. Using dynamic 
sizes does not help.
(Continue reading)

Gael Guennebaud | 29 May 17:08 2011
Picon

Re: Problem with g++-4.4 -O2 and Eigen3

ok, so just like before, the default value of the multiplicative
factor alpha gets transformed into a -1.... that's really crasy.

Does that change anything if explicitly put a multiplicative factor, e.g.:

C.noalias() = 1 * A * B;

Regarding the matrix size, this is because for matrices smaller than 8
we use another product implementation.

gael

On Sun, May 29, 2011 at 2:45 PM, Boris Lau
<lau@...> wrote:
> Hi folks,
>
> after updating Eigen to the newest version in the repository, I now compile
> my code with Eigen including the "no inlining of the GEBP product kernel"
> change by Gael.
>
> However, still a simple matrix multiplication goes awfully wrong when using
> -O2 in g++-4.4:
>
> // a code snipped
> Eigen::Matrix<double,3,9> J;
> J.fill(1.0);
> Eigen::Matrix<double,3,9> Jprime = Eigen::Matrix3d::Identity() * J;
> std::cout << "J\n" << J << std::endl;
> std::cout << "Jprime\n" << Jprime << std::endl;
>
(Continue reading)

Boris Lau | 1 Jun 16:29 2011
Picon

Re: Problem with g++-4.4 -O2 and Eigen3

Hi,
sorry, but no, adding the 1 and/or the noalias doesn't change anything.

Here are some more interesting matrix multiplication results. In short, 
3x3 * 3x9 gives a mess, while 3x9 * 9x3 and 9x3 * 3x9 does not.

Best, Boris

Eigen::Matrix<double,3,9> J;
J.fill(1.0);

std::cout << J << std::endl;
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1

std::cout << Eigen::Matrix3d::Identity()*J << std::endl;
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
wrong!

std::cout << J.transpose()*J << std::endl;
3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3
(Continue reading)

Gael Guennebaud | 1 Jun 16:42 2011
Picon

Re: Problem with g++-4.4 -O2 and Eigen3

I'm afraid there is nothing we can do on our side. It's clearly a
compiler bug. For the record, and for the others, on your initial
example I found that a double value was wrongly modified to -1 in
between function calls, something like:

foo(1);

void foo(double alpha)
{
   // here alpha still equal 1)
   bar(alpha);
}

void bar(double alpha)
{
   // here alpha == -1
}

and even worse, this behavior was dependent on the order of the .o
files in the linking command line, i.e., the bug only appeared for
some orders.

Valgrind did not reported any issue.

All other version of gcc was fine.

So I'd recommend you to upgrade your compiler. At least you could try
with the latest version of 4.4, i.e., 4.4.6 if that's not already the
one you are using.

(Continue reading)

Boris Lau | 1 Jun 17:46 2011
Picon

Re: Problem with g++-4.4 -O2 and Eigen3

Thanks, that made it very clear. I've switched to 4.5 now, and it works 
perfectly. Thanks a lot :)

Best, Boris

On 06/01/2011 04:42 PM, Gael Guennebaud wrote:
> I'm afraid there is nothing we can do on our side. It's clearly a
> compiler bug. For the record, and for the others, on your initial
> example I found that a double value was wrongly modified to -1 in
> between function calls, something like:
>
> foo(1);
>
> void foo(double alpha)
> {
>     // here alpha still equal 1)
>     bar(alpha);
> }
>
> void bar(double alpha)
> {
>     // here alpha == -1
> }
>
> and even worse, this behavior was dependent on the order of the .o
> files in the linking command line, i.e., the bug only appeared for
> some orders.
>
> Valgrind did not reported any issue.
>
(Continue reading)

Bastien ROUCARIES | 17 Jul 11:46 2011
Picon

Re: Problem with g++-4.4 -O2 and Eigen3

Do you have a test case for reporting bug ?

On Wed, Jun 1, 2011 at 4:42 PM, Gael Guennebaud
<gael.guennebaud@...> wrote:
> I'm afraid there is nothing we can do on our side. It's clearly a
> compiler bug. For the record, and for the others, on your initial
> example I found that a double value was wrongly modified to -1 in
> between function calls, something like:
>
> foo(1);
>
> void foo(double alpha)
> {
>   // here alpha still equal 1)
>   bar(alpha);
> }
>
> void bar(double alpha)
> {
>   // here alpha == -1
> }
>
> and even worse, this behavior was dependent on the order of the .o
> files in the linking command line, i.e., the bug only appeared for
> some orders.
>
> Valgrind did not reported any issue.
>
> All other version of gcc was fine.
>
(Continue reading)

Gael Guennebaud | 17 Jul 21:44 2011
Picon

Re: Problem with g++-4.4 -O2 and Eigen3

see this threads for more details about this bug:

http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2011/04/msg00013.html

gael

On Sun, Jul 17, 2011 at 11:46 AM, Bastien ROUCARIES
<roucaries.bastien@...> wrote:
> Do you have a test case for reporting bug ?
>
> On Wed, Jun 1, 2011 at 4:42 PM, Gael Guennebaud
> <gael.guennebaud@...> wrote:
>> I'm afraid there is nothing we can do on our side. It's clearly a
>> compiler bug. For the record, and for the others, on your initial
>> example I found that a double value was wrongly modified to -1 in
>> between function calls, something like:
>>
>> foo(1);
>>
>> void foo(double alpha)
>> {
>>   // here alpha still equal 1)
>>   bar(alpha);
>> }
>>
>> void bar(double alpha)
>> {
>>   // here alpha == -1
>> }
>>
(Continue reading)

Bastien ROUCARIES | 17 Jul 21:52 2011
Picon

Re: Problem with g++-4.4 -O2 and Eigen3

On Sun, Jul 17, 2011 at 9:44 PM, Gael Guennebaud
<gael.guennebaud@...> wrote:
> see this threads for more details about this bug:
>
> http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2011/04/msg00013.html

Too large for gcc bugzilla unfortunatly.

I will try to add a bug

Bastien

> gael
>
> On Sun, Jul 17, 2011 at 11:46 AM, Bastien ROUCARIES
> <roucaries.bastien@...> wrote:
>> Do you have a test case for reporting bug ?
>>
>> On Wed, Jun 1, 2011 at 4:42 PM, Gael Guennebaud
>> <gael.guennebaud@...> wrote:
>>> I'm afraid there is nothing we can do on our side. It's clearly a
>>> compiler bug. For the record, and for the others, on your initial
>>> example I found that a double value was wrongly modified to -1 in
>>> between function calls, something like:
>>>
>>> foo(1);
>>>
>>> void foo(double alpha)
>>> {
>>>   // here alpha still equal 1)
(Continue reading)


Gmane