Re: [eigen] Problem with g++-4.4 -O2 and Eigen3 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Problem with g++-4.4 -O2 and Eigen3
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Thu, 7 Apr 2011 18:52:27 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=vsRPRx7H9xPL/kAo7HJWiOH0XO5HAqzdhnuVT36LX7g=; b=T75en5pfhSOy8fxhicm7pEr2KTDmsSx6vAdYAkhkBlVI5Gn+XCZHf1jZ8QPpzucovi BrFGUV1qDrFdHbSn0IC+nvXbcbrymIzr0AD4VI84QrCmHEkz7Hujdl+6/E7qZ1H5OJIA rt9TlrfKMG8b5qLj8XyqH3af0UAr9fwlKP5B0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=RCGLe2KElDZ9Nn1HcYgHOOmo7qEkI9MAci+OBd2I8Niq0kFHxHd4T4Dpav0od3f7JE MTZb1eK2F6HadT7z8G/cnzrcWbbaC2T1pCm3ARs4oEo5a1numWE0NbjhAg4/MsQuOWMh AcvdIKoCPCjVGwku1W8Zc7TpSUbjXPlxsQmGs=
another workaround is to disable inlining of the GEBP kernel, that I
did in changeset 49e00a2e570c:
enforce no inlining of the GEBP product kernel: this is a big
function that makes no sense to inline, though GCC was thinking
the opposite. This even slighlty improve the perf. And as a side
effect this workaround a weird GCC-4.4 linking bug (see
"Problem with g++-4.4 -O2 and Eigen3" in the ML)
Of course this is only hiding the issue.
gael
On Thu, Apr 7, 2011 at 6:04 PM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
> the fix is very obvious, change the last line of your CMakeLists.txt to:
>
> ADD_EXECUTABLE(test foo.cpp main.cpp foo.h)
>
> (reverse foo.cpp and main.cpp). The effect is to change the order of
> the .o files at linking stage, and here that does the trick.
>
> btw, I was kidding, this makes no sense to me :) But at least we know
> that something very strange happens during the linking.
>
> gael
>
>
> On Thu, Apr 7, 2011 at 5:30 PM, hauke strasdat <strasdat@xxxxxxxxx> wrote:
>> Hi all,
>>
>> I think I found a bug related to g++-4.4 and Eigen3.
>>
>> If I multiply two matrices A=[1 1;0 0] and B=[1 0; 1 0] to each other,
>> the sign of the result is flipped: [-2 0; 0 0] instead of [2 0; 0 0].
>> A.row(0).dot(B.col(0)) always provides the correct result 2.
>>
>> What triggers the bug:
>> - Apply lu().inverse() on a random matrix,
>> - and A*B is calculated in a member function of a separate class.
>> - and the program is complied using g++-4.4 with optimisation O2 or O3.
>>
>> The bug does not happen if I compile the program with O0/O1 or with
>> g++-4.3/g++-4.5.
>>
>> g++-4.4 is the standard compiler for Ubuntu 10.04 (v 4.4.3) and 10.10
>> (v 4.4.5) and I could reproduce the bug on both operating systems
>> (both 64 bit).
>> I tried the Eigen3 release version as well as a very recent version
>> from the hg repository.
>>
>> This could be a regression in g++-4.4, but I thought it is a good idea
>> to contact you guys first.
>> It would be awesome, if somebody would know a work-around, since it
>> would be very difficult for me
>> to switch to g++-4.3 or g++-4.5.
>>
>> A small test case is attached below.
>>
>> Cheers,
>> Hauke S.
>>
>>
>>
>> --- FILE foo.cpp:
>>
>> #include "foo.h"
>> #include <iostream>
>>
>> using namespace std;
>>
>> double Foo::method()
>> {
>> Matrix<double, 2,2> A;
>> A << 1,1,
>> 0,0;
>> MatrixXd B(2,2);
>> B <<1,0,
>> 1,0;
>> MatrixXd C = (A*B);
>> cerr << "A*B = " << C << endl;
>> cerr << "a*b = " << A.row(0).dot(B.col(0)) << endl;
>>
>> return 0;
>> }
>>
>> -- FILE foo.h:
>>
>> #ifndef FOO_H
>> #define FOO_H
>>
>> #include <Eigen/Core>
>> #include <Eigen/LU>
>> using namespace Eigen;
>>
>> class Foo
>> {
>> public:
>> double method();
>> };
>>
>> #endif
>>
>> -- FILE main.cpp:
>>
>> #include "foo.h"
>>
>> int main()
>> {
>> MatrixXd X(1,1);
>> X << 2;
>> X.lu().inverse();
>>
>> Foo foo;
>> foo.method();
>> }
>>
>> --- FILE CMakeLists.txt:
>>
>> SET (PROJECT_NAME TEST)
>>
>> PROJECT(${PROJECT_NAME})
>> CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
>> SET (CMAKE_VERBOSE_MAKEFILE ON)
>>
>> SET(CMAKE_CXX_COMPILER /usr/bin/g++-4.4)
>>
>> SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -Werror -Wall")
>> SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Werror -Wall")
>>
>> # override by appending -DCMAKE_BUILD_TYPE=Debug to cmake argument list
>> IF( NOT CMAKE_BUILD_TYPE )
>> SET( CMAKE_BUILD_TYPE Release )
>> ENDIF()
>>
>> SET (INCLUDE_DIRS "eigen3/" )
>> INCLUDE_DIRECTORIES( ${INCLUDE_DIRS})
>>
>> ADD_EXECUTABLE(test main.cpp foo.cpp foo.h)
>>
>>
>>
>