Skip to content
Closed
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
51 changes: 37 additions & 14 deletions crates/xcl/tests/gpu_compute_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,29 @@ fn offline_split_compute_pipeline_is_reused_by_a_second_process() {
#[test]
fn a_preparation_worker_also_builds_a_split_programs_whole_form() {
use std::{fs, process::Command};
use std::collections::BTreeSet;
use xcl::gpu::recomp::pso::{console_to_dxil_in, Stage};
const TEST: &str = "a_preparation_worker_also_builds_a_split_programs_whole_form";
let blob = console_cs(&split_program(), 2 << 1 | 1 << 7, [32, 1, 1]);
// Translate with the worker's split settings in a separate process, so other tests
// do not inherit them. Derive the expected artifacts independently of the build loop.
if let Some(driver) = std::env::var_os("XCL_TEST_SPLIT_DRIVER_FILES") {
let c = console_to_dxil_in(&blob, Stage::Compute, 0, true, 1).unwrap();
assert!(c.samplers.is_empty());
let chain = c.dispatch_chain.unwrap();
assert!(chain.pieces.len() >= 2);
let name = |dxil: &[u8], ext: &str| format!("{:016x}-{:x}-0.{ext}", xcl::gpu::shader::fnv64(dxil), dxil.len());
let mut expected: BTreeSet<_> = chain.pieces.iter().map(|p| name(p, "chain.pso")).collect();
expected.insert(name(&c.dxil, "chain.pso"));
expected.insert(name(&c.dxil, "pso"));
let actual: BTreeSet<_> = fs::read_dir(driver).unwrap().map(|entry| {
let entry = entry.unwrap();
assert!(entry.file_type().unwrap().is_file() && entry.metadata().unwrap().len() > 0);
entry.file_name().into_string().unwrap()
}).collect();
assert_eq!(actual, expected);
return;
}
let _serial = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
if xcl::gpu::recomp::dxc::location().is_err() {
runner::skip_test("no DXC");
Expand All @@ -328,11 +351,11 @@ fn a_preparation_worker_also_builds_a_split_programs_whole_form() {
let input = dir.join("input");
let cache = dir.join("cache");
fs::create_dir_all(&input).unwrap();
fs::write(input.join("split.bin"), console_cs(&split_program(), 2 << 1 | 1 << 7, [32, 1, 1])).unwrap();
fs::write(input.join("split.bin"), blob).unwrap();
let out = Command::new(env!("CARGO_BIN_EXE_xcl"))
.arg("shaders")
.arg(&input)
.args(["--precompile", "--pipelines", "--windows", "1"])
.args(["--precompile", "--pipelines", "--windows", "1", "--split", "1"])
.env("XCL_DXIL_CACHE", &cache)
.env("XCL_DIRECT_DXIL", "1")
.env("XCL_DIRECT_SPLIT_INSTRUCTIONS", "12")
Expand All @@ -344,18 +367,18 @@ fn a_preparation_worker_also_builds_a_split_programs_whole_form() {
let text = String::from_utf8_lossy(&out.stdout).into_owned();
assert!(out.status.success(), "{text}
{}", String::from_utf8_lossy(&out.stderr));
let files: Vec<_> = fs::read_dir(cache.join("driver")).unwrap().flatten().map(|e| e.path()).collect();
let is_piece = |p: &std::path::Path| {
p.extension().is_some_and(|e| e == "pso") && p.file_name().is_some_and(|n| n.to_string_lossy().ends_with(".chain.pso"))
};
let pieces = files.iter().filter(|p| is_piece(p)).count();
let whole = files.iter().filter(|p| p.extension().is_some_and(|e| e == "pso") && !is_piece(p)).count();
assert!(pieces >= 2, "a blob for each split piece: {files:?}\n{text}");
assert_eq!(whole, 1, "one blob for the whole form: {files:?}\n{text}");
assert!(text.contains(&format!("pipelines made on the GPU {}, refused 0", pieces + whole)), "the whole form was not built: {text}");
assert_eq!(files.len(), pieces + whole, "only a blob for each piece and the whole form: {files:?}
{text}");
assert!(files.iter().all(|p| p.metadata().unwrap().len() > 0));
let driver = cache.join("driver");
let check = Command::new(std::env::current_exe().unwrap())
.args(["--exact", TEST, "--nocapture"])
.env("XCL_TEST_SPLIT_DRIVER_FILES", &driver)
.env("XCL_DXIL_CACHE", dir.join("expected"))
.env("XCL_DIRECT_DXIL", "1")
.env("XCL_DIRECT_SPLIT_INSTRUCTIONS", "12")
.output().unwrap();
assert!(check.status.success() && String::from_utf8_lossy(&check.stdout).contains("1 passed"),
"{}\n{}", String::from_utf8_lossy(&check.stdout), String::from_utf8_lossy(&check.stderr));
let count = fs::read_dir(driver).unwrap().count();
assert!(text.contains(&format!("pipelines made on the GPU {count}, refused 0")), "{text}");
let _ = fs::remove_dir_all(&dir);
}

Expand Down
Loading