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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
- Translated shaders are reused across XCL rebuilds when the translator sources and DXC
toolchain are unchanged; `XCL_TRANSLATED_CACHE=0` disables that disk cache.
- Direct compute dispatches can split large programs into pipelines built in parallel.
With guest LDS, single-wave groups can use any thread-group dimensions for native wave32
and wave64 emulated on wave32.
`XCL_DIRECT_SPLIT_INSTRUCTIONS` sets the target instructions per piece (default 12500,
zero disables splitting). Loops stay in one piece. A strongly connected component over the
target gets its own piece, up to four times the target. Larger components and indirect
Expand Down
14 changes: 11 additions & 3 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ fn translate_on_this_thread(
}
Entry::Compute(cs) => {
let (tid, gtid) = lw.setup_lanes_compute(cs.threads, uses_lds);
if split && !uses_lds && cs.threads == [64, 1, 1] { split_tid = Some(tid); }
let total = cs.threads.iter().try_fold(1u32, |a, &b| a.checked_mul(b)).unwrap_or(0);
if split && total != 0 && total % 64 == 0 && (!uses_lds || total == 64) {
split_tid = Some(tid);
} else if !o.wave64 && !uses_lds && cs.threads[1] * cs.threads[2] > 1 && total > 32 && total % 32 == 0 {
split_tid = Some(tid);
}
compute_init(&mut lw, cs, tid, gtid);
cs.threads
}
Expand Down Expand Up @@ -608,11 +613,14 @@ impl Lw {
}
let stage = self.s.stage;
let mut dispatch_chain = None;
let total = numthreads.iter().try_fold(1u32, |a, &b| a.checked_mul(b)).unwrap_or(0);
let native_w32 = !self.wave64 && !self.split && total >= 32 && total % 32 == 0
&& (self.lds.is_none() || total == 32);
let c = if matches!(stage, Stage::Vertex | Stage::Pixel) {
let g = self.gfx.take().ok_or("graphics entry without graphics I/O")?;
let info = if stage == Stage::Pixel { super::graphics::StageInfo::Pixel { early_depth_stencil: false } } else { super::graphics::StageInfo::Vertex };
self.s.try_finish_graphics(g.io, info)
} else if limit > 0 && (numthreads == [32, 1, 1] || split_tid.is_some()) && hw == 32 {
} else if limit > 0 && (native_w32 || split_tid.is_some()) && hw == 32 {
self.s.m.optimize();
dispatch_chain = self.s.split_compute(numthreads, split_tid, limit).map(std::sync::Arc::new);
self.s.finish_optimized(numthreads, Some(hw))
Expand Down Expand Up @@ -659,7 +667,7 @@ fn dispatch_chain_native_wave64_builds_whole() {
lw.s.m.ret();
lw.s.m.optimize();
// Exercise the native-wave admission gate with an otherwise partitionable CFG.
assert!(lw.s.m.dispatch_plan(64).is_some());
assert!(lw.s.m.dispatch_plan(64, None).is_some());
let program = lw.finish_dispatch(threads, 64, 64, None).unwrap();
assert!(program.dispatch_chain.is_none());
super::validate::validate(&program.dxil).expect("valid native wave64 whole shader");
Expand Down
13 changes: 11 additions & 2 deletions crates/xcl/src/gpu/dxil/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Lw {
let t = self.s.m.i1c(true);
let rank = self.s.wave_prefix_bit_count(t);
self.add(base, rank)
} else if y * z > 1 {
} else if y * z > 1 && total > lanes {
let i32 = self.s.m.i32();
let (g, at) = match (self.lds, lds_top_word) {
(Some(l), true) => (l, 8191),
Expand All @@ -136,8 +136,13 @@ impl Lw {
let base = self.sel(take, got, dflt);
let base = self.s.wave_read_lane_first(base);
let tid = self.add(base, hw);
self.s.barrier(barrier::GROUP_SYNC);
if lds_top_word && self.lds.is_some() {
self.s.barrier(barrier::GROUP_SYNC);
}
tid
} else if y * z > 1 {
// single native wave (`total <= lanes`): base is always 0, so no `xcl_wt` counter or barriers
self.s.wave_lane_index()
} else {
self.s.flattened_thread_id_in_group()
};
Expand All @@ -156,6 +161,8 @@ impl Lw {
}
let lane = if self.split {
self.andc(tid, 63)
} else if y * z > 1 && total <= lanes {
tid
} else {
self.s.wave_lane_index()
};
Expand Down Expand Up @@ -300,6 +307,7 @@ impl Lw {
let alive = self.cmpc(Pred::Eq, dead, 0);
let has = self.cmpc(Pred::Ne, xn, 0);
let go = self.land(alive, has);
let region = (self.cur(), self.s.m.block_count());
let _ = self.guarded(go, &mut |lw| {
lw.s.barrier(barrier::TGSM_FENCE);
let t = lw.s.m.i1c(true);
Expand Down Expand Up @@ -354,6 +362,7 @@ impl Lw {
});
let one = self.c(1);
let ho = self.xor(h, one);
self.s.m.finish_spin_region(region.0, region.1);
let theirs = at(self, ho);
let metv = self.rd(met);
let ok = self.nz(metv);
Expand Down
10 changes: 10 additions & 0 deletions crates/xcl/src/gpu/dxil/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pub struct Module {
insts: Vec<InstDef>,
def_block: Vec<Block>,
blocks: Vec<Vec<u32>>,
spin_regions: Vec<Vec<Block>>,
cur: Block,
insert_before_term: bool,
md: Vec<MdDef>,
Expand Down Expand Up @@ -282,6 +283,7 @@ impl Module {
insts: Vec::new(),
def_block: Vec::new(),
blocks: vec![Vec::new()],
spin_regions: Vec::new(),
cur: Block(0),
insert_before_term: false,
md: Vec::new(),
Expand Down Expand Up @@ -519,6 +521,14 @@ impl Module {
self.blocks.push(Vec::new());
Block(self.blocks.len() as u32 - 1)
}
/// Keep both halves' signal and wait in the same dispatch. The join can
/// begin the next piece since the exchange slots are checkpointed.
pub(super) fn finish_spin_region(&mut self, start: Block, first_new: usize) {
let mut region = vec![start];
region.extend((first_new..self.blocks.len()).map(|i| Block(i as u32)).filter(|&b| b != self.cur));
self.spin_regions.push(region);
}

pub fn entry_block(&self) -> Block {
Block(0)
}
Expand Down
Loading
Loading