简体   繁体   中英

Using gcc, is -march=native forwards compatible?

We have a cluster consisting of machines that have the following CPU's:

  • Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz,
  • Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz,
  • Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz.

These support different instruction set extensions (eg the E5-2680 v3 has AVX2 and the others do not). Is -march=native forwards compatible such that code compiled with it on the oldest machine will run on the later models, or should one manually figure out the lowest common denominator?

The gcc version is 4.8.2.

Is -march=native forwards compatible such that code compiled with it on the oldest machine will run on the later models

In general, no. There is no guarantee that an arbitrary newer chip will have all the instructions present on some arbitrary older chip. Using one of GCC's named -march option would be safer, because newer families tend to be supersets of older ones, but -march=native isn't generally safe to use that way.

For these specific chips, I think it should be OK to use -march=native but why risk it? Either enable individual instructions sets with options like -msse4.2 -mavx or use a named option.

With a modern GCC you could just use -march=sandybridge which matches the first two, and doesn't use any instructions not supported by the third one (which I think matches -march=haswell ). For GCC 4.8.2 -march=corei7-avx should work for all of them.

https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html shows which instructions are enabled by each -march option, or for GCC 4.8.2 https://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/i386-and-x86-64-Options.html lists them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM