Repository navigation
ARCH/X86: Add AVX512 nt-buffer-transfer functions - #11954
arun-chandran-edarath wants to merge 7 commits into
Conversation
|
🤖 Starting review — findings will be posted here when done. |
|
|
||
| #ifdef __AVX__ | ||
| #if defined(__AVX512BW__) | ||
| #include "cpu_nt_avx512.inl" |
There was a problem hiding this comment.
nothing in the build ever adds -mavx512bw — config/m4/compiler.m4 only has COMPILER_CPU_OPTIMIZATION([avx], ...), and no job in buildlib//contrib/ passes --with-avx/--enable-optimizations/-march=native. so this branch and the whole new .inl are never compiled, and test_arch.nt_buffer_transfer_* never covers them. can we add an avx512bw optimization knob plus a CI build that enables it?
There was a problem hiding this comment.
@tvegas1 @roiedanino Any suggestions on how to handle this?
There was a problem hiding this comment.
@tvegas1 @roiedanino @yosefe gentle reminder. Before I can address this thread,
we need to agree on how the AVX-512 kernels should be enabled in the build. I
see a few options and would like your view.
Current state:
- The NT path is compiled only when
__AVX__is defined, i.e. with
--enable-optimizationsor--with-avx(-mavx).
run_nt_buffer_transfer_testsincontrib/test_jenkins.shalready builds
this way and runstest_arch.*. - No configure option adds
-mavx512bw, so the AVX-512 kernels are compiled
only when the user passes it inCFLAGS(for example-march=znver5). Such
a build also skips theCPU_FLAGScheck inucs_check_cpu_flags(), so on a
CPU without AVX-512 it fails with SIGILL instead of the FATAL message.
Options:
- Add
--with-avx512bwthat follows--enable-optimizations, like
--with-avx.- No CI change: the
roceworker that runs
run_nt_buffer_transfer_tests(currently a Xeon Silver 4210R) supports
AVX512BW, so it would test the AVX-512 kernels, and the Haswell and Sandy
Bridge workers keep testing the AVX2 kernels. - Existing
--enable-optimizationsbuilds on AVX-512 hosts, including
Skylake-SP and Cascade Lake, switch to the AVX-512 kernels.
--without-avx512bwkeeps the old behavior.
- No CI change: the
- Add
--with-avx512bwas opt-in only (defaultno).- No change for existing builds.
- Needs a CI change: an extra
--with-avx512bwbuild in
run_nt_buffer_transfer_testson hosts withavx512bwin
/proc/cpuinfo.
- No new configure option: keep the
CFLAGSway and add a compile-only CI
build.- Smallest change.
- No
CPU_FLAGScheck and no CI run of the AVX-512 kernels.
For options 1 and 2, the flag would be -mavx512bw: it enables only AVX512F
and AVX512BW, which is what the kernels use, and it matches the
__AVX512BW__ check in cpu.c. As with -mavx today, it applies to the whole
library. I would also add AVX512BW to ucs_arch_get_cpu_flag() and
ucs_check_cpu_flags().
Which option do you prefer, or is there another approach you want? I will
update the PR once we agree.
There was a problem hiding this comment.
Seems AVX-512 might not always be faster than AVX2 so i would not enable it for every --enable-optimizations build.
Can we do it this way?
- add
--with-avx512bw, defaultno(explicit opt-in) and test in CI - let
--with-march=<arch>take a value (today it is only yes/no), and in m4 enable avx512bw by default only for arches where we measured a gain, e.g.znver5 - in
cpu.c, select the AVX-512 kernels from a configure define instead of__AVX512BW__, otherwise-march=znver4in CFLAGS would still select them - add AVX512BW to
ucs_arch_get_cpu_flag()/ucs_check_cpu_flags(), and one--with-avx512bwbuild inrun_nt_buffer_transfer_tests
Also, is runtime selection doable? i.e. build both AVX2 and AVX-512 kernels, and pick one in ucs_cpu_init() by cpu flag + vendor/model (like ucs_cpu_memcpy_thresh()), with a UCX_ knob to override. It would let one binary use the best kernel on each CPU.
There was a problem hiding this comment.
@tvegas1 agreed, opt-in is the right default for AVX-512. The update:
--with-avx512bwis off by default, and--enable-optimizationsdoes not
turn it on. If it is requested but the compiler or build machine cannot run
AVX512BW code, configure fails instead of quietly building the AVX2 kernels.- The AVX-512 kernels are now selected by a configure define instead of
__AVX512BW__, so-march=znver4inCFLAGSalone keeps the AVX2 kernels. - AVX512BW is added to
ucs_arch_get_cpu_flag()and checked at load time, so
running such a build on a CPU without AVX512BW gives the FATAL message
instead of SIGILL. - CI:
run_nt_buffer_transfer_testsadds a--with-avx512bwbuild on
AVX512BW hosts and runstest_arch.*with it.
Adding the flag exposed a bug in the existing detection.
ucs_arch_get_cpu_flag() reads CPUID leaf 7 without setting the sub-leaf in
ECX, so depending on the compiler it can read an invalid sub-leaf and miss AVX2
even on CPUs that have it. AVX512BW comes from the same leaf, so without a fix
a --with-avx512bw build could stop with the FATAL message on a CPU that does
support AVX512BW. The read now uses sub-leaf 0. A gtest cross-checks each of
the AVX2 and AVX512BW flags against __builtin_cpu_supports().
I kept --with-march=<arch> out of this PR:
- On x86, configure never evaluates
--with-marchtoday. On AArch64 it means
"use the detected-march", and accepting a value would change that. -marchlets the compiler use the whole ISA anywhere in UCX, while the
load-time check covers only the flags UCX knows. A mismatch would then show
up as SIGILL rather than the FATAL message.- A per-architecture default would mean keeping a CPU list in configure. With
the opt-in option, anyone building for AVX-512 systems can already enable it
with one flag.
I don't plan to add run-time selection either. The cases where AVX-512 loses
to AVX2 are mainly older CPUs, where 512-bit instructions lower the clock
frequency. Recent designs have reduced or removed that penalty, so we expect
AVX-512 to be the better choice on new CPUs. Run-time selection would be new
infrastructure, because UCX selects ISA-specific code only at build time
today. It would need both kernels in one library, a choice in ucs_cpu_init()
by vendor and model, a CPU table to maintain, and a UCX_ override, mostly to
serve CPUs that are going out of service. The opt-in option already covers
them: builds for those systems leave --with-avx512bw off.
| } | ||
|
|
||
| #ifdef __AVX__ | ||
| #if defined(__AVX512BW__) |
There was a problem hiding this comment.
on Intel Skylake-SP/Cascade Lake, 512-bit stores trigger AVX-512 frequency licensing, so a -march=native build there may end up slower than the AVX2 path. should the AVX-512 kernels be picked by vendor/uarch instead of purely by __AVX512BW__?
| ucs_memory_bus_store_fence(); | ||
| } | ||
|
|
||
| /* AVX-512 NT_SOURCE copy-out: body stores, descending. An unconditional |
There was a problem hiding this comment.
why descending here? ucs_x86_nt_src_avx2_buffer_transfer copies ascending, and the descent is the only reason for the four _bwd helpers — the same masked-head + ascending-body structure as ucs_x86_nt_dst_avx512_buffer_transfer would drop all of them.
|
|
||
| /* Vector copy helpers. Ascending helpers store from the base [dst, dst+n); | ||
| * descending (_bwd) helpers store from the top [dst-n, dst). The | ||
| * ucs_compiler_fence() between the four stores pins their order (they are |
There was a problem hiding this comment.
why is the store ordering needed here when cpu_nt_avx2.inl has no fences at all? each 512-bit store already covers a full 64B line, so write-combining should not depend on the order, and in the _bwd helpers these are plain WB stores where the barrier only constrains the scheduler.
| arch/ppc64/cpu.h \ | ||
| arch/rv64/cpu.h \ | ||
| arch/x86_64/cpu.h \ | ||
| arch/x86_64/cpu_nt_avx512.inl \ |
There was a problem hiding this comment.
minor: pls keep the list sorted.
| arch/x86_64/cpu_nt_avx512.inl \ | |
| arch/x86_64/cpu_nt_avx2.inl \ | |
| arch/x86_64/cpu_nt_avx512.inl \ |
| static UCS_F_ALWAYS_INLINE void | ||
| ucs_x86_avx512_nt_masked_head_64(void *dst, const void *src, size_t edge_len) | ||
| { | ||
| const size_t head_pad = 64u - edge_len; |
There was a problem hiding this comment.
minor: -head_pad on a size_t wraps to 2^64 - head_pad and then relies on the implementation-defined (intptr_t) conversion in UCS_PTR_BYTE_OFFSET.
| const size_t head_pad = 64u - edge_len; | |
| const ptrdiff_t head_pad = 64 - (ptrdiff_t)edge_len; | |
| const __mmask64 k = (__mmask64)(~0ull << head_pad); |
|
@roiedanino @tvegas1 Please review. |
CLA check passedAll commits are covered by a signed CLA. |
|
🤖 CI Triage Agent — TL;DR: This is not a code/test failure — the Full analysisSummary: The Root cause: Policy gate failure, not a build/test regression. The log shows the check ran cleanly ( Every commit on branch Implicated commit: The failure is attributable to the PR's own commits (HEAD File: Suggested fix: The PR author should:
Do not retry the job or touch CI config expecting a different result — the check is deterministic and will keep failing until the commits are signed by a CLA-registered identity. Related: #12120 (added the CLA check), #11954 (the failing PR),
|
|
🤖 Starting review — findings will be posted here when done. |
dc24343 to
597f804
Compare
| UCS_CPU_FLAG_AVX = UCS_BIT(9), | ||
| UCS_CPU_FLAG_AVX2 = UCS_BIT(10) | ||
| UCS_CPU_FLAG_AVX2 = UCS_BIT(10), | ||
| UCS_CPU_FLAG_AVX512BW = UCS_BIT(11) |
There was a problem hiding this comment.
master already uses UCS_BIT(11) for UCS_CPU_FLAG_LS64, which was added after this branch, so after a rebase two flags would share the same bit. pls rebase and take the next free bit.
| UCS_CPU_FLAG_AVX512BW = UCS_BIT(11) | |
| UCS_CPU_FLAG_AVX512BW = UCS_BIT(12) |
| #ifndef __AVX512BW__ | ||
| #error "HAVE_NT_AVX512BW is set but -mavx512bw is not in effect" | ||
| #endif | ||
| #include "cpu_nt_avx512.inl" |
There was a problem hiding this comment.
the kernel is picked at build time and -mavx512bw ends up in BASE_CFLAGS for the whole library, so ucs_check_cpu_flags() aborts such a build on any CPU without AVX512BW, and packaged builds can never enable it. why not dispatch at runtime on UCS_CPU_FLAG_AVX512BW, which this PR already detects, and build only this kernel with __attribute__((target("avx512bw")))?
| [no], | ||
| [AC_DEFINE([HAVE_NT_AVX512BW], [1], | ||
| [Use the AVX512BW NT buffer-transfer kernels])], | ||
| [AC_MSG_ERROR([--with-avx512bw was requested, but the compiler or this build machine does not support -mavx512bw])]) |
There was a problem hiding this comment.
CHECK_CROSS_COMP runs the probe, so --with-avx512bw now hard-fails on any build machine whose CPU lacks AVX512BW, even when the deployment target has it. can we make this one a compile/link-only check and leave the CPU validation to ucs_check_cpu_flags()?
|
|
||
| /* 256B NT store (4x), ascending, aligned load. */ | ||
| static UCS_F_ALWAYS_INLINE void | ||
| ucs_x86_avx512_loada_stream_256(void *dst, const void *src) |
There was a problem hiding this comment.
the four 256B helpers differ only in load alignment and store direction; can we fold them into one always-inline helper taking aligned/descending as constant args? root AGENTS.md asks not to duplicate similar implementation patterns.
| __m512i z3 = _mm512_loadu_si512(sa + 3); | ||
|
|
||
| _mm512_stream_si512(da, z0); | ||
| ucs_compiler_fence(); |
There was a problem hiding this comment.
why is ucs_compiler_fence() needed between the stream stores here, while the AVX2 kernels issue 8 stream stores with no barrier? this is the hot loop, so pls keep the barriers only if they show a measurable gain.
| ucs_memory_bus_store_fence(); | ||
| } | ||
|
|
||
| /* AVX-512 NT_SOURCE copy-out: body stores, descending. An unconditional |
There was a problem hiding this comment.
why does the AVX-512 NT_SOURCE copy descend while the AVX2 one ascends? descending streams are less friendly to the HW prefetchers, so pls note the reason in the comment.
| echo "==== Running test_arch tests with optimizations ====" | ||
| ./test/gtest/gtest --gtest_filter="test_arch.*" | ||
|
|
||
| if ! grep -qw avx512bw /proc/cpuinfo |
There was a problem hiding this comment.
do the x86 CI nodes report avx512bw? if not, the whole --with-avx512bw build and the new kernels are silently never tested.
|
🤖 Starting review — findings will be posted here when done. |
Add AVX512BW kernels with masked edge handling and compile-time ISA selection. Keep the AVX2 implementation as the fallback when AVX512BW is not enabled. Signed-off-by: Arun Chandran <Arun.Chandran@amd.com>
CPUID leaf 7 reports the AVX2 and AVX-512 feature bits in EBX of sub-leaf 0, selected by ECX. ucs_arch_get_cpu_flag() read the leaf with ucs_x86_cpuid(), which loads only EAX, so the sub-leaf was whatever ECX held. The value depends on code generation; in one optimized build it was part of a stack address. CPUID returns zeros for an invalid sub-leaf, so ucs_arch_get_cpu_flag() then omitted UCS_CPU_FLAG_AVX2 on an AVX2-capable CPU. Use ucs_x86_cpuid_ecx() with sub-leaf 0, as the leaf 4 cache code already does. Signed-off-by: Arun Chandran <Arun.Chandran@amd.com>
Compare UCS_CPU_FLAG_AVX2 with the compiler's __builtin_cpu_supports() result. Before the previous commit read CPUID leaf 7 sub-leaf 0, UCX did not report AVX2 on AVX2-capable CPUs and nothing noticed, because no code or test consumed the flag. Signed-off-by: Arun Chandran <Arun.Chandran@amd.com>
| UCS_CPU_FLAG_AVX = UCS_BIT(9), | ||
| UCS_CPU_FLAG_AVX2 = UCS_BIT(10) | ||
| UCS_CPU_FLAG_AVX2 = UCS_BIT(10), | ||
| UCS_CPU_FLAG_AVX512BW = UCS_BIT(11) |
There was a problem hiding this comment.
blocker: UCS_BIT(11) is already taken by UCS_CPU_FLAG_LS64 on master, pls rebase and use UCS_BIT(12) for AVX512BW.
| __m512i z3 = _mm512_loadu_si512(sa + 3); | ||
|
|
||
| _mm512_stream_si512(da, z0); | ||
| ucs_compiler_fence(); |
There was a problem hiding this comment.
why do we need the ucs_compiler_fence() between the stores here? the AVX2 kernel issues 8 independent _mm256_stream_si256 without any, so this looks like an unexplained difference in the hot loop. (Applies to the other three helpers as well.)
| ucs_memory_bus_store_fence(); | ||
| } | ||
|
|
||
| /* AVX-512 NT_SOURCE copy-out: body stores, descending. An unconditional |
There was a problem hiding this comment.
why is NT_SOURCE descending here while the AVX2 NT_SOURCE kernel copies ascending? pls add the reason to the comment, it is the only place the two kernels differ in direction.
Add UCS_CPU_FLAG_AVX512BW. It is set when the CPU reports AVX, AVX512F and AVX512BW, and XCR0 shows that the OS saves the opmask and full ZMM state, so a hypervisor or kernel that hides AVX-512 state is treated as lacking support. Register "avx512bw" in ucs_check_cpu_flags() so a library built with that CPU flag fails at load time on a CPU without it. Signed-off-by: Arun Chandran <Arun.Chandran@amd.com>
Compare UCS_CPU_FLAG_AVX512BW with the compiler's __builtin_cpu_supports() result. The test runs on every x86 host, so hosts without AVX-512 check the negative case. GCC 5 and older reject the "avx512bw" feature name, so the test is compiled only by Clang and GCC 6 or newer. Signed-off-by: Arun Chandran <Arun.Chandran@amd.com>
Select the AVX512BW NT buffer-transfer kernels with an explicit --with-avx512bw configure option instead of the compiler's __AVX512BW__ macro. A -march in CFLAGS that enables AVX-512 no longer switches kernels on its own; such builds keep the AVX2 kernels. The option defaults to no and is not enabled by --enable-optimizations. When given, configure compiles and runs a masked AVX512BW load and store on the build machine (link only when cross-compiling) and stops with an error if that fails, rather than silently building the AVX2 kernels. On success it adds -mavx512bw, records avx512bw in CPU_FLAGS for the load-time CPU check, and defines HAVE_NT_AVX512BW. Values other than yes or no are rejected. COMPILER_CPU_OPTIMIZATION gains optional default, action-if-found and action-if-not-found arguments; existing callers are unchanged. cpu.c stops the build if HAVE_NT_AVX512BW is set while user CFLAGS such as -mno-avx512bw turn AVX512BW off again. Signed-off-by: Arun Chandran <Arun.Chandran@amd.com>
After the existing optimized build, check that ucx_info -b does not report HAVE_NT_AVX512BW, which covers the default path. On a worker whose CPU reports avx512bw, rebuild with --with-avx512bw, require HAVE_NT_AVX512BW 1 in ucx_info -b, and rerun the test_arch tests against the AVX512BW kernels. Other workers print an explicit skip. Signed-off-by: Arun Chandran <Arun.Chandran@amd.com>
597f804 to
5160510
Compare
|
🤖 Starting review — findings will be posted here when done. |
| return | ||
| fi | ||
|
|
||
| build release --enable-gtest --enable-optimizations --with-avx512bw |
There was a problem hiding this comment.
The second build is requested based on CPU flags only, but configure now hard-errors on --with-avx512bw if the compiler rejects -mavx512bw (e.g. gcc < 5), and build runs under set -e, so the whole job fails on such a host. Please gate this on compiler support too.
| # alone keeps the AVX2 kernels. The probe runs a masked AVX512BW load and store, | ||
| # so the build machine must support AVX512BW unless cross-compiling. | ||
| # | ||
| AS_CASE(["x$with_avx512bw"], |
There was a problem hiding this comment.
Minor: this reads $with_avx512bw before COMPILER_CPU_OPTIMIZATION declares the option, and no other --with- validates its value. Can we fold the check into the macro so all CPU options behave the same?
| arch/ppc64/cpu.h \ | ||
| arch/rv64/cpu.h \ | ||
| arch/x86_64/cpu.h \ | ||
| arch/x86_64/cpu_nt_avx512.inl \ |
There was a problem hiding this comment.
Minor: list is alphabetical, "avx2" sorts before "avx512". Suggestion (replacing the two adjacent lines):
| arch/x86_64/cpu_nt_avx512.inl \ | |
| arch/x86_64/cpu_nt_avx2.inl \ | |
| arch/x86_64/cpu_nt_avx512.inl \ |
|
Please add one line on why NT_SOURCE descends here while the AVX2 kernel ascends; the direction flip is the main behavioral difference between the two files and is not obvious from the code. (Around line 218.) Residual coverage gaps: the AVX-512 kernels are exercised only by |
|
🤖 CI Triage Agent — TL;DR: The BlueField ASan job failed on the LeakSanitizer check at the end of the gtest run ( Full analysisSummary: Root cause: Every leaked allocation's stack bottoms out in the test's setup path:
The QP buffer, the There is nothing in the log tying this to the PR under test: PR #11954 ( Implicated commit: Most likely File: Suggested fix:
Related: PR #12387 (
|
What?
Add AVX512BW non-temporal destination and source kernels with masked edge handling. Select the AVX-512 implementation at compile time when configured with
--with-avx512bwand retain AVX2 as the fallback.This is the third part of the split from #11696, following #11878 and #11895.
Why?
Use the full AVX-512 vector width for large cache-bypassing transfers and use byte masks for non-cache-line-aligned edges.
How?
The NT destination kernel copies forward with streaming stores and an
sfence. The NT source kernel copies backward with regular stores and no fence. Both implementations retain the existing dispatcher contract.Build
AVX2: configure with --enable-optimizations.
AVX-512: configure with --with-avx512bw.
Runtime requirements
Currently recommended for workloads using one MPI rank per L3 cache domain.
Required runtime arguments(config params):
UCX_NT_BUFFER_TRANSFER_MIN=0
The default UCX_NT_BUFFER_TRANSFER_MIN start threshold is three-quarters of the detected L3 cache size.