Skip to content

[Experimental] Add NIC_NEAR_AID to place NIC RDMA WRITEs by AID - #371

Draft
amd-arozanov wants to merge 5 commits into
developfrom
users/arozanov/nic-near-aid
Draft

amd-arozanov wants to merge 5 commits into
developfrom
users/arozanov/nic-near-aid

Conversation

@amd-arozanov

@amd-arozanov amd-arozanov commented Nov 25, 2026 •

Copy link
Copy Markdown

Experimental PR to test the near/far AID hypothesis on gfx1250 in SPX/NPS1 mode.

Motivation

This PR adds NIC_NEAR_AID, which lets the NIC write to one AID only. In SPX/NPS1, GPU memory switches between the two AIDs every 16 KiB, so normally half of the data a NIC writes goes to the AID next to the NIC and half goes to the other AID. Writing to one AID shows how much the far half costs.

Technical Details

Modes

NIC_NEAR_AID:

  • 0 (default): normal contiguous writes, no change.
  • 1 (near): write only to blocks on the AID next to the NIC.
  • 2 (far): write only to blocks on the other AID. Used as a control.

Memory layout

We measured the AID pattern beforehand. If you draw a 1 MiB region as an 8 x 8 grid of 16 KiB blocks, it looks like a checkerboard. Some regions use the inverted checkerboard:

regular        inverted
N F N F ...    F N F N ...
F N F N ...    N F N F ...
N F N F ...    F N F N ...
...            ...

N is a block on the AID next to the NIC, F is a block on the other AID.

  • The destination buffer is now twice the transfer size, because only half of each region is on the wanted AID.
  • TransferBench now checks each region once per Transfer to see which pattern it has. The CPU reads a few blocks and times them: near blocks take about 520 ns, far blocks about 620 ns.
  • Regions with unclear timing are treated as regular. That can only lower bandwidth, not break data. It happens for 0-1 of 2048 regions per 1 GiB.

Posting

  • Each 16 KiB block is sent as its own RDMA WRITE, because the blocks of one AID are not contiguous.
  • WRs are posted in chains of 32, and only the last one in a chain asks for a completion. This keeps completion overhead low.
  • At most 4 chains are in flight per queue pair, because more than that sometimes stalls the ionic NIC.
  • NIC_MAX_SEND_WR must be at least 256, because ionic also stalls when the WRs in flight fill more than half of the send queue.

Validation

Validation and the interactive PASS/FAIL view now put the blocks back in order before comparing, because the data is no longer contiguous.

Code

The new logic is in a separate file, src/header/NicNearAid.hpp, to keep it apart from the main code. TransferBench.hpp only has the option checks, the extra resources, the send loop, and the calls into the new file.

Requirements

  • x86 host
  • DMA-BUF support
  • one GPU destination
  • the NIC executor on the source rank
  • BYTE_OFFSET=0
  • VALIDATE_ON_DEVICE=0

Test Plan

Two gfx1250 nodes in SPX/NPS1 with AINIC (ionic) RoCE. Ranks set up over sockets (TB_RANK, TB_NUM_RANKS=2, TB_MASTER_ADDR). NUM_ITERATIONS=20, ALWAYS_VALIDATE=1, NIC_NEAR_AID = 0, 1, 2.

  • Both directions at once, one GPU and NIC per node, 4 queue pairs, 1 GiB each way: -2 (R0G0 R0I0.0 R1G0 4 1G) (R1G0 R1I0.0 R0G0 4 1G)
  • One direction only, same transfer
  • One queue pair, 1 GiB: -1 (R0G0 R0I0.0 R1G0 1 1G)
  • USE_INTERACTIVE=1 with ALWAYS_VALIDATE=0
  • Stress: 10 runs each of near and far, both directions

Test Result

Both directions, Aggregate (CPU):

NIC_NEAR_AID GB/s vs 0
0 135 1.00x
1 (near) 185-187 1.38x
2 (far) 109-110 0.81x
  • One direction only: near +2%, far -11%. The big difference shows up when the NIC sends and receives at the same time.
  • Validation passes in all modes, including the interactive view.
  • Stress: all 20 runs passed. Near 184.6-187.4 GB/s, far 109.1-110.6 GB/s.
  • One queue pair with 1 GiB works in near mode (52.6 GB/s, one direction).

On MI4XX (gfx1250) in SPX/NPS1 mode GPU memory alternates between the
two AIDs every 16 KiB, so a NIC writing a contiguous buffer sends half
of its data across the AID boundary. NIC_NEAR_AID makes that cost
measurable: 1 writes only the 16 KiB blocks on the NIC-near AID, 2 only
the blocks on the other AID, 0 keeps the contiguous layout.

The GPU destination is allocated at twice its size and its AID phase is
probed once per Transfer from CPU load latencies through an mmap of the
destination DMA-BUF. Each piece is one RDMA WRITE, posted as chains of
32 with only the tail signaled and at most 8 chains in flight per queue
pair, because longer unsignaled runs stall ionic. Validation copies the
destination to the host and gathers the pieces back into logical order.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical defects can hang execution on idle QPs or destination preparation failures across ranks, with additional unresolved near-AID validation and transfer-size checks.

5 open issues
What changed in this PR

Adds experimental NIC_NEAR_AID support to TransferBench for measuring NIC RDMA write performance to near versus far AID memory blocks on MI4XX (gfx1250) in SPX/NPS1 mode. The default remains contiguous writes.

Changes:

  • Exposes near/far placement through configuration and the NIC_NEAR_AID environment variable.
  • Adds destination-layout probing, expanded GPU allocations, chained 16 KiB writes, and layout-aware validation.
  • Documents the option, prerequisites, and intended experiment.
File Description
src/​header/​TransferBench.hpp Implements configuration checks, AID probing, transfer placement, completion tracking, and validation gathering.
src/​client/​EnvVars.hpp Adds environment-variable parsing, help text, and configuration wiring.
docs/​reference/​environment-variables.rst Documents placement modes and requirements.
CHANGELOG.md Announces the experimental near/far AID feature.

Review effort: Balanced

Comment thread src/header/TransferBench.hpp Resolved
Comment thread src/header/TransferBench.hpp Resolved
Comment thread src/header/TransferBench.hpp Resolved
Comment thread src/header/TransferBench.hpp Resolved
Comment thread src/header/TransferBench.hpp Resolved
With 8 chains of 32 WRs in flight (248 unsignaled WRs per queue pair)
an ionic queue pair occasionally stopped completing: one of about ten
bidirectional 1 GB runs hung in ibv_poll_cq without an error CQE. With
4 chains, 40 bidirectional near and far runs with ALWAYS_VALIDATE=1
passed at the same bandwidth.

The probe now times each read with std::chrono::steady_clock instead of
rdtsc between lfences. The clflush stays: the DMA-BUF mapping is cached
by the CPU, and without the flush every read hits the cache and no
region shows an AID split.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical issues can hang empty-QP transfers or strand ranks in collectives, while incomplete sparse-destination resets can let stale data mask missing writes.

6 open issues

Review effort: Balanced

Comment thread src/header/TransferBench.hpp Resolved
amd-arozanov and others added 2 commits November 26, 2026 10:08
The destination layout, the CPU probe of the AID phases, the build of
the RDMA WRITE chains and the gather of the destination into logical
order do not depend on TransferBench internals. They now live in
src/header/NicNearAid.hpp, so TransferBench.hpp keeps only the option
checks, the resource fields, the send window and the calls into the
new header. Behavior is unchanged.

Co-authored-by: Cursor <[email protected]>
NIC_NEAR_AID posts one RDMA WRITE per 16 KiB piece, but the max_msg_sz
checks bounded the work request size by NIC_CHUNK_BYTES, which could
reject a large transfer on a NIC with a small max_msg_sz. Both checks
now use the piece size in this mode.

The interactive PASS/FAIL display compared the DST contiguously and
reported FAIL for a correct transfer; it now gathers the pieces into
logical order, as ValidateAllTransfers does.

With ALWAYS_VALIDATE > 0 the DST was cleared only up to the transfer
size, so stale data in the rest of the doubled buffer could hide a
missing write. The whole buffer is now cleared.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 09:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Destination-only setup failures can leave other ranks blocked in a broadcast, while idle QPs can cause completion polling to hang indefinitely.

4 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/header/TransferBench.hpp Resolved
The per-Transfer state now lives in one NicNearAid::State field, and
the start of the send window and the handling of chain completions are
NicNearAid::PostFirstChains and NicNearAid::OnChainDone, so
ExecuteNicTransfer and RunNicExecutor only call into them. The checks
that the NIC executor is on the SRC rank and the DST is GPU memory move
to TransfersHaveErrors, so a bad Transfer is rejected before any
resource is prepared, and NicWorkRequestBytes holds the work request
size shared by both max_msg_sz checks.

NicNearAid.hpp now describes the layout as a regular or inverted
checkerboard of 16 KiB blocks, and the per-region phase is renamed to
inverted to match. CHANGELOG and docs name the target as gfx1250.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 11:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

AID selection depends on gfx1250 layout and CPU-latency assumptions that payload validation does not independently verify, requiring human assessment of hardware/topology correctness.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

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