Compile with march=native by default

Issue #435 resolved
Chris Beall created an issue

As discussed here, we can probably enable -march=native by default, and give the user the option to disable.

  • We still need to check whether this works on Windows (check for test failures!)
  • Need to document that this requires dependent projects to build with same flag.

Comments (7)

  1. matthew.broadway

    I have a question about the recently added performance section of the README (sorry if this is the wrong place to ask this). You said that

    Also note that all dependent projects *must* be compiled with the same flag, or seg-faults and other undefined behavior may result.
    

    by dependent projects are you referring to the dependencies of GTSAM such as boost, tbb etc, or are you referring to the user's projects which use GTSAM? I think it would be worth clarifying in the README. And what sort of problems occur? are they noticeable failures like invalid opcode or do things go wrong in a subtle way?

  2. Chris Beall reporter

    Good question. With dependent projects I mean projects which you build against gtsam. The more detailed explanation: Any project which calls gtsam functions which have Eigen types as parameters must be compiled with '-march=native`. Unfortunately, this requirement is transitive, so if you have two projects A and B, which form a dependency chain A --> B --> gtsam, and they all use Eigen, then you must use the same flags in all three projects.

    The reason for this has to do with alignment. Compiling with -march=native enables FMA, AVX, AVX2 instructions, and these change alignment of Eigen types. Incompatible mixing of flags then results in undefined behavior, numerical errors, or - if you're lucky - crashes. Eigen has some tickets on this: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1349

  3. José Luis Blanco-Claraco

    A quick note: If -march=native is appended to the PUBLIC interface of gtsam, it will be automatically propagated to "dependent"/user's projects... that's why that cmake mechanism is great! Users shouldn't be even aware of this important detail.

  4. Log in to comment