关于使用 AVX512 编译的困惑

Confusion about compiling with AVX512

我正在阅读 this 有关如何使用英特尔 C++ 编译器和 AVX512 支持在英特尔 Knights Landing 上编译 C/C++ 代码的文档。

但是,我对这部分有点困惑:

-xMIC-AVX512: use this option to generate AVX-512F, AVX-512CD, AVX-512ER and AVX-512FP.

-xCORE-AVX512: use this option to generate AVX-512F, AVX-512CD, AVX-512BW, AVX-512DQ and AVX-512VL.

For example, to generate Intel AVX-512 instructions for the Intel Xeon Phi processor x200, you should use the option –xMIC-AVX512. For example, on a Linux system

$ icc –xMIC-AVX512 application.c This compiler option is useful when you want to build a huge binary for the Intel Xeon Phi processor x200. Instead of building it on the coprocessor where it will take more time, build it on an Intel Xeon processor-based machine

我的 Xeon Phi KNL 没有协处理器(无需 ssh micX 或使用 -mmic 标志进行编译)。但是,我不明白使用 -xMIC 还是 -xCORE 更好?

第二名大约 -ax 而不是 -x:

This compiler option is useful when you try to build a binary that can run on multiple platforms.

所以-ax用于跨平台支持,但是与-x相比有什么性能差异吗?

对于第一个问题,如果您要为 Intel Xeon Phi 处理器 x200(又名 KNL 处理器)编译,请使用 –xMIC-AVX512。请注意,您提到的论文中的短语打错了,应该是 "This compiler option is useful when you want to build a huge binary for the Intel Xeon Phi processor x200. Instead of building it on the Intel Xeon Phi processor x200 where it will take more time, build it on an Intel Xeon processor-based machine."

对于第二个问题,如果您 运行 Intel Xeon Phi 处理器 x200 上的二进制文件应该不会有性能差异。但是,使用-ax选项编译的二进制文件的大小应该大于使用-x选项编译的二进制文件的大小。

您提供的 link 中的另一个选项是使用 -xCOMMON-AVX512 构建。这是一个诱人的选项,因为在我的例子中,它包含我需要的所有说明,而且我可以对 KNL 和 Sklake-AVX512 系统使用相同的选项。因为我不是在 KNL 系统上构建,所以我不能使用 -xHost(或 -march=native 与 GCC)。

但是,-xCOMMON-AVX512 不应 与 KNL 一起使用。原因是它生成 vzeroupper 指令 (https://godbolt.org/z/PgFX55),这不仅没有必要,而且在 KNL 系统上实际上非常慢。

来自 Agner Fog 的 micro-architecture manual 他在 KNL 部分写道。

The VZEROALL or VZEROUPPER instructions are not only superfluous here, they are actually harmful for the performance. A VZEROALL or VZEROUPPER instruction takes 36 clock cycles in 64 bit mode...

因此,对于 KNL 系统,您应该使用 -xMIC-AVX512,对于其他带有 AVX512 的系统,您应该使用 -xCORE-AVX512(或 -xSKYLAKE-AVX512)。我也用-qopt-zmm-usage=high

我不知道 ICC 有一个开关可以在启用 vzeroupper 后禁用它(对于 GCC,您可以使用 -mno-vzeroupper)。

顺便说一下,根据相同的逻辑,您应该将 -march=knl 与 GCC 一起使用,而不是 -mavx512f(如果您确定不需要 AVX512ER 或 AVX512PF,-mavx512f -mno-vzeroupper 可能会起作用)。