From c1e0b2cbd566b3422476e313e45b78bd11116221 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 23 Nov 2026 01:57:35 -0800 Subject: [PATCH] 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. --- .../metal2vulkan/src/lower/dispatch/tests.rs | 41 +++++-------------- .../metal2vulkan/src/tests/engine_dispatch.rs | 1 - .../src/tests/engine_global_builtins.rs | 1 - .../metal2vulkan/src/tests/engine_skeleton.rs | 21 ++++++---- crates/metal2vulkan/src/tests/fuzz_interp.rs | 2 +- 5 files changed, 25 insertions(+), 41 deletions(-) diff --git a/crates/metal2vulkan/src/lower/dispatch/tests.rs b/crates/metal2vulkan/src/lower/dispatch/tests.rs index 21bfdcce5..a5eb495e2 100644 --- a/crates/metal2vulkan/src/lower/dispatch/tests.rs +++ b/crates/metal2vulkan/src/lower/dispatch/tests.rs @@ -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)> { +fn run_region(m: &TypedModule, r: &Region, sg: SubgroupSize) -> Vec<([u32; 3], u32, Vec)> { let n = r.local.iter().product::(); let groups = r.groups.iter().product::(); 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> = 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, - ®ions, - threads, - l, - SubgroupSize::W32, - ); + check_dispatch(&m, ®ions, 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, - ®ions, - threads, - l, - SubgroupSize::W32, - ); + check_dispatch(&m, ®ions, threads, l, SubgroupSize::W32); } } @@ -533,7 +513,7 @@ fn group_count_splits_match_the_single_dispatch() { }); } } - check_dispatch(&m, form, ®ions, threads, l, SubgroupSize::W64); + check_dispatch(&m, ®ions, 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> = 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:?}"); } diff --git a/crates/metal2vulkan/src/tests/engine_dispatch.rs b/crates/metal2vulkan/src/tests/engine_dispatch.rs index 18526eb0c..be4d9e1a0 100644 --- a/crates/metal2vulkan/src/tests/engine_dispatch.rs +++ b/crates/metal2vulkan/src/tests/engine_dispatch.rs @@ -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 { diff --git a/crates/metal2vulkan/src/tests/engine_global_builtins.rs b/crates/metal2vulkan/src/tests/engine_global_builtins.rs index ee7dd00e4..a3a6ccca7 100644 --- a/crates/metal2vulkan/src/tests/engine_global_builtins.rs +++ b/crates/metal2vulkan/src/tests/engine_global_builtins.rs @@ -286,7 +286,6 @@ fn run_kernel(bc: &[u8], local: [u32; 3], words: usize) -> Vec { 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:?}"); diff --git a/crates/metal2vulkan/src/tests/engine_skeleton.rs b/crates/metal2vulkan/src/tests/engine_skeleton.rs index 73bc78e7d..2d908975c 100644 --- a/crates/metal2vulkan/src/tests/engine_skeleton.rs +++ b/crates/metal2vulkan/src/tests/engine_skeleton.rs @@ -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}" ); diff --git a/crates/metal2vulkan/src/tests/fuzz_interp.rs b/crates/metal2vulkan/src/tests/fuzz_interp.rs index 7806e33e0..82f946c6e 100644 --- a/crates/metal2vulkan/src/tests/fuzz_interp.rs +++ b/crates/metal2vulkan/src/tests/fuzz_interp.rs @@ -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,