Skip to content
Merged
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
1 change: 1 addition & 0 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ impl Lw {
whole_live: Default::default(),
guard_override: None,
mask_override: None,
local_masks: false,
exchange_error: None,
pc: 0,
};
Expand Down
7 changes: 6 additions & 1 deletion crates/xcl/src/gpu/dxil/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ pub struct Lw {
/// When set, the wave-wide mask cross-lane instructions see (DPP source lanes,
/// readfirstlane, ds_swizzle / bpermute) instead of the SSA EXEC.
pub mask_override: Option<(Value, Value)>,
/// split form: a mask an instruction writes is built from this half's ballot alone, as
/// when it is never read whole. Set by a caller that reads back only each lane's own bit
/// (the per-lane form's bridge), so no exchange meets the other half.
pub local_masks: bool,
}

impl Lw {
Expand Down Expand Up @@ -867,7 +871,8 @@ impl Lw {
// split form: a mask only ever read lane by lane (or going nowhere, or 0 anyway)
// needs only this half's word (`recomp::x64_masks`, the HLSL `xcl_x_ballot_local`)
let local = self.split
&& (self.s.m.const_u64(cond) == Some(0)
&& (self.local_masks
|| self.s.m.const_u64(cond) == Some(0)
|| match *dst {
Dst::S(n) => n < 126 && self.whole_live.get(&self.pc).is_some_and(|live| live & (3u128 << n) == 0),
Dst::Null => true,
Expand Down
55 changes: 55 additions & 0 deletions crates/xcl/src/gpu/recomp/lower_dxil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ impl Ir for DxilIr {
// the registers `Lw` touches for `d` alone
let before = std::mem::take(&mut self.lw.init.touched);
self.lw.pc = d.pc;
// the per-lane form reads back only this lane's bit of a mask `d` writes: in the split
// form a ballot of this half is enough, and an exchange there would wait at a barrier
// for a half that is elsewhere when only one half reaches this block
self.lw.local_masks = true;
let r = self.lw.inst_guarded(d, guard, None);
self.lw.local_masks = false;
let used = std::mem::replace(&mut self.lw.init.touched, before);
self.lw.init.touched.extend(&used);
r?;
Expand Down Expand Up @@ -1005,4 +1010,54 @@ mod tests {
}
}
}

/// A float compare bridged to #1426's lowering in a block only the lower half of a split
/// wave64 group reaches (Pipodi's point 5 on #1745): a nested `if` whose condition goes to
/// `s_and_saveexec`. #1426 would ballot the compare's mask through an exchange, a group
/// barrier the upper half never reaches. The bridge reads back only each lane's bit, so this
/// half's ballot is enough, and the only barrier left is the one at the start.
#[test]
fn a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier() {
let lines: &[I] = &[
("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 1), ("SRC0", V)]),
("V_MOV_B32", "ENC_VOP1", &[("VDST", 7), ("SRC0", 128)]),
// lanes 0–31: the lower hardware half
("V_CMP_GT_U32", "ENC_VOPC", &[("SRC0", 160), ("VSRC1", 0)]),
("S_AND_SAVEEXEC_B64", "ENC_SOP1", &[("SDST", 8), ("SSRC0", 106)]),
("S_CBRANCH_EXECZ", "ENC_SOPP", &[("SIMM16", 4)]),
// 0 < f32(lane): every lane in EXEC but lane 0
("V_CMP_LT_F32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 1)]),
("S_AND_SAVEEXEC_B64", "ENC_SOP1", &[("SDST", 10), ("SSRC0", 106)]),
("V_MOV_B32", "ENC_VOP1", &[("VDST", 7), ("SRC0", 133)]),
("S_OR_B64", "ENC_SOP2", &[("SDST", 126), ("SSRC0", 126), ("SSRC1", 10)]),
("S_OR_B64", "ENC_SOP2", &[("SDST", 126), ("SSRC0", 126), ("SSRC1", 8)]),
("S_LSHL_B32", "ENC_SOP2", &[("SDST", 3), ("SSRC0", 2), ("SSRC1", 135)]),
("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 4), ("SRC0", 3), ("VSRC1", 0)]),
("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 8), ("SRC0", 130), ("VSRC1", 4)]),
("V_MOV_B32", "ENC_VOP1", &[("VDST", 9), ("SRC0", 128)]),
("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 7), ("SADDR", 125), ("OFFSET", 0)]),
ENDPGM,
];
// one console wave per group: the halves meet at a group barrier (`Partner::Present`)
let cs = compute_cs();
let dxil = super::compute_split(&decode(lines), &cs).unwrap_or_else(|e| panic!("{e}"));
if dxc::location().is_err() {
return runner::skip_test("no DXC");
}
let text = crate::gpu::dxil::validate::disassemble(&dxil).unwrap();
let barriers = text.lines().filter(|l| l.contains("call void @dx.op.barrier")).count();
// the one where the halves take their console lanes, at the start (every lane is there)
assert_eq!(barriers, 1, "group barriers in the program:\n{text}");
if !gpu() {
return;
}
let mem = vec![0u32; 256];
let gpu = runner::dispatch(&dxil, [2, 1, 1], &[100, 0], &mem).unwrap();
// the console's v7 (the CPU `Interp` has no #1426 bridge): 5 in lanes 1–31, else 0
for g in 0..2 {
for l in 0..64 {
assert_eq!(gpu[g * 128 + l], if (1..32).contains(&l) { 5 } else { 0 }, "group {g}, lane {l}");
}
}
}
}
Loading