Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/xcl/src/gpu/dxil/core_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ fn prog(list: &[(&str, &str, &[(&str, u64)], Option<u32>)]) -> Vec<u8> {
v
}

#[test]
fn split_single_wave_uses_bounded_exchange() {
use crate::gpu::recomp::CsInterface;
let code = prog(&[("V_READLANE_B32", "ENC_VOP3", &[("VDST", 1), ("SRC0", 256), ("SRC1", 160)], None)]);
let options = KernelOptions { wave64: true, split: true, mem_windows: 1, sampler_base: 0 };
let kernel = translate(&code, options).unwrap();
let dis = super::validate::disassemble(&kernel).unwrap();
assert!(dis.matches("atomicrmw").count() >= 3, "kernel must use bounded counter exchange: {dis}");
let single = CsInterface { threads: [32, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1 };
let single_shader = super::kernel::translate_compute(&code, options, &single).unwrap();
let single_dis = super::validate::disassemble(&single_shader.dxil).unwrap();
assert!(single_dis.matches("atomicrmw").count() < 3, "a missing partner must not spin: {single_dis}");
for threads in [33, 64, 128] {
let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1 };
let shader = super::kernel::translate_compute(&code, options, &cs).unwrap();
let dis = super::validate::disassemble(&shader.dxil).unwrap();
assert!(dis.matches("atomicrmw").count() >= 3, "{threads} threads must use bounded counter exchange: {dis}");
}
let with_lds = prog(&[
("DS_WRITE_B32", "ENC_DS", &[("ADDR", 1), ("DATA0", 0)], None),
("V_READLANE_B32", "ENC_VOP3", &[("VDST", 1), ("SRC0", 256), ("SRC1", 160)], None),
]);
let shader = super::kernel::translate_compute(&with_lds, options, &CsInterface { threads: [64, 1, 1], ..single }).unwrap();
let dis = super::validate::disassemble(&shader.dxil).unwrap();
assert!(dis.matches("atomicrmw").count() >= 3, "LDS-backed counters must use bounded exchange: {dis}");
}
#[test]
fn straight_line_and_loop_kernels_validate() {
let code = prog(&[
Expand Down
7 changes: 3 additions & 4 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,9 @@ fn translate_on_this_thread(code: &[u8], o: KernelOptions, entry: Entry) -> Resu
lw.whole_live = crate::gpu::recomp::x64_masks::by_pc(&cfg.insts, kernel);
}
lw.setup_storage(uses_lds, if split { slot } else { 1 });
if let (Some(t), true) = (group_threads, split) {
lw.partner = match t {
0..=32 => Partner::Missing,
33..=64 => Partner::Present,
if split {
lw.partner = match group_threads {
Some(0..=32) => Partner::Missing,
_ => Partner::Spin,
};
}
Expand Down
23 changes: 14 additions & 9 deletions crates/xcl/src/gpu/dxil/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
//! value built with `WaveActiveBallot`; a lane tests its own bit
//! ([`Lw::lanebit`], cached per block). In the split form (a wave64 console
//! program on a GPU with 32-lane waves only, `docs/wave64-on-wave32.md`) the
//! two hardware halves of the console wave are the whole thread group and
//! meet at a group barrier to exchange one word each: ballot words and
//! `v_readlane` values. Lane reads the ISA keeps inside a 32-lane half (DPP,
//! two hardware halves exchange ballot words and `v_readlane` values through bounded
//! group-shared counters. Lane reads the ISA keeps inside a 32-lane half (DPP,
//! `ds_swizzle`, permlane) need no exchange.

use super::lower::{Lw, Partner};
Expand Down Expand Up @@ -39,12 +38,10 @@ impl Lw {
} else if self.split {
let w = self.s.groupshared("xcl_xw", i32, 1);
self.xw = Some((w, 0));
if self.waves > 1 {
let x = self.s.groupshared("xcl_xs", i32, (4 * self.xslot * self.waves) as u64);
self.xs = Some((x, 0));
let c = self.s.groupshared("xcl_xc", i32, 2 * self.waves as u64);
self.xc = Some((c, 0));
}
let x = self.s.groupshared("xcl_xs", i32, (4 * self.xslot * self.waves) as u64);
self.xs = Some((x, 0));
let c = self.s.groupshared("xcl_xc", i32, 2 * self.waves as u64);
self.xc = Some((c, 0));
}
}

Expand All @@ -58,7 +55,15 @@ impl Lw {
let ai = self.c(at);
let p = self.s.gs_ptr(xw, ai);
self.s.m.store(p, z, 4);
let (xc, cb) = self.xc.expect("split counters");
let gi = self.s.flattened_thread_id_in_group();
let last = self.c(1);
let counter = self.umin(gi, last);
let counter = self.addc(counter, cb);
let cp = self.s.gs_ptr(xc, counter);
self.s.m.store(cp, z, 4);
self.s.barrier(barrier::GROUP_SYNC);
self.xn = self.c(32);
let first = self.s.wave_is_first_lane();
let k = self.selc(first, 32, z);
let got = self.s.m.atomic_rmw(RmwOp::Add, p, k);
Expand Down
Loading