Skip to contentSkip to conversation

config/x86: improve AVX512 availability check

PATCH Applied Dmitry Kozlyuk 3 participants 8 messages Nov 12, 2021 – Nov 17, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover config/x86: improve AVX512 availability check

The goal of this series is to enable cross-compilation
of Windows binaries from Linux using MinGW with Meson 0.49 used in CI. It also aims to reduce difference between Unix and Windows build code.

AVX512 was switched off for MinGW cross builds,
but unfortunately in a way that is not usable with meson 0.49. Also, c_args was used instead of machine_args for -mno-avx512f. After patch 3/3, AVX512 support for MinGW cross builds is configured exactly the same way as for Unix builds. This required rewriting a Unix-specific script in patch 2/3. Patch 1/3 skips check of GNU binutils when LLVM suite is used:
it is useful in general [1], and also simplifies patch 2/3.

[1]: https://inbox.dpdk.org/dev/20211112160837.131994aa@sovereign

Dmitry Kozlyuk (3):
config/x86: skip GNU binutils bug check for LLVM
buildtools: make AVX512 check script portable config/x86: fix MinGW cross build with meson 0.49

 buildtools/binutils-avx512-check.py | 21 +++++++++++++++++++++
 buildtools/binutils-avx512-check.sh | 16 ----------------
 buildtools/meson.build              |  4 +++-
 config/x86/cross-mingw              |  4 +---
 config/x86/meson.build              |  7 ++++---
 lib/acl/meson.build                 |  2 +-
 lib/fib/meson.build                 |  2 +-
 7 files changed, 31 insertions(+), 25 deletions(-)
 create mode 100644 buildtools/binutils-avx512-check.py
 delete mode 100755 buildtools/binutils-avx512-check.sh
Signature · 1 line
2.29.3
#1 lore raw

PATCH 1/3 config/x86: skip GNU binutils bug check for LLVM

AVX512 was disabled when GNU binutils were missing or had a known bug, even if LLVM binutils were used for the build,
because binutils-avx512-check.sh was invoked regardless and failed. In particular, this was the case for FreeBSD with clang (default). Run the check only when GNU binutils are used.

Fixes 68b1f1cda5b4 ("build: check AVX512 rather than binutils version")
---
 config/x86/meson.build | 7 ++++---
 lib/acl/meson.build    | 2 +-
 lib/fib/meson.build    | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)
config/x86/meson.build +4 -3
index 29f3dea181..603359e55a 100644
@@ -2,9 +2,10 @@
 # Copyright(c) 2017-2020 Intel Corporation
 
 # get binutils version for the workaround of Bug 97
-if not is_windows
-    binutils_ok = run_command(binutils_avx512_check)
-    if binutils_ok.returncode() != 0 and cc.has_argument('-mno-avx512f')
+binutils_ok = true
+if not is_windows and (is_linux or cc.get_id() == 'gcc')
+    binutils_ok = run_command(binutils_avx512_check).returncode() == 0
+    if not binutils_ok and cc.has_argument('-mno-avx512f')
         machine_args += '-mno-avx512f'
         warning('Binutils error with AVX512 assembly, disabling AVX512 support')
     endif
lib/acl/meson.build +1 -1
index f3dc513846..fbe17f9454 100644
@@ -36,7 +36,7 @@ if dpdk_conf.has('RTE_ARCH_X86')
     # compile AVX512 version if:
     # we are building 64-bit binary AND binutils can generate proper code
 
-    if dpdk_conf.has('RTE_ARCH_X86_64') and binutils_ok.returncode() == 0
+    if dpdk_conf.has('RTE_ARCH_X86_64') and binutils_ok
 
         # compile AVX512 version if either:
         # a. we have AVX512 supported in minimum instruction set
lib/fib/meson.build +1 -1
index 593c8c47c8..9b848d0841 100644
@@ -14,7 +14,7 @@ deps += ['rib']
 
 # compile AVX512 version if:
 # we are building 64-bit binary AND binutils can generate proper code
-if dpdk_conf.has('RTE_ARCH_X86_64') and binutils_ok.returncode() == 0
+if dpdk_conf.has('RTE_ARCH_X86_64') and binutils_ok
     # compile AVX512 version if either:
     # a. we have AVX512F supported in minimum instruction set baseline
     # b. it's not minimum instruction set, but supported by compiler
Signature · 1 line
2.29.3
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] config/x86: skip GNU binutils bug check for LLVM

Quoted 11 lines · Dmitry Kozlyuk

AVX512 was disabled when GNU binutils were missing or had a known bug, even if LLVM binutils were used for the build,
because binutils-avx512-check.sh was invoked regardless and failed. In particular, this was the case for FreeBSD with clang (default). Run the check only when GNU binutils are used.

Fixes 68b1f1cda5b4 ("build: check AVX512 rather than binutils version")
#3 lore raw

PATCH 2/3 buildtools: make AVX512 check script portable

In reply to Dmitry Kozlyuk

buildtools/binutils-avx512-check.sh was Unix-only and could not be used in cross builds:
1) written in shell;
2) used the assembler binary that may be missing, e.g. when building on Windows with LLVM;
3) located the assembler as ${AS:-as} and referenced objdump, but those binaries may be overridden via --cross-file.

Rewrite the script in Python.
Use the C compiler for the check.
Locate objdump and the C compiler using Meson.

---
 buildtools/binutils-avx512-check.py | 21 +++++++++++++++++++++
 buildtools/binutils-avx512-check.sh | 16 ----------------
 buildtools/meson.build              |  4 +++-
 3 files changed, 24 insertions(+), 17 deletions(-)
 create mode 100644 buildtools/binutils-avx512-check.py
 delete mode 100755 buildtools/binutils-avx512-check.sh
buildtools/binutils-avx512-check.py new file +21 -0
new file mode 100644
index 0000000000..a4e14f3593
@@ -0,0 +1,21 @@
+#! /usr/bin/env python3
+# SPDX-License-Identitifer: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import subprocess
+import sys
+import tempfile
+
+objdump, *cc = sys.argv[1:]
+with tempfile.NamedTemporaryFile() as obj:
+    # On Windows, the file is opened exclusively and is not writable.
+    obj.close()
+    # from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
+    gather_params = '0x8(,%ymm1,1),%ymm0{%k2}'
+    src = '__asm__("vpgatherqq {}");'.format(gather_params).encode('utf-8')
+    subprocess.run(cc + ['-c', '-xc', '-o', obj.name, '-'], input=src, check=True)
+    asm = subprocess.run([objdump, '-d', '--no-show-raw-insn', obj.name],
+                         capture_output=True, check=True).stdout.decode('utf-8')
+    if gather_params not in asm:
+	    print('vpgatherqq displacement error with as')
+	    sys.exit(1)
buildtools/binutils-avx512-check.sh deleted +0 -16
deleted file mode 100755
index 2a833b64b7..0000000000
@@ -1,16 +0,0 @@
-#! /bin/sh
-# SPDX-License-Identifier: BSD-3-Clause
-# Copyright(c) 2020 Intel Corporation
-
-AS=${AS:-as}
-OBJFILE=$(mktemp -t dpdk.binutils-check.XXXXXX)
-trap 'rm -f "$OBJFILE"' EXIT
-# from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
-GATHER_PARAMS='0x8(,%ymm1,1),%ymm0{%k2}'
-
-# assemble vpgather to file and similarly check
-echo "vpgatherqq $GATHER_PARAMS" | $AS --64 -o $OBJFILE -
-objdump -d  --no-show-raw-insn $OBJFILE | grep -q $GATHER_PARAMS || {
-	echo "vpgatherqq displacement error with as"
-	exit 1
-}
buildtools/meson.build +3 -1
index f776316da1..22ea0ba375 100644
@@ -4,7 +4,7 @@
 pkgconf = find_program('pkg-config', 'pkgconf', required: false)
 check_symbols = find_program('check-symbols.sh')
 ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
-binutils_avx512_check = find_program('binutils-avx512-check.sh')
+objdump = find_program('objdump', 'llvm-objdump')
 
 python3 = import('python').find_installation(required: false)
 if python3.found()
@@ -18,6 +18,8 @@ map_to_win_cmd = py3 + files('map_to_win.py')
 sphinx_wrapper = py3 + files('call-sphinx-build.py')
 get_cpu_count_cmd = py3 + files('get-cpu-count.py')
 get_numa_count_cmd = py3 + files('get-numa-count.py')
+binutils_avx512_check = (py3 + files('binutils-avx512-check.py') +
+                        [objdump] + cc.cmd_array())
 
 # select library and object file format
 pmdinfo = py3 + files('gen-pmdinfo-cfile.py') + [meson.current_build_dir()]
Signature · 1 line
2.29.3
Acked-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] buildtools: make AVX512 check script portable

Quoted 27 lines · Dmitry Kozlyuk

buildtools/binutils-avx512-check.sh was Unix-only and could not be used in cross builds:
1) written in shell;
2) used the assembler binary that may be missing, e.g. when building on Windows with LLVM;
3) located the assembler as ${AS:-as} and referenced objdump, but those binaries may be overridden via --cross-file.

Rewrite the script in Python.
Use the C compiler for the check.
Locate objdump and the C compiler using Meson.

---
 buildtools/binutils-avx512-check.py | 21 +++++++++++++++++++++
 buildtools/binutils-avx512-check.sh | 16 ----------------
 buildtools/meson.build              |  4 +++-
 3 files changed, 24 insertions(+), 17 deletions(-)
 create mode 100644 buildtools/binutils-avx512-check.py
 delete mode 100755 buildtools/binutils-avx512-check.sh
buildtools/binutils-avx512-check.py new file +0 -0
new file mode 100644
index 0000000000..a4e14f3593

buildtools/binutils-avx512-check.py line 4

Quoted 4 lines
buildtools/binutils-avx512-check.py new file +4 -0
@@ -0,0 +1,21 @@
+#! /usr/bin/env python3
+# SPDX-License-Identitifer: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+

This probably should have your own copyright instead of or alongside the Intel one, since this is a rewrite.

Otherwise:

#5 lore raw

PATCH 3/3 config/x86: fix MinGW cross build with meson 0.49

In reply to Dmitry Kozlyuk

Cross build with MinGW was broken for the baseline meson 0.49.2.
Cause: in c_args = '-mno-avx512f' from config/x86/cross-mingw, each character was treated as a separate compiler option:

meson.build:4:0: ERROR: Compiler x86_64-w64-mingw32-gcc can not compile programs.

With c_args = ['-mno-avx512f'] configuration passed, but build failed, because Meson placed -mno-avx512f after -mavx512f in CFLAGS:

    In file included from /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/include/immintrin.h:55,
                     from /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/include/x86intrin.h:32,
                     from ../dpdk/lib/net/net_crc_avx512.c:13:
    /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/include/avx512fintrin.h:1650:1:
            error: inlining failed in call to always_inline _mm512_ternarylogic_epi64:
            target specific option mismatch
     1650 | _mm512_ternarylogic_epi64 (__m512i __A, __m512i __B, __m512i __C,
          | ^~~~~~~~~~~~~~~~~~~~~~~~~
    ../dpdk/lib/net/net_crc_avx512.c:59:9: note: called from here
       59 |  return _mm512_ternarylogic_epi64(tmp0, tmp1, data_block, 0x96);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Additionally, -m[no-]avx512f flag is expected to be in machine_args by all the checks in meson.build files.

Commit 419c6e9af69e ("net/i40e: fix build for Windows MinGW") fixed the errors cause by MinGW using AVX512F on Windows. The binutils AVX512F bug check is now portable,
so enable it for Windows to switch AVX512 support on and off without any special logic for MinGW.

Fixes 549bfc83168f ("config: disable AVX512 with MinGW")
---
 config/x86/cross-mingw | 4 +---
 config/x86/meson.build | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)
config/x86/cross-mingw +1 -3
index 48a82b457e..09f7af0928 100644
@@ -5,12 +5,10 @@ ld = 'x86_64-w64-mingw32-ld'
 ar = 'x86_64-w64-mingw32-ar'
 strip = 'x86_64-w64-mingw32-strip'
 pkgconfig = 'x86_64-w64-mingw32-pkg-config'
+objdump = 'x86_64-w64-mingw32-objdump'
 
 [host_machine]
 system = 'windows'
 cpu_family = 'x86_64'
 cpu = 'native'
 endian = 'little'
-
-[properties]
-c_args = '-mno-avx512f'
config/x86/meson.build +1 -1
index 603359e55a..e25ed316f4 100644
@@ -3,7 +3,7 @@
 
 # get binutils version for the workaround of Bug 97
 binutils_ok = true
-if not is_windows and (is_linux or cc.get_id() == 'gcc')
+if is_linux or cc.get_id() == 'gcc'
     binutils_ok = run_command(binutils_avx512_check).returncode() == 0
     if not binutils_ok and cc.has_argument('-mno-avx512f')
         machine_args += '-mno-avx512f'
Signature · 1 line
2.29.3
Acked-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] config/x86: fix MinGW cross build with meson 0.49

Quoted 30 lines · Dmitry Kozlyuk

Cross build with MinGW was broken for the baseline meson 0.49.2.
Cause: in c_args = '-mno-avx512f' from config/x86/cross-mingw, each character was treated as a separate compiler option:

meson.build:4:0: ERROR: Compiler x86_64-w64-mingw32-gcc can not compile programs.

With c_args = ['-mno-avx512f'] configuration passed, but build failed, because Meson placed -mno-avx512f after -mavx512f in CFLAGS:

    In file included from /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/include/immintrin.h:55,
                     from /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/include/x86intrin.h:32,
                     from ../dpdk/lib/net/net_crc_avx512.c:13:
    /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/include/avx512fintrin.h:1650:1:
            error: inlining failed in call to always_inline _mm512_ternarylogic_epi64:
            target specific option mismatch
     1650 | _mm512_ternarylogic_epi64 (__m512i __A, __m512i __B, __m512i __C,
          | ^~~~~~~~~~~~~~~~~~~~~~~~~
    ../dpdk/lib/net/net_crc_avx512.c:59:9: note: called from here
       59 |  return _mm512_ternarylogic_epi64(tmp0, tmp1, data_block, 0x96);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Additionally, -m[no-]avx512f flag is expected to be in machine_args by all the checks in meson.build files.

Commit 419c6e9af69e ("net/i40e: fix build for Windows MinGW") fixed the errors cause by MinGW using AVX512F on Windows. The binutils AVX512F bug check is now portable,
so enable it for Windows to switch AVX512 support on and off without any special logic for MinGW.

Quoted 5 lines
Fixes 549bfc83168f ("config: disable AVX512 with MinGW")

---

#7 lore raw
In reply to Dmitry Kozlyuk

12/11/2021 22:48, Dmitry Kozlyuk:

Quoted 13 lines

The goal of this series is to enable cross-compilation
of Windows binaries from Linux using MinGW with Meson 0.49 used in CI. It also aims to reduce difference between Unix and Windows build code.

AVX512 was switched off for MinGW cross builds,
but unfortunately in a way that is not usable with meson 0.49. Also, c_args was used instead of machine_args for -mno-avx512f. After patch 3/3, AVX512 support for MinGW cross builds is configured exactly the same way as for Unix builds. This required rewriting a Unix-specific script in patch 2/3. Patch 1/3 skips check of GNU binutils when LLVM suite is used:
it is useful in general [1], and also simplifies patch 2/3.

Quoted 6 lines

[1]: https://inbox.dpdk.org/dev/20211112160837.131994aa@sovereign

Dmitry Kozlyuk (3):
config/x86: skip GNU binutils bug check for LLVM
buildtools: make AVX512 check script portable config/x86: fix MinGW cross build with meson 0.49

Applied, thanks.

Note 1: MAINTAINERS was updated for the new script.
Note 2: patch 3 cannot be backported without patch 2, so no Cc:stable on purpose.