Console waves' meetings: cheaper, fewer, and none where LDS order does not count

CS_DefragHeap_ComputeRelocations took 11.9 ms of GPU time a frame with
the pair meetings of ce383f8 (run 184458, the card's time by command).
Three changes, all for console waves meeting on their own
(`with_pair_meetings`: the digest list, VICTORY_WAVE_WIDE=1):

- LDS order (`LdsOrder`): the program cut at its s_barriers; an access
  needs the host waves of its console wave to meet only when a plain
  ds_write stands in a piece it can reach or be reached from. Atomics
  among themselves and reads of what an earlier piece wrote need none.
  In ComputeRelocations the relocation pass (reads, ds_cmpst loops,
  ds_add_rtn) and the copy pass after it lose every meeting, and their
  per-lane loops are no longer taken wave-wide: 8 branches widened
  instead of 18, 50 meetings in the code instead of 138. Reads near an
  LDS atomic are not taken as alike in every lane.
- A meeting: the first lane of each host wave counts it in (one atomic
  per host wave, two a meeting), the wave polls the counter with one
  shared load behind a fence. Before: an atomic per lane to arrive and
  per lane per poll.
- An exchange is one meeting: two buffers per console wave, taken in
  turn by the count of meetings (a half writes one only after the
  meeting its partner's reads of it came before). Before: two meetings.
  A first-lane read exchanges "has a lane" and the value at once.

Other programs translate as before (900 compute programs, the same DXIL
with VICTORY_HOST_MAX_WAVE=32); ComputeRelocations validates. Tests: the
two console waves' loops still bit-exact on the RTX 4070 SUPER; a new
test for the LDS order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-26 19:24:19 +05:30
1 parent 02b255d25b
commit 89cfae291b
2 files changed
+329 -58

No files matched your search

@@ -898,3 +898,38 @@ fn console_waves_of_one_group_meet_on_their_own_in_loops_of_their_own() {
}
eprintln!("ran on the hardware device: both console waves' loops, as the console runs them");
}
/// Which LDS accesses need the host waves of their console wave to meet
/// ([`lower::LdsOrder`]): before a barrier a lane writes its dword and reads it back (the
/// order counts); after it the lanes read and add with atomics only (it does not: a read
/// there may see another lane's atomic, so it is not taken as alike in every lane).
#[test]
fn lds_accesses_after_the_last_plain_write_need_no_meeting() {
let words = [
0x3402_0082, // v_lshlrev_b32 v1, 2, v0
0xD834_0000,
0x0000_0001, // ds_write_b32 v1, v0
0xD8D8_0000,
0x0400_0001, // ds_read_b32 v4, v1
0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
0xBF8A_0000, // s_barrier
0xD8D8_0000,
0x0500_0001, // ds_read_b32 v5, v1
0xD800_0000,
0x0000_0001, // ds_add_u32 v1, v0
];
let mut native = native_of(&words, true, 128);
if let StageIo::Cs(cs) = &mut native.io {
cs.rsrc2 |= 1 << 15;
}
let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build");
let st = structure::structure(&p).expect("structure");
let order = lower::lds_order(&p, &st);
let name = |&(b, i): &(usize, usize)| (p.blocks[b].insts[i].name(), p.blocks[b].insts[i].machine.offset);
let mut unordered: Vec<_> = order.unordered.iter().map(name).collect();
unordered.sort_unstable_by_key(|x| x.1);
let unstable: Vec<_> = order.unstable.iter().map(name).collect();
assert_eq!(unordered.iter().map(|x| x.0).collect::<Vec<_>>(), ["ds_read_b32", "ds_add_u32"]);
assert_eq!(unstable.iter().map(|x| x.0).collect::<Vec<_>>(), ["ds_read_b32"]);
assert!(unordered[0].1 > 0x10, "the read after the barrier");
}