Skip to content
Open
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
43 changes: 43 additions & 0 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,37 @@ pub fn translate_compute(code: &[u8], o: KernelOptions, cs: &CsInterface) -> Res
translate_entry(code, o, Entry::Compute(cs.clone()), compact_mode())
}

/// `XCL_DIRECT_COMPACT_KB`: a compute program whose plain DXIL is over this many KiB is
/// translated again in the compact form, kept when smaller (default 1536; 0: off). On
/// NVIDIA the driver's compile time explodes between 2 and 4 MB of DXIL (a 3.9 MB plain
/// compute program was still in the driver after 5 minutes, its compact form a few seconds),
/// and a title that binds such a pipeline waits for it.
pub fn compact_over_bytes() -> usize {
static B: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
*B.get_or_init(|| compact_over_kb(std::env::var("XCL_DIRECT_COMPACT_KB").ok().as_deref()).saturating_mul(1024))
}

fn compact_over_kb(set: Option<&str>) -> usize {
set.and_then(|v| v.trim().parse().ok()).unwrap_or(1536)
}

fn translate_entry(code: &[u8], o: KernelOptions, entry: Entry, compact: Option<bool>) -> Result<Kernel, String> {
let retry = compact.is_none() && matches!(entry, Entry::Kernel | Entry::Compute(_));
let plain = translate_entry_once(code, o, entry.clone(), compact)?;
let over = compact_over_bytes();
if !retry || over == 0 || plain.dxil.len() <= over {
return Ok(plain);
}
match translate_entry_once(code, o, entry, Some(true)) {
Ok(c) if c.dxil.len() < plain.dxil.len() => {
crate::xlog_info!("[SHADER] direct DXIL: {} B plain over XCL_DIRECT_COMPACT_KB, {} B compact kept", plain.dxil.len(), c.dxil.len());
Ok(c)
}
_ => Ok(plain),
}
}

fn translate_entry_once(code: &[u8], o: KernelOptions, entry: Entry, compact: Option<bool>) -> Result<Kernel, String> {
// SSA construction recurses along the CFG (one level per guarded memory access between
// a register's definition and its use): a thread with a large stack for big programs
let code = code.to_vec();
Expand Down Expand Up @@ -820,3 +850,16 @@ fn geom_init(lw: &mut Lw, g: &GsInterface, _tid: Value, io: super::shader::RawUa
lw.wr(base, none);
lw.geom = Some(super::lower_geom::GeomCtx { g: g.clone(), emitted, strip, ntri, base, tri, maxt, rec });
}

#[cfg(test)]
mod compact_over_tests {
use super::compact_over_kb;

#[test]
fn the_compact_retry_is_over_1536_kib_unless_set_and_off_at_zero() {
assert_eq!(compact_over_kb(None), 1536);
assert_eq!(compact_over_kb(Some("4096")), 4096);
assert_eq!(compact_over_kb(Some("0")), 0);
assert_eq!(compact_over_kb(Some("nope")), 1536);
}
}
6 changes: 6 additions & 0 deletions crates/xcl/src/gpu/recomp/pso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ mod translated {
Some(on) if Backend::current() != Backend::Hlsl => identity_for(&id.to_string(), if on { "xcl-direct-compact-1" } else { "xcl-direct-compact-0" }),
_ => id,
};
// `XCL_DIRECT_COMPACT_KB` other than the default: the retry in the compact form
// happens at another size, another output
let id = match crate::gpu::dxil::kernel::compact_over_bytes() {
b if Backend::current() != Backend::Hlsl && b != 1536 * 1024 => identity_for(&id.to_string(), &format!("xcl-direct-compact-kb-{}", b >> 10)),
_ => id,
};
// `XCL_PER_LANE=1` (direct compute only): its entries under their own identity
if Backend::current() != Backend::Hlsl && crate::gpu::recomp::lower_dxil::enabled() {
identity_for(&id.to_string(), concat!("xcl-per-lane-", env!("XCL_PER_LANE_SOURCE_ID")))
Expand Down
Loading