Skip to content

Commit

Permalink
build: apply patch when building dpdk to use evex512 ISA
Browse files Browse the repository at this point in the history
when building dpdk on a building host which has AVX10.1 ISA support,
with Clang 18, we have following failure
```
/usr/lib/llvm-18/bin/clang -Ilib/net/libnet_crc_avx512_lib.a.p -Ilib/net -I../../../../../../dpdk/lib/net -I. -I../../../../../../dpdk -Iconfig -I../../../../../../dpdk/config -Ilib/eal/include -I../../../../../../dpdk/lib/eal/include -Ilib/eal/linux/include -I../../../../../../dpdk/lib/eal/linux/include -Ilib/eal/x86/include -I../../../../../../dpdk/lib/eal/x86/include -Ilib/eal/common -I../../../../../../dpdk/lib/eal/common -Ilib/eal -I../../../../../../dpdk/lib/eal -Ilib/kvargs -I../../../../../../dpdk/lib/kvargs -Ilib/metrics -I../../../../../../dpdk/lib/metrics -Ilib/telemetry -I../../../../../../dpdk/lib/telemetry -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -O3 -include rte_config.h -Wcast-qual -Wdeprecated -Wformat -Wformat-nonliteral -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wundef -Wwrite-strings -Wno-address-of-packed-member -Wno-missing-field-initializers -D_GNU_SOURCE -Wno-error -fPIC -march=native -DALLOW_EXPERIMENTAL_API -DALLOW_INTERNAL_API -Wno-format-truncation -DCC_X86_64_SSE42_PCLMULQDQ_SUPPORT -DCC_X86_64_AVX512_VPCLMULQDQ_SUPPORT -mavx512f -mavx512bw -mavx512dq -mavx512vl -mvpclmulqdq -mavx2 -mavx -MD -MQ lib/net/libnet_crc_avx512_lib.a.p/net_crc_avx512.c.o -MF lib/net/libnet_crc_avx512_lib.a.p/net_crc_avx512.c.o.d -o lib/net/libnet_crc_avx512_lib.a.p/net_crc_avx512.c.o -c ../../../../../../dpdk/lib/net/net_crc_avx512.c
Error: ../../../../../../dpdk/lib/net/net_crc_avx512.c:324:22: error: always_inline function '_mm512_broadcast_i32x4' requires target feature 'evex512', but would be inlined into function 'crc32_load_init_constants' that is compiled without support for 'evex512'
  324 |         crc32_eth.rk1_rk2 = _mm512_broadcast_i32x4(a);
      |                             ^
```

according to https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
and
https://github.com/llvm/llvm-project/blob/release/18.x/clang/docs/UsersManual.rst#x86,
we should either use `-mevex512` or use `-mavx10.1-512` for accessing
these new vectorized instructions provided by AVX10.1. so in this
change, per the suggestion in Clang's document of

> Users should avoid using AVX512 features in function target attributes
> when developing code for AVX10.

instead of keeping the `-mavx512*` options, we replace them with
`-mavx10.1-512`. the patch is not merged into DPDK upstream yet,
so let's apply it when building dpdk.

Fixes scylladb#2242

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed May 16, 2024
1 parent 169831e commit 244bac0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From dc33286852fa965b8ca8f57a5d52f3c4e5a92661 Mon Sep 17 00:00:00 2001
From: Kefu Chai <[email protected]>
Date: Thu, 16 May 2024 08:00:41 +0800
Subject: [PATCH] net: replace -mavx512* with -mavx10.1.512 in cflags

net_crc_avx512.c uses intrinsics like
`_mm512_broadcast_i32x4`, the corresponding AVX-512 instruction is
`VBROADCASTI32X4`, which is an AVX-10.1 ISA instruction, see
https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/intrinsics-for-integer-broadcast-operations.html
and https://cdrdv2-public.intel.com/795593/355989-intel-avx10-spec.pdf .

if we compile this file with
`-DCC_X86_64_SSE42_PCLMULQDQ_SUPPORT
-DCC_X86_64_AVX512_VPCLMULQDQ_SUPPORT -mavx512f -mavx512bw -mavx512dq
-mavx512vl -mvpclmulqdq -mavx2 -mavx` cflags using Clang 18.1.6, it fails
like:

```
Error: ../../../../../../dpdk/lib/net/net_crc_avx512.c:324:22: error: always_inline function '_mm512_broadcast_i32x4' requires target feature 'evex512', but would be inlined into function 'crc32_load_init_constants' that is compiled without support for 'evex512'
324 | crc32_eth.rk1_rk2 = _mm512_broadcast_i32x4(a);
|
```

according to GCC and LLVM's related document at
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html and
https://github.com/llvm/llvm-project/blob/release/18.x/clang/docs/UsersManual.rst,
we are encouraged to use `-mavx10.1-512` to instead of the `-mavx512*`
options, to use the 512-bit vector extension instruction set which
can otherwise enabled using `-mevex512`

so, in this change, we just replace the `-mavx512*` options with
a `-mavx10.1.512`.

Signed-off-by: Kefu Chai <[email protected]>
---
lib/net/meson.build | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/lib/net/meson.build b/lib/net/meson.build
index b1bc27bad5..fee9fdf406 100644
--- a/lib/net/meson.build
+++ b/lib/net/meson.build
@@ -68,13 +68,9 @@ if dpdk_conf.has('RTE_ARCH_X86_64')
elif net_crc_avx512_cc_support == true
build_static_net_crc_avx512_lib = 1
net_crc_avx512_lib_cflags = [
- '-mavx512f',
- '-mavx512bw',
- '-mavx512dq',
- '-mavx512vl',
'-mvpclmulqdq',
+ '-mavx10.1-512',
'-mavx2',
- '-mavx',
]
cflags += ['-DCC_X86_64_AVX512_VPCLMULQDQ_SUPPORT']
endif
--
2.45.0

2 changes: 2 additions & 0 deletions cooking_recipe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ endif ()
cooking_ingredient (dpdk
EXTERNAL_PROJECT_ARGS
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dpdk
PATCH_COMMAND patch -p1 <
${CMAKE_CURRENT_SOURCE_DIR}/cmake/dpdk-0001-net-replace-mavx512-with-mavx10.1.512-in-cflags.patch
CONFIGURE_COMMAND
env CC=${CMAKE_C_COMPILER} ${Meson_EXECUTABLE} setup ${dpdk_args} --prefix=<INSTALL_DIR> <BINARY_DIR> <SOURCE_DIR>
BUILD_COMMAND
Expand Down

0 comments on commit 244bac0

Please sign in to comment.