Skip to content

ARCH/X86: Add AVX512 nt-buffer-transfer functions - #11954

Open
arun-chandran-edarath wants to merge 1 commit into
openucx:masterfrom
arun-chandran-edarath:ntbt_avx512_nt_kernels
Open

arun-chandran-edarath wants to merge 1 commit into
openucx:masterfrom
arun-chandran-edarath:ntbt_avx512_nt_kernels

Conversation

@arun-chandran-edarath

@arun-chandran-edarath arun-chandran-edarath commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What?

Add AVX512BW non-temporal destination and source kernels with masked edge handling. Select the AVX-512 implementation at compile time when __AVX512BW__ is defined and 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: add -march=znver5 or another target flag defining AVX512BW into CFLAGS.

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.

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>
@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread src/ucs/arch/x86_64/cpu.c

#ifdef __AVX__
#if defined(__AVX512BW__)
#include "cpu_nt_avx512.inl"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing in the build ever adds -mavx512bwconfig/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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvegas1 @roiedanino Any suggestions on how to handle this?

Comment thread src/ucs/arch/x86_64/cpu.c
}

#ifdef __AVX__
#if defined(__AVX512BW__)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/ucs/Makefile.am
arch/ppc64/cpu.h \
arch/rv64/cpu.h \
arch/x86_64/cpu.h \
arch/x86_64/cpu_nt_avx512.inl \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: pls keep the list sorted.

Suggested change
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

@arun-chandran-edarath

Copy link
Copy Markdown
Contributor Author

@roiedanino @tvegas1 Please review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants