如何获得 AVX512_FP16 标志支持?

y.s*_*hyk 0 c++ intel avx512

我的 CPU 支持各种功能

  -march=CPU[,+EXTENSION...]
                          generate code for CPU and EXTENSION, CPU is one of:
                           generic32, generic64, i386, i486, i586, i686,
                           pentium, pentiumpro, pentiumii, pentiumiii, pentium4,
                           prescott, nocona, core, core2, corei7, l1om, k1om,
                           iamcu, k6, k6_2, athlon, opteron, k8, amdfam10,
                           bdver1, bdver2, bdver3, bdver4, znver1, btver1,
                           btver2
                          EXTENSION is combination of:
                           8087, 287, 387, 687, mmx, sse, sse2, sse3, ssse3,
                           sse4.1, sse4.2, sse4, avx, avx2, avx512f, avx512cd,
                           avx512er, avx512pf, avx512dq, avx512bw, avx512vl,
                           vmx, vmfunc, smx, xsave, xsaveopt, xsavec, xsaves,
                           aes, pclmul, fsgsbase, rdrnd, f16c, bmi2, fma, fma4,
                           xop, lwp, movbe, cx16, ept, lzcnt, hle, rtm, invpcid,
                           clflush, nop, syscall, rdtscp, 3dnow, 3dnowa,
                           padlock, svme, sse4a, abm, bmi, tbm, adx, rdseed,
                           prfchw, smap, mpx, sha, clflushopt, prefetchwt1, se1,
                           clwb, avx512ifma, avx512vbmi, avx512_4fmaps,
                           avx512_4vnniw, avx512_vpopcntdq, clzero, mwaitx,
                           ospke, rdpid, ptwrite, cet, no87, no287, no387,
                           no687, nommx, nosse, nosse2, nosse3, nossse3,
                           nosse4.1, nosse4.2, nosse4, noavx, noavx2, noavx512f,
                           noavx512cd, noavx512er, noavx512pf, noavx512dq,
                           noavx512bw, noavx512vl, noavx512ifma, noavx512vbmi,
                           noavx512_4fmaps, noavx512_4vnniw, noavx512_vpopcntdq
Run Code Online (Sandbox Code Playgroud)

然而,像简单的事情__m256h inter;会产生一个error: '__m256h' was not declared in this scope. 这是有道理的,因此 CPU 要求CPUID Flags: AVX512_FP16 + AVX512VL不在AVX512_FP16列表中。

一个人如何获得AVX512_FP16支持?是否与 CPU 版本相关,或者可以通过补丁修复吗?

更新: 英特尔提到 AVX512_FP16 仅与 AVX512BW 一起受支持 [检查]。我正在使用-march=skylake-avx512它进行编译,它可以正常编译__m512,但在这些基于 FP16 的操作上特别失败。

小智 6

主要答案

\n

由于 AVX512FP16 是AVX512 ISA 的扩展,因此它必须:

\n

A) 内置明确的硬件支持。

\n

B) 通过将类型提升为另一种合适的替代方案(例如具有特定舍入/一致性代码的 fp32),在软件中进行模拟。

\n

截至您发帖时,市场上还没有支持 AVX 512 FP16 的系统。

\n

截至本文发布(2022 年 2 月 10 日),市场上唯一支持的是适用于英特尔第 12 代 K 系列 AlderLake CPU* 的 AVX512 P(性能)核心解决方法。

\n

这些 P 核基于 Golden Cove 架构,支持 AVX512FP16*。

\n

要在 C 或 C++ 中使用指令,必须使用最新的编译器。我自己的测试表明 GCC-12、Clang-14 和 ICX 2022.0 都能够利用该指令。

\n

如果您想使用官方支持的平台,可以选择等待 Intel Xeon Sapphire Rapids,它仅基于 Golden Cove 核心,并且将启用完整的 AVX512 ISA。

\n

最后是一段代码,该代码将进行编译以利用 AVX512FP16 ISA 扩展中的 FMA 指令,并附有有关其用法的说明。

\n

使用Alder Lake的注意事项

\n

*注意:只有在具有特定 BIOS/微码修订版本的特定供应商主板上禁用 Gracemont E-core 后,才能启用此功能。这不受英特尔认可或支持

\n

其原因主要是与 Gracemont 和 Golden Cove 核心之间的不同 ISA 以及进程固定有关(但这超出了本问题的范围)

\n

代码示例

\n

如果您的平台支持该指令,请使用gcc-12 fp16_FMA_avx512.c -O3 -march=sapphirerapids -mavx512fp16 -o avx512example.bin \n生成可执行文件

\n

使用gcc-12 fp16_FMA_avx512.c -O3 -march=sapphirerapids -mavx512fp16 -o avx512example.S -S\n生成一个显示指令本身用法的汇编文件。

\n
    #include <stdio.h>\n    #include <stdlib.h>\n    #include <time.h>\n    /*\n    Simple example of FP16 arithmetic with it's declaration\n \n    NB: This uses Clang/GCC convention FP16 declarations due to near universal platform support.\n    Any compiler that has yet to formally adopt ISO/IEC TS 18661-3:2015 (\xe2\x80\x9cFloating-point extensions for C\xe2\x80\x9d) will not support the type.    \n    Known working x86_64 compilers as of Feb 08 2022 are:\n    Clang/LLVM-14+\n    GCC-12+\n    Intel ICX Version 2022.0.0\n     \n    Known working architectures:\n        Intel Alder-Lake [        *under certain conditions]\n        Intel Sapphire Rapids\n*/\n\nint main(){\n\nfloat seed = 1;\nsrand((time(0)));\nint count = 31;\n_Float16 factor = seed;\n\n//primaries\n_Float16 a=1.436;\n_Float16 b=0.83546;\n\n//arrays to be used for FMA\n_Float16 alpha[32];\n_Float16 delta[32];\n_Float16 omega[32];\n\nwhile (count>=0)\n{\n//fill the arrays with differing values\nalpha[count]=(_Float16) (a*factor);\ndelta[count]=(_Float16) (b*factor);\nomega[count]=(_Float16) (factor+(a*b));\n\nfactor = factor+b;\ncount--;\n}\n\nprintf("Print the FMA of 3  _Float16's that are cast as Float\\n");\n\nwhile (count < 32){\n\nomega[count]=(omega[count]*alpha[count])+delta[count];\n\ncount++;\n}\nprintf("\\n"); //clear last line\n\nwhile (count>=0)\n{\nprintf("%i %f \\n", count, (float) omega[count]);\ncount--;\n}\n\n\n\n// 32 entry variable can be used: 512bit/16bits per variable = 32 variables\n//c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah\n}\n
Run Code Online (Sandbox Code Playgroud)\n