diff --git a/crates/xcl/src/gpu/dxil/core_tests.rs b/crates/xcl/src/gpu/dxil/core_tests.rs index e1421c69bc..a97caf268f 100644 --- a/crates/xcl/src/gpu/dxil/core_tests.rs +++ b/crates/xcl/src/gpu/dxil/core_tests.rs @@ -25,7 +25,7 @@ fn a_single_split_wave_of_a_compute_group_exchanges_without_a_group_barrier() { let code = prog(&[("V_READLANE_B32", "ENC_VOP3", &[("VDST", 1), ("SRC0", 256), ("SRC1", 160)], None)]); let o = KernelOptions { wave64: true, split: true, mem_windows: 1, sampler_base: 0 }; let dis = |threads: u32, code: &[u8]| { - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; super::validate::disassemble(&super::kernel::translate_compute(code, o, &cs).unwrap_or_else(|e| panic!("{threads} threads: {e}")).dxil) }; // (barrier mode 9: the thread group's sync with its memory fence, `ops::barrier::GROUP_SYNC`) @@ -152,7 +152,7 @@ fn split_lds_reads_meet_after_writes() { assert!(looped(&[read, write]) >= looped(&[read]) + 2, "the loop's read and write meet when the bits are set"); // compute groups: the counters' meet (two more atomics), none without a partner half let atomics = |threads: u32, list: &[Inst]| { - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let o = KernelOptions { wave64: true, split: true, mem_windows: 1, sampler_base: 0 }; let d = super::validate::disassemble(&super::kernel::translate_compute(&prog(list), o, &cs).unwrap_or_else(|e| panic!("{threads} threads: {e}")).dxil).unwrap(); d.matches("atomicrmw").count() @@ -1089,7 +1089,7 @@ fn count_phis(dis: &str, cap: &str, b: &str) -> Vec { #[test] fn direct_compute_loops_count_each_entry() { use crate::gpu::recomp::CsInterface; - let cs = CsInterface { threads: [8, 4, 2], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [8, 4, 2], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let straight = prog(&[ ("V_MOV_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", 2)], None), ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 6), ("SRC0", 130), ("VSRC1", 0)], None), @@ -1162,7 +1162,7 @@ fn the_compute_entry_lets_only_the_lanes_below_the_thread_limits_in() { let load = format!("i32 {}, i32 undef, i8 7, i32 4)", IO_THREAD_LIMIT[0] * 4); for (wave64, split, threads) in [(false, false, 32), (true, false, 64), (true, true, 64), (true, true, 32)] { let o = KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; // (a split wave64 of 64 threads is two hardware waves: its barrier is the HLSL path's) for barrier in [false, true].into_iter().filter(|&b| !(b && split && threads == 64)) { let what = format!("wave64 {wave64}, split {split}, {threads} threads, barrier {barrier}"); @@ -1238,7 +1238,7 @@ fn gpu_direct_compute_loop_passes_follow_the_dispatch() { Err(e) => return runner::skip_test(&e), } let threads = 64u32; - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; for wave64 in [false, true] { let o = KernelOptions { wave64, split: wave64, mem_windows: 1, sampler_base: 0 }; let run = |code: &[u8], slot: u32| -> u32 { @@ -1367,7 +1367,7 @@ fn compute_movrel_uses_program_max_vgpr_and_masks_m0() { // stored, so DCE keeps the relative move this test looks at ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 1), ("DATA", 0), ("SADDR", 0x7D), ("OFFSET", 0)], None), ]); - let cs = CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let k = super::kernel::translate_compute(&code, ko, &cs).expect("compute movrel translates"); super::validate::validate(&k.dxil).expect("validates"); if let Ok(dis) = super::validate::disassemble(&k.dxil) { @@ -1380,7 +1380,7 @@ fn compute_movrel_uses_program_max_vgpr_and_masks_m0() { fn compute_omits_rodata_without_s_getpc() { use super::kernel::{translate_entry_rodata, Entry}; use crate::gpu::recomp::CsInterface; - let cs = CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let ko = KernelOptions { wave64: false, split: false, mem_windows: 2, sampler_base: 0 }; let rodata = vec![(0x40u32, vec![0x7AB1_E000u32, 0x7AB1_E001, 0xBF81_0000])]; @@ -1649,3 +1649,113 @@ fn raw_buffer_oob_check_guards_32bit_wraparound() { assert!(uge >= 4, "expected wraparound icmp uge checks for load and atomic (got {uge}):\n{dis}"); } } + +/// `f` with `XCL_DECLARED_LDS` taken as `on` by the translations of this thread. +fn with_declared_lds(on: bool, f: impl FnOnce() -> R) -> R { + let before = super::kernel::DECLARED_LDS_FOR_TEST.with(|c| c.replace(Some(on))); + let r = f(); + super::kernel::DECLARED_LDS_FOR_TEST.with(|c| c.set(before)); + r +} + +/// `XCL_DECLARED_LDS` (on by default): a compute program's groupshared block is the LDS its +/// header declares (COMPUTE_PGM_RSRC2 LDS_SIZE, 128-dword granules) and the translator's words +/// after it – a native 2-D group's arrival counter, a multi-wave barrier's two words, the split +/// form's exchange slots and counters – or the whole 8,192 dwords when the header gives no size +/// or those words would not fit. Off: always 8,192. +#[test] +fn compute_lds_is_the_declared_block_and_the_translators_words() { + use crate::gpu::recomp::CsInterface; + let write = prog(&[("DS_WRITE_B32", "ENC_DS", &[("ADDR", 0), ("DATA0", 1)], None)]); + let barrier = prog(&[("DS_WRITE_B32", "ENC_DS", &[("ADDR", 0), ("DATA0", 1)], None), ("S_BARRIER", "ENC_SOPP", &[], None)]); + let bar = if crate::gpu::recomp::emit::safe_barrier_wanted() { 2 } else { 0 }; + // (threads, granules, wave64, split, program, words with the switch) + let cases: [([u32; 3], u32, bool, bool, &[u8], u32); 14] = [ + ([64, 1, 1], 2, false, false, &write, 256), + ([8, 8, 1], 1, false, false, &write, 129), + ([8, 8, 1], 1, false, false, &barrier, 129 + bar), + ([64, 1, 1], 2, false, false, &barrier, 256 + bar), + // native wave64: one wave has no barrier words, two have + ([64, 1, 1], 1, true, false, &barrier, 128), + ([128, 1, 1], 2, true, false, &barrier, 256 + bar), + ([16, 8, 1], 1, true, false, &barrier, 129 + bar), + // split: slots 4 · waves, counters 2 · waves, the arrival word (and the barrier's two) + ([8, 8, 1], 1, true, true, &write, 135), + ([128, 1, 1], 2, true, true, &write, 269), + ([128, 1, 1], 2, true, true, &barrier, 269 + bar), + // no size, or no room for the translator's words: the whole block + ([8, 8, 1], 0, true, true, &write, 8192), + ([8, 8, 1], 0, false, false, &barrier, 8192), + ([8, 8, 1], 64, true, true, &write, 8192), + ([8, 8, 1], 64, false, false, &write, 8192), + ]; + for (threads, granules, wave64, split, code, words) in cases { + // the size comes from the stage descriptor (COMPUTE_PGM_RSRC2 at +0x38, LDS_SIZE at bit 15) + let mut descriptor = [0u8; 0x48]; + for (i, v) in [granules << 15 | 1 << 11, threads[0], threads[1], threads[2]].into_iter().enumerate() { + descriptor[0x38 + 4 * i..0x3C + 4 * i].copy_from_slice(&v.to_le_bytes()); + } + let cs = CsInterface::from_descriptor(&descriptor, 0).unwrap(); + assert_eq!(cs.lds_dwords, granules * 128); + let o = KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; + for on in [false, true] { + let what = format!("{threads:?}, {granules} granules, wave64 {wave64}, split {split}, switch {on}"); + let k = with_declared_lds(on, || super::kernel::translate_compute(code, o, &cs)).unwrap_or_else(|e| panic!("{what}: {e}")); + super::validate::validate(&k.dxil).unwrap_or_else(|e| panic!("{what}: {e}")); + let dis = super::validate::disassemble(&k.dxil).unwrap(); + let want = if on { words } else { 8192 }; + assert!(dis.contains(&format!("@xcl_lds = external addrspace(3) global [{want} x i32]")), "{what}: {want} words"); + } + } +} + +/// The declared block on the GPU (`XCL_DECLARED_LDS`), with the switch on and off: a 16 x 8 +/// group (several hardware waves: a native 2-D group's arrival counter and the safe barrier's +/// words after its 256 dwords, or the split form's exchange words) whose threads first write +/// past the declared LDS (kept at its last dword, not over the translator's words: the clamp +/// itself is `declared_lds_accesses_stop_below_the_translators_words`'s), then their index, +/// meet at a group barrier and read another thread's. Native wave32, native wave64 (on a GPU +/// that runs it) and the split wave64 form. +#[test] +fn gpu_compute_declared_lds_keeps_the_translators_words() { + use crate::gpu::recomp::{runner, CsInterface, KERNEL_SGPRS}; + match runner::wave32_supported() { + Ok(true) => {} + Ok(false) => return runner::skip_test("no wave32"), + Err(e) => return runner::skip_test(&e), + } + const V: u64 = 256; + let code = prog(&[ + ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 2), ("SRC0", 132), ("VSRC1", 1)], None), // y · 16 + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 2), ("SRC0", V + 2), ("VSRC1", 0)], None), // i + ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 3), ("SRC0", 130), ("VSRC1", 2)], None), // 4i + // dword 256 + i: past the declared 256 (unclamped, over the translator's words) + ("DS_WRITE_B32", "ENC_DS", &[("ADDR", 3), ("DATA0", 3), ("OFFSET1", 4)], None), + ("DS_WRITE_B32", "ENC_DS", &[("ADDR", 3), ("DATA0", 2)], None), + ("S_WAITCNT", "ENC_SOPP", &[("SIMM16", 0)], None), + ("S_BARRIER", "ENC_SOPP", &[], None), + ("V_SUB_NC_U32", "ENC_VOP2", &[("VDST", 4), ("SRC0", 255), ("VSRC1", 2)], Some(127)), // 127 - i + ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 5), ("SRC0", 130), ("VSRC1", 4)], None), + ("DS_READ_B32", "ENC_DS", &[("VDST", 6), ("ADDR", 5)], None), + ("S_WAITCNT", "ENC_SOPP", &[("SIMM16", 0)], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 8), ("SRC0", V + 3)], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 9), ("SRC0", 128)], None), + ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 6), ("SADDR", 0x7D)], None), + ]); + let cs = CsInterface { threads: [16, 8, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 2, lds_dwords: 256 }; + let native64 = runner::wave64_supported() == Ok(true); + for (wave64, split) in [(false, false), (true, false), (true, true)].into_iter().filter(|&(w, s)| !w || s || native64) { + let o = KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; + for on in [false, true] { + let what = format!("wave64 {wave64}, split {split}, switch {on}"); + let k = with_declared_lds(on, || super::kernel::translate_compute(&code, o, &cs)).unwrap_or_else(|e| panic!("{what}: {e}")); + let mem = runner::dispatch(&k.dxil, [1, 1, 1], &vec![0u32; KERNEL_SGPRS], &vec![0xFFFF_FFFFu32; 128]).expect("GPU run"); + for i in 0..128 { + assert_eq!(mem[i], 127 - i as u32, "{what}: thread {i}"); + } + } + } + if !native64 { + runner::skip_test("no wave64"); + } +} diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index f57cf8d7c0..a9557c2ea5 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -40,6 +40,26 @@ pub struct KernelOptions { /// (the `gpu/dxil` sources are not in build.rs's translator source hash). pub const TRANSLATOR_VERSION: u32 = 12; +/// `XCL_DECLARED_LDS` (default on; `=0` off): a compute program's groupshared block is the LDS +/// its header declares (`CsInterface::lds_dwords`) plus the translator's own words after it, +/// instead of the whole 8,192 dwords D3D12 allows (still so when the header gives no size). A +/// one-wave group holding 32 KB let an RDNA WGP (128 KB) run 4 groups: one wave a SIMD. The +/// caches and `ComputePolicyKey` key it apart. (After xcl-dev/xcl#2937, Kalmarv, there opt-in.) +pub fn declared_lds_enabled() -> bool { + #[cfg(test)] + if let Some(on) = DECLARED_LDS_FOR_TEST.with(|c| c.get()) { + return on; + } + static ON: std::sync::OnceLock = std::sync::OnceLock::new(); + *ON.get_or_init(|| std::env::var("XCL_DECLARED_LDS").map_or(true, |v| v.trim() != "0")) +} + +#[cfg(test)] +thread_local! { + /// `declared_lds_enabled` for the translations of this test thread + pub(crate) static DECLARED_LDS_FOR_TEST: std::cell::Cell> = const { std::cell::Cell::new(None) }; +} + /// Console compute shaders (and the kernel tests) go through this translator, with the HLSL /// path as the fallback for what it cannot translate yet: the default, and `XCL_DIRECT_DXIL=1`. /// `XCL_DIRECT_DXIL=0` keeps every stage on the HLSL path. @@ -252,12 +272,16 @@ fn translate_entry_with( let code = code.to_vec(); #[cfg(test)] let no_select_fold = super::module::NO_SELECT_FOLD.with(|c| c.get()); + #[cfg(test)] + let declared_lds = DECLARED_LDS_FOR_TEST.with(|c| c.get()); std::thread::Builder::new() .name("xcl-dxil-translate".into()) .stack_size(256 << 20) .spawn(move || { #[cfg(test)] super::module::NO_SELECT_FOLD.with(|c| c.set(no_select_fold)); + #[cfg(test)] + DECLARED_LDS_FOR_TEST.with(|c| c.set(declared_lds)); translate_on_this_thread(&code, o, entry, compact, nest, rodata, ps_rt32_mask) }) .map_err(|e| format!("translator thread: {e}"))? @@ -829,7 +853,13 @@ impl Lw { let safe_bar = lw.barrier_waves.is_some_and(|w| w > 1) && has_s_barrier && crate::gpu::recomp::emit::safe_barrier_wanted(); - lw.setup_storage(uses_lds, if split { slot } else { 1 }, safe_bar); + // `XCL_DECLARED_LDS`: the program's own LDS, then the translator's words; a native 2-D + // / 3-D group's arrival counter (`setup_lanes_compute`) is one of them + let (declared, native_counter) = match entry { + Entry::Compute(cs) if declared_lds_enabled() => (cs.lds_dwords, !split && (cs.threads[1] > 1 || cs.threads[2] > 1)), + _ => (0, false), + }; + lw.setup_storage(uses_lds, if split { slot } else { 1 }, safe_bar, declared, native_counter); lw } @@ -984,7 +1014,7 @@ fn a_split_wave64_compute_program_stays_whole() { fn a_dispatch_chain_leaves_the_lanes_past_a_thread_limit_out() { use crate::gpu::recomp::{runner, IO_THREAD_LIMIT}; let threads = [32, 1, 1]; - let cs = CsInterface { threads, user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads, user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let options = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 }; let mut lw = Lw::new(&[], &Default::default(), options, &Entry::Compute(cs.clone())); let (tid, gtid) = lw.setup_lanes_compute(threads, false); @@ -1492,7 +1522,7 @@ fn gpu_compact_slots_use_the_dispatch_prologues_exec_mask() { ] { code.extend(encode(name, enc, fields, None).unwrap()); } - let cs = CsInterface { threads: [32, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [32, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let options = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 }; let kernel = translate_entry(&code, options, Entry::Compute(cs), Some(true), None).unwrap(); let initial = [0xa5a5_5a5a; 32]; diff --git a/crates/xcl/src/gpu/dxil/lanes.rs b/crates/xcl/src/gpu/dxil/lanes.rs index 5746adaa95..c372b8e9fc 100644 --- a/crates/xcl/src/gpu/dxil/lanes.rs +++ b/crates/xcl/src/gpu/dxil/lanes.rs @@ -21,28 +21,43 @@ impl Lw { /// the program's LDS (`lds_words` > 0), multi-wave safe-barrier counters /// (`safe_bar`, 2 words), and, in the split form, the halves' exchange /// words — in the top of the LDS block when there is one (D3D12 allows - /// 32 KB, the whole LDS), as the HLSL kernel lays it out. - pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool) { + /// 32 KB, the whole LDS), as the HLSL kernel lays it out. With `declared` + /// dwords (`XCL_DECLARED_LDS`, 0 = not known) the block is the program's + /// LDS followed by those words (and a native 2-D / 3-D group's arrival + /// counter, `native_counter`), when they fit in 8,192. + pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool, declared: u32, native_counter: bool) { let i32 = self.s.m.i32(); self.xslot = slot.max(1); if lds { - let g = self.s.groupshared("xcl_lds", i32, 8192); + // the translator's words at the top: [exchange slots, counters (split)], + // [XCL_BAR_ALIVE, XCL_BAR_STATE (safe_bar)], XCL_XW / XCL_WT + let bar_words = if safe_bar { 2 } else { 0 }; + let slots = 4 * self.xslot * self.waves; + let control = if self.split { slots + 2 * self.waves + 1 + bar_words } else { bar_words + u32::from(native_counter) }; + let fits = declared != 0 && declared <= 8192u32.saturating_sub(control); + let words = if fits { declared + control } else { 8192 }; + let g = self.s.groupshared("xcl_lds", i32, words as u64); self.lds = Some(g); if safe_bar { // Words 8189 = XCL_BAR_ALIVE, 8190 = XCL_BAR_STATE (8191 = XCL_XW / XCL_WT), - // matching `recomp::emit::safe_barrier_prelude`. - self.safe_bar = Some((g, 8189)); + // matching `recomp::emit::safe_barrier_prelude`; with the declared LDS of a + // native group right after the program's + self.safe_bar = Some((g, if fits && !self.split { declared } else { words - 3 })); } if self.split { // HLSL: exchange base = 8192 - slots - counters - 1 (- 2 if safe_bar) // (slots = 4 · slot per console wave, 2 counters each); program LDS stops below it. - let bar_words = if safe_bar { 2 } else { 0 }; - let slots = 4 * self.xslot * self.waves; - let base = 8192 - slots - 2 * self.waves - 1 - bar_words; + let base = words - control; self.lds_top = base - 1; self.xs = Some((g, base)); self.xc = Some((g, base + slots)); - self.xw = Some((g, 8191)); + self.xw = Some((g, words - 1)); + } else if fits { + // `lds_index` clamps below the translator's words (`lds_top` < 8191) + self.lds_top = declared - 1; + if native_counter { + self.xw = Some((g, words - 1)); + } } else { self.lds_top = if safe_bar { 8188 } else { 8191 }; } @@ -133,7 +148,7 @@ impl Lw { } else if y * z > 1 { let i32 = self.s.m.i32(); let (g, at) = match (self.lds, lds_top_word) { - (Some(l), true) => (l, 8191), + (Some(l), true) => self.xw.unwrap_or((l, 8191)), _ => (self.s.groupshared("xcl_wt", i32, 1), 0), }; let ai = self.c(at); diff --git a/crates/xcl/src/gpu/dxil/lower.rs b/crates/xcl/src/gpu/dxil/lower.rs index 07220732d1..5a418c24ce 100644 --- a/crates/xcl/src/gpu/dxil/lower.rs +++ b/crates/xcl/src/gpu/dxil/lower.rs @@ -324,7 +324,8 @@ pub struct Lw { pub live_exec: Option<(Value, Value)>, /// words per half in an exchange pub xslot: u32, - /// the program's LDS (`xcl_lds`, 8192 dwords) and its last usable dword + /// the program's LDS (`xcl_lds`, 8192 dwords or the declared ones and the translator's + /// words, `Lw::setup_storage`) and its last usable dword pub lds: Option, pub lds_top: u32, /// DPP write enable of the instruction being lowered diff --git a/crates/xcl/src/gpu/dxil/lower_mem.rs b/crates/xcl/src/gpu/dxil/lower_mem.rs index dbe002c217..1dc78f49b6 100644 --- a/crates/xcl/src/gpu/dxil/lower_mem.rs +++ b/crates/xcl/src/gpu/dxil/lower_mem.rs @@ -2806,7 +2806,7 @@ mod stage_guard_tests { } fn cs_iface() -> CsInterface { - CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1 } + CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() } } fn gs_iface(gs_start: Option) -> GsInterface { diff --git a/crates/xcl/src/gpu/dxil/robustness_tests.rs b/crates/xcl/src/gpu/dxil/robustness_tests.rs index 9a82e67cae..be4aec8b0e 100644 --- a/crates/xcl/src/gpu/dxil/robustness_tests.rs +++ b/crates/xcl/src/gpu/dxil/robustness_tests.rs @@ -69,7 +69,7 @@ fn translate_all() -> Vec> { input_ena: 0x302, attrs: None, }; - let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let o = |wave64, split| KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; let mut out = Vec::new(); for (w, s) in [(false, false), (true, true), (true, false)] { @@ -107,7 +107,7 @@ fn a_group_barrier_of_several_hardware_waves_uses_safe_barrier_directly() { } let code = prog(&[("S_BARRIER", "ENC_SOPP", &[], None)]); let o = |wave64, split| KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; - let cs = |threads| CsInterface { threads, user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = |threads| CsInterface { threads, user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; // 16 x 16 threads: 8 hardware waves in the split form, 4 native 64-lane ones, 8 of a // 32-lane program; and the two 32-lane halves of one console wave for (wave64, split, threads) in [(true, true, [16, 16, 1]), (true, false, [16, 16, 1]), (false, false, [16, 16, 1]), (true, true, [64, 1, 1])] { @@ -152,6 +152,46 @@ fn a_group_barrier_of_several_hardware_waves_uses_safe_barrier_directly() { } } +/// With the declared LDS (`XCL_DECLARED_LDS`, on by default) a program's LDS accesses stop at +/// the last dword it declares, and the translator's words after it each have their own: a +/// native 2-D group's safe-barrier words and arrival counter, the split form's exchange slots, +/// counters, barrier words and arrival word, all inside the block. +#[test] +fn declared_lds_accesses_stop_below_the_translators_words() { + let before = kernel::DECLARED_LDS_FOR_TEST.with(|c| c.replace(Some(true))); + // the address is v0, the thread ID (up to 255: past the declared 128 dwords) + let code = prog(&[ + ("DS_WRITE_B32", "ENC_DS", &[("ADDR", 0), ("DATA0", 0)], None), + ("S_BARRIER", "ENC_SOPP", &[], None), + ("DS_READ_B32", "ENC_DS", &[("VDST", 2), ("ADDR", 0)], None), + ]); + let cs = CsInterface { threads: [16, 16, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1, lds_dwords: 128 }; + let bar = crate::gpu::recomp::emit::safe_barrier_wanted(); + let b = if bar { 2 } else { 0 }; + // (wave64, split, block, the translator's words); split: 4 console waves, 16 slots + for (wave64, split, words, own) in [ + (false, false, 128 + b + 1, if bar { vec![128, 129, 130] } else { vec![128] }), + (true, false, 128 + b + 1, if bar { vec![128, 129, 130] } else { vec![128] }), + (true, true, 128 + 16 + 8 + b + 1, (128..128 + 16 + 8 + b + 1).collect::>()), + ] { + let what = format!("wave64 {wave64}, split {split}"); + let o = KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; + let k = kernel::translate_compute(&code, o, &cs).unwrap_or_else(|e| panic!("{what}: {e}")); + let dis = super::validate::disassemble(&k.dxil).expect("disassemble"); + assert!(dis.contains(&format!("@xcl_lds = external addrspace(3) global [{words} x i32]")), "{what}: {words} words:\n{dis}"); + assert!(!dis.contains("@xcl_bar") && !dis.contains("@xcl_wt") && !dis.contains("@xcl_xw"), "{what}: the translator's words outside the block:\n{dis}"); + let clamps = dis.lines().filter(|l| l.contains("@dx.op.binary.i32(i32 40,") && l.contains(", i32 127)")).count(); + assert!(clamps > 0, "{what}: LDS indices not clamped to 127:\n{dis}"); + assert!(!dis.contains("i32 8191) ; UMin") && !dis.contains("i32 8188) ; UMin"), "{what}: a clamp to the whole block:\n{dis}"); + let at = |i: u32| format!("[{words} x i32] addrspace(3)* @xcl_lds, i32 0, i32 {i}"); + // (the split form's slots and counters are indexed by wave: their constant words only) + for i in own.iter().filter(|&&i| !split || i >= 128 + 16 + 8) { + assert!(dis.contains(&at(*i)), "{what}: no word {i}:\n{dis}"); + } + } + kernel::DECLARED_LDS_FOR_TEST.with(|c| c.set(before)); +} + /// The translator's own variables after the loop budget each have a slot of their own (the /// multi-wave barrier's once shared `VAR_F32_MODE`'s), below the image-store slots. #[test] @@ -206,7 +246,7 @@ fn gpu_a_multi_wave_barrier_after_the_f32_mode_is_set_to_zero_still_waits() { ("S_ROUND_MODE", "ENC_SOPP", &[("SIMM16", 1)], None), ]); let threads = 128u32; - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; for (wave64, split) in [(false, false), (true, true)] { let o = KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; let k = kernel::translate_compute(&code, o, &cs).unwrap_or_else(|e| panic!("wave64 {wave64}: {e}")); @@ -221,7 +261,7 @@ fn gpu_a_multi_wave_barrier_after_the_f32_mode_is_set_to_zero_still_waits() { fn split_wave64_real_lds_is_left_to_the_hlsl_path() { let write = prog(&[("DS_WRITE_B32", "ENC_DS", &[("ADDR", 0), ("DATA0", 1)], None)]); let swizzle = prog(&[("DS_SWIZZLE_B32", "ENC_DS", &[("VDST", 1), ("ADDR", 0), ("OFFSET0", 0x1F), ("OFFSET1", 4)], None)]); - let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let o = |wave64, split| KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 }; // the direct translator orders split LDS itself (`XCL_X_LDS_ORDER`, on by default); without @@ -242,7 +282,7 @@ fn split_wave64_real_lds_is_left_to_the_hlsl_path() { fn split_wave64_spin_uses_fail_closed_direct_dxil() { const V: u64 = 256; let code = prog(&[("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", V)], None)]); - let cs = CsInterface { threads: [128, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [128, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let options = |split| KernelOptions { wave64: true, split, mem_windows: 1, sampler_base: 0 }; kernel::translate_compute(&code, options(true), &cs).expect("counter-paired direct DXIL translation"); kernel::translate_compute(&code, options(false), &cs).expect("native wave64 translation"); diff --git a/crates/xcl/src/gpu/recomp/link_tests.rs b/crates/xcl/src/gpu/recomp/link_tests.rs index b2e99dfab9..c28b6acf4f 100644 --- a/crates/xcl/src/gpu/recomp/link_tests.rs +++ b/crates/xcl/src/gpu/recomp/link_tests.rs @@ -162,7 +162,7 @@ fn bench_memory_window_accessors() { for round in 0..3 { for windows in [1, 4] { nonce = nonce.wrapping_mul(0x9E37_79B1) | 1; - let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 24, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 24, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let t = translate(&program(n, nonce), &on_gpu(Options { mode: Mode::Compute(cs), wave64: true, mem_windows: windows, ..Default::default() })).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); let forms = if windows == 1 { @@ -212,7 +212,7 @@ fn linked_programs_keep_their_declarations() { let list = [buf("BUFFER_LOAD_DWORD", 2, coherent), buf("BUFFER_STORE_DWORD", 3, false)]; let refs: Vec<(&str, &str, &[(&str, u64)], Option)> = list.iter().map(|(a, b, c, d)| (*a, *b, c.as_slice(), *d)).collect(); let p = prog(&refs); - let cs = super::CsInterface { threads: [8, 4, 2], user_sgprs: 16, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [8, 4, 2], user_sgprs: 16, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let t = translate(&p, &Options { mode: Mode::Compute(cs), wave64, mem_windows: 4, ..Default::default() }).unwrap(); let size = if wave64 { 64 } else { 32 }; assert!(t.hlsl.contains(&format!("[WaveSize({size})]")), "{}", t.hlsl); diff --git a/crates/xcl/src/gpu/recomp/lower.rs b/crates/xcl/src/gpu/recomp/lower.rs index ec891719a5..2a28c46122 100644 --- a/crates/xcl/src/gpu/recomp/lower.rs +++ b/crates/xcl/src/gpu/recomp/lower.rs @@ -3269,7 +3269,7 @@ pub(crate) mod tests { } pub(crate) fn compute_cs() -> crate::gpu::recomp::CsInterface { - crate::gpu::recomp::CsInterface { threads: [64, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1 } + crate::gpu::recomp::CsInterface { threads: [64, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() } } /// A compute program run on the CPU over `groups` groups (wave32): the memory after. @@ -3341,7 +3341,7 @@ pub(crate) mod tests { } mem }; - let cs = |threads: [u32; 3], y: bool| CsInterface { threads, user_sgprs: 2, tgid: [true, y, false], tg_size: false, tid_components: if y { 2 } else { 1 } }; + let cs = |threads: [u32; 3], y: bool| CsInterface { threads, user_sgprs: 2, tgid: [true, y, false], tg_size: false, tid_components: if y { 2 } else { 1 }, ..Default::default() }; let limit = |x: u32, y: u32| vec![(IO_THREAD_LIMIT[0], x), (IO_THREAD_LIMIT[1], y)]; for wave64 in [false, true] { let lanes = if wave64 { 64 } else { 32 }; diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index 76bb83c1db..b011fdd8d6 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -467,6 +467,9 @@ pub struct CsInterface { pub tg_size: bool, /// thread id VGPRs: 1 (v0), 2 (v0, v1) or 3 (v0..v2) pub tid_components: u32, + /// the group's LDS from COMPUTE_PGM_RSRC2 (LDS_SIZE, 128-dword granules), in dwords; 0 = not + /// given (`gpu::dxil::kernel::declared_lds_enabled`) + pub lds_dwords: u32, } impl CsInterface { @@ -488,6 +491,7 @@ impl CsInterface { tgid: [(r >> 7) & 1 == 1, (r >> 8) & 1 == 1, (r >> 9) & 1 == 1], tg_size: (r >> 10) & 1 == 1, tid_components: ((r >> 11) & 3) + 1, + lds_dwords: ((r >> 15) & 0x1FF) * 128, } } } diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index f4a3b95d8c..3ab550d0e4 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -42,6 +42,7 @@ pub(crate) struct ComputePolicyKey { pub direct_compact: Option, pub direct_compact_nest: Option, pub direct_piece_limit: usize, + pub declared_lds: bool, pub per_lane: bool, pub disabled_dxil_optimizations: u8, } @@ -63,6 +64,7 @@ pub(crate) fn compute_policy_key() -> ComputePolicyKey { direct_compact: crate::gpu::dxil::kernel::compact_mode(), direct_compact_nest: crate::gpu::dxil::kernel::compact_nest_tag(), direct_piece_limit: crate::gpu::dxil::kernel::dispatch_piece_limit(), + declared_lds: crate::gpu::dxil::kernel::declared_lds_enabled(), per_lane: crate::gpu::recomp::lower_dxil::enabled(), disabled_dxil_optimizations: ["phi", "cse", "dce", "merge"] .iter() @@ -383,6 +385,10 @@ mod translated { let id = if Backend::current() != Backend::Hlsl { identity_for(&id.to_string(), &format!("dispatch-split-{}", crate::gpu::dxil::kernel::dispatch_piece_limit())) } else { id }; + // `XCL_DECLARED_LDS=0`: direct compute programs' groupshared blocks of 8,192 dwords + let id = if Backend::current() != Backend::Hlsl && !crate::gpu::dxil::kernel::declared_lds_enabled() { + identity_for(&id.to_string(), "xcl-declared-lds-0") + } else { id }; // `XCL_X_LDS_ORDER=0`: the split wave64 form without its LDS order, in both translators let id = if crate::gpu::recomp::emit::lds_order_wanted() { id } else { identity_for(&id.to_string(), "xcl-x-lds-order-0") }; // `XCL_PER_LANE=1` (direct compute only): its entries under their own identity @@ -691,6 +697,7 @@ mod translated { None => id, }; let id = identity_for(&id.to_string(), &format!("dispatch-split-{split_limit}")); + let id = if crate::gpu::dxil::kernel::declared_lds_enabled() { id } else { identity_for(&id.to_string(), "xcl-declared-lds-0") }; if crate::gpu::recomp::lower_dxil::enabled() { identity_for(&id.to_string(), concat!("xcl-per-lane-", env!("XCL_PER_LANE_SOURCE_ID"))) } else { @@ -2267,6 +2274,33 @@ mod shader_cache_tests { assert_eq!(id(Backend::Hlsl, 7, built), id(Backend::Hlsl, 8, "edited")); } + /// `XCL_DECLARED_LDS=0` translations are other entries of the direct translator's caches + /// (the routed one and the one of the HLSL path's enormous programs) and another compute + /// policy for the driver's pipeline cache. + #[test] + fn declared_lds_is_another_direct_output() { + let with = |on, f: &dyn Fn() -> u64| { + let before = crate::gpu::dxil::kernel::DECLARED_LDS_FOR_TEST.with(|c| c.replace(Some(on))); + let id = f(); + crate::gpu::dxil::kernel::DECLARED_LDS_FOR_TEST.with(|c| c.set(before)); + id + }; + let direct = || translated::direct_output_identity(None, 1); + assert_ne!(with(false, &direct), with(true, &direct)); + assert_eq!(with(true, &direct), with(true, &direct)); + if translated::Backend::current() != translated::Backend::Hlsl && std::env::var("XCL_TRANSLATED_CACHE").map_or(true, |v| v != "0") { + let routed = || translated::identity_from_source("s"); + assert_ne!(with(false, &routed), with(true, &routed)); + } + let policy = |on| { + let before = crate::gpu::dxil::kernel::DECLARED_LDS_FOR_TEST.with(|c| c.replace(Some(on))); + let p = compute_policy_key(); + crate::gpu::dxil::kernel::DECLARED_LDS_FOR_TEST.with(|c| c.set(before)); + p + }; + assert_ne!(policy(false), policy(true)); + } + #[test] fn huge_direct_threshold_from_env() { assert_eq!(huge_direct_min_from(None), Some(HUGE_DIRECT_MIN_DEFAULT)); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 6777b5a967..27d8962d82 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -3652,7 +3652,7 @@ fn gpu_static_samplers_from_constants_in_code() { ("GLOBAL_STORE_DWORDX2", "ENC_FLAT_GLBL", vec![("ADDR", 8), ("DATA", 10), ("SADDR", 0x7D)], None), ]); let refs: Vec<_> = compute.iter().map(|(n, e, fields, literal)| (*n, *e, fields.as_slice(), *literal)).collect(); - let cs = super::CsInterface { threads: [32, 1, 1], user_sgprs: 24, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [32, 1, 1], user_sgprs: 24, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let options = crate::gpu::dxil::kernel::KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 }; let translated = crate::gpu::dxil::kernel::translate_compute(&prog(&refs), options, &cs).unwrap(); assert_eq!(translated.static_samplers, [(point, false), (linear, false)]); @@ -6204,7 +6204,7 @@ fn gpu_compute_mode_dispatch_abi() { return; } use super::{dxc, CsInterface}; - let cs = CsInterface { threads: [16, 8, 1], user_sgprs: 2, tgid: [true, true, false], tg_size: false, tid_components: 2 }; + let cs = CsInterface { threads: [16, 8, 1], user_sgprs: 2, tgid: [true, true, false], tg_size: false, tid_components: 2, ..Default::default() }; let p = prog(&[ ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 2), ("SRC0", 132), ("VSRC1", 1)], None), // y · 16 ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 2), ("SRC0", V + 2), ("VSRC1", 0)], None), // index in group @@ -8387,7 +8387,7 @@ fn split_wave64_meet_form_by_group_size() { let lane = prog(&[("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", V)], None)]); for dims in [[64u32, 1, 1], [8, 8, 1], [4, 4, 4], [40, 1, 1], [256, 1, 1], [8, 8, 4]] { let threads = dims.iter().product::(); - let cs = CsInterface { threads: dims, user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: dims, user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let t = translate(&lane, &Options { mode: Mode::Compute(cs), wave64: true, split_wave64: true, no_remap: true, ..Default::default() }).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); assert!(t.hlsl.contains(&format!("#define XCL_X_THREADS {threads}u")), "{dims:?}"); @@ -8395,14 +8395,14 @@ fn split_wave64_meet_form_by_group_size() { assert!(t.hlsl.contains(&format!("#define XCL_X_SPIN {}\n", want as u8)), "{dims:?}"); } // A half without a partner (32 threads or fewer: `xcl_xn == 0`) leaves before either form. - let t = translate(&lane, &Options { mode: Mode::Compute(CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }), wave64: true, split_wave64: true, ..Default::default() }).unwrap(); + let t = translate(&lane, &Options { mode: Mode::Compute(CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }), wave64: true, split_wave64: true, ..Default::default() }).unwrap(); let meet = &t.hlsl[t.hlsl.find("bool xcl_x_meet()").unwrap()..]; let (leave, spin, barrier) = (meet.find("if (xcl_xn == 0u) return false;").unwrap(), meet.find("#if XCL_X_SPIN").unwrap(), meet.find("GroupMemoryBarrierWithGroupSync();").unwrap()); assert!(leave < spin && spin < barrier); // A multi-wave production entry checks both its initial EXEC exchange and an // instruction exchange before any following instruction can consume the timeout value. - let cs = CsInterface { threads: [128, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [128, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let split = translate(&lane, &Options { mode: Mode::Compute(cs.clone()), wave64: true, split_wave64: true, no_remap: true, ..Default::default() }).unwrap(); assert!(split.hlsl.contains("static const uint XCL_X_FAIL = 0x80000000u;")); assert!(split.hlsl.contains("((o | (o + lanes) | need) & XCL_X_FAIL) != 0u")); @@ -8484,7 +8484,7 @@ fn split_wave64_lds_reads_meet_after_writes() { } // a compute group of several console waves (the counters' meet) and one of a single half for threads in [128u32, 32] { - let cs = super::CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let h = hlsl(&[write, read], &Options { mode: Mode::Compute(cs), ..split.clone() }); assert!(h.contains(AFTER_WRITE) && h.contains(WROTE), "{threads} threads"); } @@ -8887,7 +8887,7 @@ fn gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves() { ]); for dims in [[256u32, 1, 1], [8, 8, 4]] { let threads = dims.iter().product::(); - let cs = CsInterface { threads: dims, user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 3 }; + let cs = CsInterface { threads: dims, user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 3, ..Default::default() }; let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() }); let t = translate(&p, &opt).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); @@ -8967,7 +8967,7 @@ fn gpu_split_wave64_waves_diverge() { ]); for dims in [[256u32, 1, 1], [64, 1, 1], [8, 8, 4], [16, 4, 1]] { let threads = dims.iter().product::(); - let cs = CsInterface { threads: dims, user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 3 }; + let cs = CsInterface { threads: dims, user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 3, ..Default::default() }; let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() }); let t = translate(&p, &opt).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); @@ -9085,7 +9085,7 @@ fn gpu_split_wave64_lds_write_then_read_across_halves() { let base = 0x1000usize; let groups = 64usize; for threads in [64u32, 128, 256] { - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 5, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 5, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() }); let t = translate(&p, &opt).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); @@ -9142,7 +9142,7 @@ fn gpu_split_wave64_one_wave_groups_end_early() { ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 7), ("DATA", 4), ("SADDR", 0x7D)], None), ]); for threads in [64u32, 48, 40] { - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() }); let t = translate(&p, &opt).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); @@ -9206,7 +9206,7 @@ fn lds_order_program() -> Vec { } fn lds_order_cs(threads: u32) -> super::CsInterface { - super::CsInterface { threads: [threads, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1 } + super::CsInterface { threads: [threads, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() } } #[test] @@ -9407,7 +9407,7 @@ fn wave_local_remap_decision_and_console_ids() { ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 6), ("DATA", 0), ("SADDR", 0x7D)], None), ]); let translate_as = |code: &[u8], threads, tgid, no_remap| { - let cs = CsInterface { threads, user_sgprs: 2, tgid, tg_size: false, tid_components: 3 }; + let cs = CsInterface { threads, user_sgprs: 2, tgid, tg_size: false, tid_components: 3, ..Default::default() }; translate(code, &Options { mode: Mode::Compute(cs), wave64: true, split_wave64: true, no_remap, ..Default::default() }).unwrap() }; for (threads, remap, shape, group_id) in [ @@ -9442,7 +9442,7 @@ fn dispatch_thread_limits_seed_compute_exec_for_native_and_remapped_groups() { translate( &p, &Options { - mode: Mode::Compute(CsInterface { threads, user_sgprs: 2, tgid: [true; 3], tg_size: false, tid_components: 3 }), + mode: Mode::Compute(CsInterface { threads, user_sgprs: 2, tgid: [true; 3], tg_size: false, tid_components: 3, ..Default::default() }), wave64: true, split_wave64, ..Default::default() @@ -9517,7 +9517,7 @@ fn bench_split_wave64() { let mut exchanges = 0; let mut spin = false; for wave64 in [false, true] { - let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64, ..Default::default() }); let t = translate(&p, &opt).unwrap(); // the loop's exchanges: masks read whole (`x64_masks`: not the v_cndmask @@ -9570,7 +9570,7 @@ fn gpu_compute_tg_size_counts_a_partial_last_wave() { ]); for (threads, wave64) in [(96u32, true), (96, false), (64, true), (40, false), (128, true)] { let lanes = if wave64 { 64 } else { 32 }; - let cs = super::CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: true, tid_components: 1 }; + let cs = super::CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: true, tid_components: 1, ..Default::default() }; let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64, ..Default::default() }); let t = translate(&p, &opt).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); @@ -9640,7 +9640,7 @@ fn dispatch_loop_budget_shrinks_with_the_groups() { /// the HLSL of every other program (and with it the DXIL cache's key) is as it was. #[test] fn only_compute_programs_with_a_loop_read_the_dispatch_loop_budget() { - let cs = super::CsInterface { threads: [8, 4, 2], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [8, 4, 2], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let compute = Options { mode: Mode::Compute(cs), wave64: false, ..Default::default() }; let looping = translate(&endless_loop_program(), &compute).unwrap(); assert!(looping.complete(), "{:?}", looping.unsupported_why); @@ -9671,7 +9671,7 @@ fn compute_loop_counts_compile() { if super::dxc::location().is_err() { return runner::skip_test("no DXC"); } - let cs = super::CsInterface { threads: [8, 4, 2], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [8, 4, 2], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; for wave64 in [false, true] { let compute = Options { mode: Mode::Compute(cs.clone()), wave64, ..Default::default() }; for code in [endless_loop_program(), endless_loop_entered_three_times()] { @@ -9695,7 +9695,7 @@ fn gpu_compute_loop_passes_follow_the_dispatch() { } let threads = 64u32; let run = |p: &[u8], wave64: bool, slot: u32| -> u32 { - let cs = super::CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: false, tid_components: 1, ..Default::default() }; let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64, ..Default::default() }); let t = translate(p, &opt).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); @@ -9755,7 +9755,7 @@ fn gpu_compute_folded_dispatch_runs_each_console_group_once() { assert_eq!(got, if k < 100 { k as u32 } else { 0xFFFF_FFFF }, "{what}: unfolded group {k}"); } }; - let cs = super::CsInterface { threads: [1, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [1, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; // the native wave64 forms need a GPU that runs wave64 (the split form runs anywhere) let wave64_ok = runner::wave64_supported() == Ok(true); for wave64 in [false, true] { @@ -9801,7 +9801,7 @@ fn compute_prologues_leave_the_lanes_past_a_thread_limit_out_of_exec() { (false, false, [64, 1, 1], true), ] { let what = format!("wave64 {wave64}, split {split}, {threads:?}, barrier {with_barrier}"); - let cs = super::CsInterface { threads, user_sgprs: 2, tgid: [true, true, false], tg_size: false, tid_components: 2 }; + let cs = super::CsInterface { threads, user_sgprs: 2, tgid: [true, true, false], tg_size: false, tid_components: 2, ..Default::default() }; let mut lines = store.to_vec(); if with_barrier { lines.insert(0, ("S_BARRIER", "ENC_SOPP", &[], None)); @@ -9869,7 +9869,7 @@ fn gpu_compute_thread_limits_leave_the_lanes_past_them_out() { forms.push(("direct wave64", true, |l, cs| translate_compute(&code_of(l), KernelOptions { wave64: true, split: false, mem_windows: 1, sampler_base: 0 }, cs).unwrap().dxil)); forms.push(("per-lane wave64", true, |l, cs| super::lower_dxil::compute_code(&code_of(l), cs, true).unwrap())); } - let cs = |threads: [u32; 3], y: bool| CsInterface { threads, user_sgprs: 2, tgid: [true, y, false], tg_size: false, tid_components: if y { 2 } else { 1 } }; + let cs = |threads: [u32; 3], y: bool| CsInterface { threads, user_sgprs: 2, tgid: [true, y, false], tg_size: false, tid_components: if y { 2 } else { 1 }, ..Default::default() }; let io = |x: u32, y: u32, folded: u32| { let mut io = vec![0u32; 128]; (io[IO_THREAD_LIMIT[0]], io[IO_THREAD_LIMIT[1]], io[IO_GROUP_LIMIT]) = (x, y, folded); @@ -11577,7 +11577,7 @@ fn gpu_safe_s_barrier_multi_warp_and_early_endpgm() { ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 7), ("DATA", 5), ("SADDR", 0x7D)], None), ]); - let cs = CsInterface { threads: [128, 1, 1], user_sgprs: 2, tgid: [false, false, false], tg_size: false, tid_components: 1 }; + let cs = CsInterface { threads: [128, 1, 1], user_sgprs: 2, tgid: [false, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let base = 0x100usize; let mut io = vec![0u32; 128]; io[0] = base as u32; @@ -12112,7 +12112,7 @@ fn jumps_to_outer_loop_heads_are_structured() { /// backends follow the same predicate. #[test] fn compute_globallycoherent_only_when_needed() { - let cs = super::CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let enc = |n: &str, e: &str, f: &[(&str, u64)]| encode(n, e, f, None).unwrap_or_else(|x| panic!("{n}: {x}")); let prog = |insts: &[(&str, &str, &[(&str, u64)])]| { let mut c = Vec::new(); @@ -12192,7 +12192,7 @@ fn gpu_compute_coherent_and_cached_loads() { if !gpu_ready() { return; } - let cs = super::CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1 }; + let cs = super::CsInterface { threads: [32, 1, 1], user_sgprs: 2, tgid: [true, false, false], tg_size: false, tid_components: 1, ..Default::default() }; let enc = |n: &str, e: &str, f: &[(&str, u64)]| encode(n, e, f, None).unwrap_or_else(|x| panic!("{n}: {x}")); // 1. Plain cached compute: each thread reads a uniform dword via SMEM (s[0:1] = 0x100) and diff --git a/crates/xcl/src/hle/d3d12x/real/compute_build_key.rs b/crates/xcl/src/hle/d3d12x/real/compute_build_key.rs index c91784fbb3..660c1ac322 100644 --- a/crates/xcl/src/hle/d3d12x/real/compute_build_key.rs +++ b/crates/xcl/src/hle/d3d12x/real/compute_build_key.rs @@ -157,6 +157,7 @@ mod tests { direct_compact: None, direct_compact_nest: None, direct_piece_limit: 0, + declared_lds: true, per_lane: false, disabled_dxil_optimizations: 0, } @@ -199,6 +200,7 @@ mod tests { mutate_policy(|p| p.direct_compact = Some(true)); mutate_policy(|p| p.direct_compact_nest = Some("outer".into())); mutate_policy(|p| p.direct_piece_limit = 1); + mutate_policy(|p| p.declared_lds = false); mutate_policy(|p| p.per_lane = true); mutate_policy(|p| p.disabled_dxil_optimizations = 1);