Tests: the threadgroup_constants edit's leftovers, and the skeleton kernel's declared constants

Test files only. At 99f90c7503 plain clippy (job m3-max-70512, msi) refused the mechanical
edit's leftovers: two `let n` products no longer read, a SpecKey import, and the `form` parameter
of dispatch/tests.rs's run_region, run_partial and check_dispatch, which chose only whether to
write FlatLocalSize, now always written by the call. The translator suite (m3-max-70516, msi:
2782 of 2784, the golden table bless-due aside) failed engine_skeleton's
store_const_passes_the_pipeline_on_every_m1_profile, whose kernel now declares the three
WorkgroupSize constants after DeepThreadgroup, every bit of them read, and reads no bit of
LocalSize or DeepThreadgroup (unread_bits all ones), which only the old OpSpecConstantOp parts
read; the expectation says so.
This commit is contained in:
Anees Iqbal committed 2026-11-23 01:57:35 -08:00
1 parent 99f90c7503
commit c1e0b2cbd5
5 files changed
+25 -41

No files matched your search

+10 -31
View File
@@ -208,12 +208,7 @@ struct Region {
}
/// Run `m` for region `r`; returns each invocation's `(Vulkan workgroup, local index, record)`.
fn run_region(
m: &TypedModule,
form: LocalSizeForm,
r: &Region,
sg: SubgroupSize,
) -> Vec<([u32; 3], u32, Vec<u32>)> {
fn run_region(m: &TypedModule, r: &Region, sg: SubgroupSize) -> Vec<([u32; 3], u32, Vec<u32>)> {
let n = r.local.iter().product::<u32>();
let groups = r.groups.iter().product::<u32>();
let words = record_words();
@@ -320,7 +315,6 @@ fn position(rec: &[u32]) -> [u32; 3] {
/// the records cover each Metal thread exactly once with Metal's builtins.
fn check_dispatch(
m: &TypedModule,
form: LocalSizeForm,
regions: &[Region],
threads: [u32; 3],
l: [u32; 3],
@@ -328,7 +322,7 @@ fn check_dispatch(
) {
let mut seen: BTreeMap<[u32; 3], Vec<u32>> = BTreeMap::new();
for r in regions {
for (wg, li, rec) in run_region(m, form, r, sg) {
for (wg, li, rec) in run_region(m, r, sg) {
let p = position(&rec);
assert!(
seen.insert(p, rec.clone()).is_none(),
@@ -391,7 +385,7 @@ fn single_region_builtins_match_metal() {
multi: None,
};
let threads = std::array::from_fn(|i| l[i] * groups[i]);
check_dispatch(&m, form, &[r], threads, l, sg);
check_dispatch(&m, &[r], threads, l, sg);
}
}
}
@@ -421,7 +415,7 @@ fn a_deep_threadgroup_keeps_every_builtin() {
multi: None,
};
let threads = std::array::from_fn(|i| l[i] * groups[i]);
check_dispatch(&m, LocalSizeForm::Spec, &[r], threads, l, sg);
check_dispatch(&m, &[r], threads, l, sg);
}
}
}
@@ -430,14 +424,7 @@ fn a_deep_threadgroup_keeps_every_builtin() {
let m = module(&dp);
let (threads, l) = ([3, 5, 316], [2, 2, 128]);
let regions = thread_regions(threads, l);
check_dispatch(
&m,
LocalSizeForm::Spec,
&regions,
threads,
l,
SubgroupSize::W32,
);
check_dispatch(&m, &regions, threads, l, SubgroupSize::W32);
}
/// A flattened kernel whose pipeline pins its subgroup size reads no `SubgroupSize` builtin: its
@@ -482,7 +469,7 @@ fn a_pinned_subgroup_size_reads_no_subgroup_size_builtin() {
groups,
multi: None,
};
check_dispatch(&m, LocalSizeForm::Flat, &[r], threads, l, sg);
check_dispatch(&m, &[r], threads, l, sg);
}
}
}
@@ -499,14 +486,7 @@ fn dispatch_threads_regions_match_metal() {
([5, 7, 3], [2, 3, 2]),
] {
let regions = thread_regions(threads, l);
check_dispatch(
&m,
LocalSizeForm::Spec,
&regions,
threads,
l,
SubgroupSize::W32,
);
check_dispatch(&m, &regions, threads, l, SubgroupSize::W32);
}
}
@@ -533,7 +513,7 @@ fn group_count_splits_match_the_single_dispatch() {
});
}
}
check_dispatch(&m, form, &regions, threads, l, SubgroupSize::W64);
check_dispatch(&m, &regions, threads, l, SubgroupSize::W64);
}
}
@@ -543,7 +523,6 @@ fn group_count_splits_match_the_single_dispatch() {
/// invocation's live word and builtins.
fn run_partial(
m: &TypedModule,
form: LocalSizeForm,
threads: [u32; 3],
l: [u32; 3],
flagged: bool,
@@ -621,7 +600,7 @@ fn partial_object_threadgroups_match_metal() {
for &(threads, l) in cases {
let mut seen: BTreeMap<[u32; 3], Vec<u32>> = BTreeMap::new();
let mut dead = 0;
for (live, rec) in run_partial(&m, form, threads, l, true, sg) {
for (live, rec) in run_partial(&m, threads, l, true, sg) {
if live == 0 {
dead += 1;
continue;
@@ -647,7 +626,7 @@ fn partial_object_threadgroups_match_metal() {
}
// Unflagged, of whole threadgroups: the uniform answers, every invocation live.
let (threads, l) = ([64, 4, 2], [32, 2, 1]);
for (live, rec) in run_partial(&m, form, threads, l, false, sg) {
for (live, rec) in run_partial(&m, threads, l, false, sg) {
assert_eq!(live, 1);
assert_eq!(rec, metal(position(&rec), threads, l), "{form:?}");
}
@@ -80,7 +80,6 @@ const STATUS_BYTES: usize =
fn run_word0(plan: &Plan, m: &TypedModule, d: &Dispatch) -> u32 {
let mut spec = BTreeMap::new();
spec.extend(crate::pipeline::threadgroup_constants(d.local));
let n: u32 = d.local.iter().product();
let mut push = vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)];
for f in &plan.push.fields {
let PushLoc::Push { offset } = f.loc else {
@@ -286,7 +286,6 @@ fn run_kernel(bc: &[u8], local: [u32; 3], words: usize) -> Vec<u32> {
let (plan, m) = typed_module(bc, "k", &p).expect("plan");
let mut spec = BTreeMap::new();
spec.extend(crate::pipeline::threadgroup_constants(local));
let n: u32 = local.iter().product();
let push = vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)];
for f in &plan.push.fields {
assert!(matches!(f.loc, PushLoc::Push { .. }), "{f:?}");
@@ -103,16 +103,23 @@ fn check_artifact(a: &FunctionArtifact, what: &str) {
)],
"{what}"
);
// The local size is the `WorkgroupSize` spec composite of `sx, sy, sz`, 4-byte `u32`
// constants defaulting to 1, and the threadgroup runs as one row under `DeepThreadgroup`,
// defaulting to false.
// The workgroup is the `WorkgroupSize` composite of its own plain constants, 4-byte `u32`
// constants defaulting to 1, beside the threadgroup's sides `sx, sy, sz` (defaulting to 1)
// and `DeepThreadgroup` (defaulting to false), of which this kernel's body reads no bit.
let unread = |key, default| StageSpec {
unread_bits: u64::from(u32::MAX),
..StageSpec::new(key, 4, default)
};
assert_eq!(
i.spec,
vec![
StageSpec::new(SpecKey::LocalSize(Axis::X), 4, 1),
StageSpec::new(SpecKey::LocalSize(Axis::Y), 4, 1),
StageSpec::new(SpecKey::LocalSize(Axis::Z), 4, 1),
StageSpec::new(SpecKey::DeepThreadgroup, 4, 0)
unread(SpecKey::LocalSize(Axis::X), 1),
unread(SpecKey::LocalSize(Axis::Y), 1),
unread(SpecKey::LocalSize(Axis::Z), 1),
unread(SpecKey::DeepThreadgroup, 0),
StageSpec::new(SpecKey::WorkgroupSize(Axis::X), 4, 1),
StageSpec::new(SpecKey::WorkgroupSize(Axis::Y), 4, 1),
StageSpec::new(SpecKey::WorkgroupSize(Axis::Z), 4, 1),
],
"{what}"
);
+1 -1
View File
@@ -36,7 +36,7 @@ use crate::pipeline::compile::compile_bitcode_kept;
use crate::pipeline::testing::{link_and_validate, meter, profile};
use crate::pipeline::{
EntryRef, LoweringInputs, PushField, PushLoc, ResourceKind, ResourceSlot, SlotClass, SlotRef,
SpecKey, Stage,
Stage,
};
use crate::spirv::interp::{
run, BarrierRule, Buffer, Config, Order, Outcome, Resources, SubgroupSize,