基于AMD,在英特尔上运行?
如果i 货物构建 - 释放
在AMD CPU上的生锈二进制文件,然后在英特尔(反之亦然)上运行它,这可能是一个问题(兼容性问题和/或大量的绩效牺牲)吗?我知道我们可以使用target-cpu =< cpu>
flag,并且应该 可能会导致目标的更优化的机器代码平台。我的问题是:
实际上,如果我们为一个平台构建但在另一个平台上构建,我们应该期望A 重要的运行时性能罚款吗?
如果我们使用
target-cpu = intel
(或VICE反之亦然),则可以: compilation 本身可以:- 较慢?
- 限制了它可以如何优化目标平台?
注意:Linux将是编译和运行的OS。
If I cargo build --release
a Rust binary on an AMD CPU and then run it on an Intel (or vice versa), could that be a problem (compatibility issues and/or considerable performance sacrifice)? I know we can use a target-cpu=<cpu>
flag and that should result in a potentially more optimized machine code for the target platform. My questions are:
Practically speaking, if we build for one platform but run on the other, should we expect a significant runtime performance penalty?
If we build on AMD with
target-cpu=intel
(or vice versa), could the compilation itself be:- slower?
- restricted in how well it could optimize for the target platform?
Note: Linux will be the OS for both compilation and running.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,如果您只做一个
货物构建-Release
而无需进一步的配置,那么您将获得一个在相关体系结构的任何计算机上运行的二进制文件。也就是说,它将在X86-64的Intel或AMD CPU上运行。它也将针对该体系结构的一般CPU进行优化,而不管您构建哪种类型的CPU。特定的设置将取决于配置的任何rustc和llvm,但是除非您完成了自定义构建,否则通常是这种情况。通常,对于大多数人的需求和目标CPU的构建就足够了。但是,如果您指定了特定的CPU,则将对该CPU进行优化,并可能包含在其他CPU上不运行的说明。例如,x86-64的架构定义不包含诸如AVX之类的内容,这是以后的补充,因此,如果您为CPU编译提供这些说明所有其他地方。
如果不更多地了解您的代码和性能需求,就不可能更多地谈论您的特定情况。我的建议只是对ues
货物构建 - 重新释放
,而不是针对特定的CPU进行优化,除非您测量了代码并确定有一个特定的部分很慢并且可以从中受益。大多数人从代码的额外便携性中受益匪浅,并且不需要特定于CPU的优化。我在这里说的一切也是其他架构集的。如果您为AARCH64 INKNOWN-LINUX-GNU或RISCV64GC-INKNOWN-LINUX-GNU编译,它将为该类型的通用CPU构建,除非您指定不同的选项,否则该类型适用于该类型的所有系统。例外倾向于在MacOS之类的系统上,特别知道在该操作系统上运行的所有CPU都具有一系列特定的功能,因此MacOS上的EG X86-64 CPU的汇编可能会针对Intel CPU优化具有给定功能的Intel CPU由于MacOS仅在使用这些CPU的硬件上运行。
In general, if you just do a
cargo build --release
without further configuration, then you will get a binary that runs on any machine of the relevant architecture. That is, it will run on either an Intel or AMD CPU that's x86-64. It will also be optimized for a general CPU of that architecture, regardless of what type of CPU you build it on. The specific settings are going to depend on whatever rustc and LLVM are configured for, but unless you've done a custom build, that's usually the case.Usually that is sufficient for most people's needs and building for a target CPU is unnecessary. However, if you specify a particular CPU, then it will be optimized for that CPU and may contain instructions that don't run on other CPUs. For example, the architectural definition for x86-64 doesn't contain things like AVX, which is a later addition, so if you compile for a CPU providing those instructions then rustc may use them, which may cause it to perform worse or not at all elsewhere.
It's impossible to say more about your particular situation without knowing more about your code and performance needs. My recommendation is just to ues
cargo build --release
and not to optimize for a specific CPU unless you have measured the code and determined that there is a particular section which is slow and which would benefit from that. Most people benefit greatly from the additional portability of the code and don't need CPU-specific optimizations.Everything I've said here is also true of other sets of architectures. If you compile for aarch64-unknown-linux-gnu or riscv64gc-unknown-linux-gnu, it will build for a generic CPU of that type which works on all systems of that type unless you specify different options. The exception tends to be on systems like macOS, where it is specifically known that all CPUs that run on that OS have some specific set of features, and thus a compilation for e.g. x86-64 CPUs on macOS might optimize for Intel CPUs with given features since macOS only runs on hardware that uses those CPUs.