[英]Using gcc, is -march=native forwards compatible?
We have a cluster consisting of machines that have the following CPU's:我们有一个由具有以下 CPU 的机器组成的集群:
These support different instruction set extensions (eg the E5-2680 v3 has AVX2 and the others do not).它们支持不同的指令集扩展(例如,E5-2680 v3 具有 AVX2,而其他的则没有)。 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? -march=native
向前兼容,以便在最旧的机器上用它编译的代码将在以后的模型上运行,还是应该手动找出最小的公分母?
The gcc version is 4.8.2. gcc 版本是 4.8.2。
Is
-march=native
forwards compatible such that code compiled with it on the oldest machine will run on the later models-march=native
向前兼容,以便在最旧的机器上用它编译的代码将在以后的模型上运行
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.使用 GCC 的命名-march
选项之一会更安全,因为新系列往往是旧系列的超集,但-march=native
通常使用这种方式并不安全。
For these specific chips, I think it should be OK to use -march=native
but why risk it?对于这些特定的芯片,我认为使用-march=native
应该可以,但为什么要冒险呢? Either enable individual instructions sets with options like -msse4.2 -mavx
or use a named option.使用-msse4.2 -mavx
等选项启用单个指令集或使用命名选项。
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
).使用现代 GCC,您可以只使用与前两个匹配的-march=sandybridge
,并且不使用第三个不支持的任何指令(我认为与-march=haswell
匹配)。 For GCC 4.8.2 -march=corei7-avx
should work for all of them.对于 GCC 4.8.2 -march=corei7-avx
应该适用于所有这些。
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. https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html显示每个-march
选项启用的指令,或 GCC 4.8.2 https://gcc.gnu.org/onlinedocs/gcc- 4.8.2/gcc/i386-and-x86-64-Options.html列出了它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.