diff --git a/crates/metal2vulkan-validation/corpus/README.md b/crates/metal2vulkan-validation/corpus/README.md index 3e8a07ad8..d9d761fe6 100644 --- a/crates/metal2vulkan-validation/corpus/README.md +++ b/crates/metal2vulkan-validation/corpus/README.md @@ -149,12 +149,11 @@ targeted cascade without installing a replacement. ## Observations -A Metal slot is `(case_id, environment_id)`. A candidate slot is -`(case_id, backend, environment_id)`. Requalification replaces the exact slot; duplicate active -slots are rejected. +A Metal slot is `(case_id, environment_id)`, and so is a candidate slot. Requalification replaces +the exact slot; duplicate active slots are rejected. Metal evidence carries case, AIR, input, output, environment, and oracle-ABI hashes. Candidate -evidence additionally carries the exact Metal output hash, SPIR-V hash, backend environment, and +evidence additionally carries the exact Metal output hash, SPIR-V hash, Vulkan environment, and executor ABI. Reuse requires every dependency to match. Metal qualification runs a checked literal case three times. All selected outputs must be diff --git a/crates/metal2vulkan-validation/src/bin/candidate_batch.rs b/crates/metal2vulkan-validation/src/bin/candidate_batch.rs index 5bbcd07d7..fd4c7ab88 100644 --- a/crates/metal2vulkan-validation/src/bin/candidate_batch.rs +++ b/crates/metal2vulkan-validation/src/bin/candidate_batch.rs @@ -4,12 +4,11 @@ use metal2vulkan_validation::gpu::tripwire::TripwirePaths; use metal2vulkan_validation::gpu::wait::parse_wait_timeout; use metal2vulkan_validation::gpu::DeviceType; -use metal2vulkan_validation::observation::Backend; use metal2vulkan_validation::source::corpus_root; use metal2vulkan_validation::store::CorpusStore; use metal2vulkan_validation::vulkan_batch::{ - self, plan, qualified_cases, read_done_list, report, requested_cases, run_batch, BatchBuild, - BatchConfig, BatchDevice, BatchOutput, Class, Outcome, Pass, DONE_LIST, + self, plan, qualified_cases, read_done_list, report, requested_cases, run_batch, BatchBackend, + BatchBuild, BatchConfig, BatchDevice, BatchOutput, Class, Outcome, Pass, DONE_LIST, }; use std::collections::BTreeMap; use std::path::PathBuf; @@ -63,7 +62,7 @@ sources), the only build whose rows are current once installed."; /// Run a batch mode if the command line names one (its first argument): `true` when it did (and /// it exited the process on an error), `false` for a single-case invocation, the workers' included. -pub fn serve(backend: Backend) -> bool { +pub fn serve() -> bool { let mut args = std::env::args().skip(1); let Some(mode) = args.next().filter(|arg| { matches!( @@ -73,16 +72,15 @@ pub fn serve(backend: Backend) -> bool { }) else { return false; }; - if let Err(error) = main(backend, &mode, args.collect()) { - eprintln!("corpus-{} {mode}: {error}", backend.directory()); + if let Err(error) = main(&mode, args.collect()) { + eprintln!("corpus-vulkan {mode}: {error}"); std::process::exit(1); } true } -/// Run the batch mode `mode` (`--batch`, `--batch-report`, `--batch-install`) of `backend` with -/// `args`. -fn main(backend: Backend, mode: &str, args: Vec) -> Result<(), String> { +/// Run the batch mode `mode` (`--batch`, `--batch-report`, `--batch-install`) with `args`. +fn main(mode: &str, args: Vec) -> Result<(), String> { let mut corpus = corpus_root(); let mut out = None; let mut install = None; @@ -136,7 +134,7 @@ fn main(backend: Backend, mode: &str, args: Vec) -> Result<(), String> { match mode { "--batch-install" => { let target = install.ok_or("--batch-install DIR is required")?; - let installed = vulkan_batch::install(&out, &CorpusStore::new(&target), backend)?; + let installed = vulkan_batch::install(&out, &CorpusStore::new(&target))?; println!( "batch-install rows={} refusals={} store={} this_build={}", installed.rows, @@ -160,7 +158,7 @@ fn main(backend: Backend, mode: &str, args: Vec) -> Result<(), String> { Some(recorded) => Some( *recorded == BatchBuild::current( - backend.into(), + BatchBackend::Vulkan, &metal_environment_id, &environment_id, restricted_to.as_deref(), @@ -242,7 +240,7 @@ fn main(backend: Backend, mode: &str, args: Vec) -> Result<(), String> { let config = BatchConfig { executor: std::env::current_exe() .map_err(|error| format!("this executable: {error}"))?, - backend: backend.into(), + backend: BatchBackend::Vulkan, corpus, out, metal_environment_id, diff --git a/crates/metal2vulkan-validation/src/bin/candidate_common.rs b/crates/metal2vulkan-validation/src/bin/candidate_common.rs index 3be17a91f..7bf446604 100644 --- a/crates/metal2vulkan-validation/src/bin/candidate_common.rs +++ b/crates/metal2vulkan-validation/src/bin/candidate_common.rs @@ -2,7 +2,6 @@ use metal2vulkan_validation::candidate::{engine, exit_status}; use metal2vulkan_validation::check::admission::ExecutorError; use metal2vulkan_validation::gpu::wait::{parse_wait_timeout, set_wait_timeout}; use metal2vulkan_validation::gpu::DeviceType; -use metal2vulkan_validation::observation::Backend; use metal2vulkan_validation::source::corpus_root; use metal2vulkan_validation::store::CorpusStore; use metal2vulkan_validation::worker::alloc::CountingAllocator; @@ -16,10 +15,10 @@ use std::path::PathBuf; #[global_allocator] static ALLOCATOR: CountingAllocator = CountingAllocator; -pub fn main(backend: Backend) { +pub fn main() { serve_if_requested(); device::serve_if_requested(); - match run(backend) { + match run() { Ok(()) => {} Err(ExecutorError::Refused(refused)) => { println!("{refused}"); @@ -42,13 +41,13 @@ pub fn main(backend: Backend) { std::process::exit(exit_status::VENUE_MISMATCH); } Err(ExecutorError::Failed(error)) => { - eprintln!("corpus-{}: {error}", backend.directory()); + eprintln!("corpus-vulkan: {error}"); std::process::exit(1); } } } -fn run(backend: Backend) -> Result<(), ExecutorError> { +fn run() -> Result<(), ExecutorError> { let mut root = corpus_root(); let mut case_id = None; let mut air_sha256 = None; @@ -84,7 +83,7 @@ fn run(backend: Backend) -> Result<(), ExecutorError> { )?)?)?, "-h" | "--help" => { println!( - "usage: corpus-{} [--corpus DIR] [--private-corpus DIR] --case-id HASH --metal-environment-id ID --environment-id ID --device-type cpu|gpu \\\n\ + "usage: corpus-vulkan [--corpus DIR] [--private-corpus DIR] --case-id HASH --metal-environment-id ID --environment-id ID --device-type cpu|gpu \\\n\ [--air-sha256 HASH] [--source-index FILE] \\\n\ [--gpu-wait-timeout SECONDS] [--profiles-layer P] \\\n\ [--without-generated-commands]\n\ @@ -121,8 +120,7 @@ fn run(backend: Backend) -> Result<(), ExecutorError> { The executor compares only against the case's Metal observation in the\n\ --metal-environment-id environment recorded by the current oracle for the\n\ checked case; without one it reports needs_metal_qualification{{...}} (exit 6)\n\ - before any device opens.", - backend.directory() + before any device opens." ); return Ok(()); } @@ -149,7 +147,6 @@ fn run(backend: Backend) -> Result<(), ExecutorError> { &root, case, device_type, - backend, &metal_environment_id, &environment_id, &CompileWorker::current()?, diff --git a/crates/metal2vulkan-validation/src/bin/corpus-status.rs b/crates/metal2vulkan-validation/src/bin/corpus-status.rs index 87ff3601c..c286270f3 100644 --- a/crates/metal2vulkan-validation/src/bin/corpus-status.rs +++ b/crates/metal2vulkan-validation/src/bin/corpus-status.rs @@ -130,8 +130,8 @@ fn run() -> Result<(), String> { \"fingerprint\"}}). --rekey-venues migrates venue records to this build's keys\n\ without running anything: LIST is a JSON array of {{\"stem\", \"from\":\n\ {{\"sha256\", \"fingerprint\"}}, \"to\": {{...}}}}, each \"to\" this build's key of\n\ - \"stem\" (as --venue-keys prints it), and every row and refusal, of either\n\ - backend, that recorded \"stem\" at exactly \"from\" records \"to\" instead, in\n\ + \"stem\" (as --venue-keys prints it), and every row and refusal that\n\ + recorded \"stem\" at exactly \"from\" records \"to\" instead, in\n\ one transaction; no other record changes, and a second run changes nothing.\n\ Use it only for a change whose authored-compile census leaves every artifact\n\ digest byte-identical: the records then stay their venue's\n\ diff --git a/crates/metal2vulkan-validation/src/bin/corpus-vulkan.rs b/crates/metal2vulkan-validation/src/bin/corpus-vulkan.rs index 8e4a0d32c..37535a0f8 100644 --- a/crates/metal2vulkan-validation/src/bin/corpus-vulkan.rs +++ b/crates/metal2vulkan-validation/src/bin/corpus-vulkan.rs @@ -2,7 +2,6 @@ mod candidate_batch; mod candidate_common; use metal2vulkan_validation::gpu::DeviceType; -use metal2vulkan_validation::observation::Backend; use std::path::PathBuf; fn main() { @@ -30,8 +29,8 @@ fn main() { } _ => {} } - if !candidate_batch::serve(Backend::Vulkan) { - candidate_common::main(Backend::Vulkan); + if !candidate_batch::serve() { + candidate_common::main(); } } diff --git a/crates/metal2vulkan-validation/src/c3.rs b/crates/metal2vulkan-validation/src/c3.rs index 1968f26db..3809f2210 100644 --- a/crates/metal2vulkan-validation/src/c3.rs +++ b/crates/metal2vulkan-validation/src/c3.rs @@ -97,9 +97,7 @@ use crate::cutover::scope::OutOfScope; use crate::cutover::{List, Review, SignOff}; use crate::index::EvidenceState; use crate::metal::ORACLE_ABI; -use crate::observation::{ - validate_hash, Backend, CandidateObservation, CandidateStatus, MetalObservation, -}; +use crate::observation::{validate_hash, CandidateObservation, CandidateStatus, MetalObservation}; use crate::observation_contract::ComparisonClass; use crate::refusal::{Refusal, RefusalClass, RefusalObservation}; use crate::source::public_sources; @@ -596,8 +594,8 @@ impl C3Input { Ok(C3Input { cases: store.read_all_cases()?, metals: store.read_metal()?, - vulkan: store.read_candidates(Backend::Vulkan)?, - refusals: store.read_refusals(Backend::Vulkan)?, + vulkan: store.read_candidates()?, + refusals: store.read_refusals()?, public_air: public_sources()? .into_iter() .map(|source| source.air_sha256) @@ -1292,11 +1290,11 @@ pub fn report( .is_some_and(|gaps| gaps.contains(&entry.gap))) }) }; - let verdict = |case: &AuthoredCase, backend: Backend, slot: &str| -> Option { + let verdict = |case: &AuthoredCase, slot: &str| -> Option { let Some(row) = rows.get(&(case.case_id.as_str(), slot)) else { let refusal = refusals.get(&(case.case_id.as_str(), slot))?; if other_device(slot, &refusal.environment) - || !crate::index::refusal_is_current(case, backend, refusal, keys) + || !crate::index::refusal_is_current(case, refusal, keys) { return Some(Verdict::Stale); } @@ -1319,7 +1317,7 @@ pub fn report( } let judging = judged_by(case); Some( - match crate::index::candidate_slot_state(case, backend, judging.as_slice(), row, keys) { + match crate::index::candidate_slot_state(case, judging.as_slice(), row, keys) { EvidenceState::Current => Verdict::Match, EvidenceState::Failed if list.reviews(row).is_some() && deferred_note(row).is_none() => @@ -1366,7 +1364,7 @@ pub fn report( // not join the population. let judgeable = judged_by(case).is_some(); report.population += usize::from(required); - let judged = match verdict(case, venue.backend(), &slot) { + let judged = match verdict(case, &slot) { Some(verdict) => verdict, None if required || judgeable => Verdict::Missing, None => continue, @@ -1478,13 +1476,7 @@ pub fn report( let judging = judged_by(case); !row_on_other_device(row) && matches!( - crate::index::candidate_slot_state( - case, - row.backend, - judging.as_slice(), - row, - keys, - ), + crate::index::candidate_slot_state(case, judging.as_slice(), row, keys,), EvidenceState::Current | EvidenceState::Failed ) } diff --git a/crates/metal2vulkan-validation/src/c3/tests.rs b/crates/metal2vulkan-validation/src/c3/tests.rs index 0b3d744c9..4bb6ab56a 100644 --- a/crates/metal2vulkan-validation/src/c3/tests.rs +++ b/crates/metal2vulkan-validation/src/c3/tests.rs @@ -12,7 +12,7 @@ use crate::case::{ }; use crate::cutover::SignOff; use crate::hash::{hex_encode, sha256_bytes}; -use crate::observation::MetalStatus; +use crate::observation::{Backend, MetalStatus}; use crate::observation_contract::ComparisonClass; use metal2vulkan::pipeline::PrecisionNote; use reference::ReferenceEnvironment; @@ -224,7 +224,6 @@ fn report_of( /// A row of `case` in `environment_id` reading `output` against Metal's `golden`. fn row( case: &AuthoredCase, - backend: Backend, environment_id: String, output: &[u8], golden: &[u8], @@ -239,7 +238,7 @@ fn row( translator_fingerprint: String::new(), candidate_output_sha256: sha256_bytes(output), output_b64: b64(output), - backend, + backend: Backend::Vulkan, environment_id, environment: serde_json::json!({}), executor_abi: String::new(), @@ -256,18 +255,11 @@ fn row( /// A current engine row in the stated slot of `environment`, as the executor records it. fn new_row( case: &AuthoredCase, - backend: Backend, environment: &str, output: &[u8], golden: &[u8], ) -> CandidateObservation { - let mut row = row( - case, - backend, - engine_slot(environment, None), - output, - golden, - ); + let mut row = row(case, engine_slot(environment, None), output, golden); row.executor_abi = ENGINE_EXECUTOR_ABI.into(); row.translator_fingerprint = engine_fingerprint_of(&PROFILE); row.environment = recorded_environment(environment); @@ -381,7 +373,7 @@ fn a_listed_mismatch_at_its_candidate_is_reviewed_and_a_changed_candidate_is_not public_air: [bounded.air_sha256.clone()].into(), ..C3Input::default() }; - let lavapipe = new_row(&bounded, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); + let lavapipe = new_row(&bounded, LAVAPIPE, &DEVICE, &METAL); input.vulkan.push(lavapipe.clone()); // Unlisted, the current mismatch is a mismatch, and C3 does not hold. @@ -516,7 +508,7 @@ fn a_listed_mismatch_at_its_candidate_is_reviewed_and_a_changed_candidate_is_not #[test] fn stale_rows_are_not_evidence_and_their_reviewed_reading_still_names_them() { let bounded = case(1, "bounded"); - let mut stale = new_row(&bounded, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); + let mut stale = new_row(&bounded, LAVAPIPE, &DEVICE, &METAL); // Recorded by another product build. stale.translator_fingerprint = engine_fingerprint_of(&[9; 32]); let input = C3Input { @@ -564,7 +556,7 @@ fn a_row_waiting_on_metal_is_stale_without_metal_until_metal_requalifies() { oracle_abi: "metal-literal-resources-v1".into(), ..metal(case, &METAL) }; - let mut other_build = new_row(&rebuilt, Backend::Vulkan, LAVAPIPE, &METAL, &METAL); + let mut other_build = new_row(&rebuilt, LAVAPIPE, &METAL, &METAL); other_build.translator_fingerprint = engine_fingerprint_of(&[9; 32]); let mut stale_refusal = refusal_of( &refused, @@ -575,10 +567,7 @@ fn a_row_waiting_on_metal_is_stale_without_metal_until_metal_requalifies() { let input = C3Input { cases: vec![awaiting.clone(), rebuilt.clone(), refused.clone()], metals: vec![older(&awaiting), metal(&rebuilt, &METAL), older(&refused)], - vulkan: vec![ - new_row(&awaiting, Backend::Vulkan, LAVAPIPE, &METAL, &METAL), - other_build, - ], + vulkan: vec![new_row(&awaiting, LAVAPIPE, &METAL, &METAL), other_build], refusals: vec![stale_refusal], public_air: [&awaiting, &rebuilt, &refused] .iter() @@ -653,7 +642,7 @@ fn a_reference_gap_is_counted_apart_and_held_to_the_users_sign_off() { metals: vec![gap_row(&gap_case), gap_row(&stale_gap)], vulkan: vec![ // Recorded against a Metal output the oracle no longer holds: stale. - new_row(&stale_gap, Backend::Vulkan, LAVAPIPE, &METAL, &METAL), + new_row(&stale_gap, LAVAPIPE, &METAL, &METAL), ], public_air: [&gap_case, &stale_gap, &unqualified] .map(|case| case.air_sha256.clone()) @@ -707,14 +696,10 @@ fn a_reference_gap_is_counted_apart_and_held_to_the_users_sign_off() { qualified.metals.push(metal(&unqualified, &METAL)); qualified .vulkan - .push(new_row(&unqualified, Backend::Vulkan, GPU, &METAL, &METAL)); - qualified.vulkan.push(new_row( - &unqualified, - Backend::Vulkan, - LAVAPIPE, - &METAL, - &METAL, - )); + .push(new_row(&unqualified, GPU, &METAL, &METAL)); + qualified + .vulkan + .push(new_row(&unqualified, LAVAPIPE, &METAL, &METAL)); let entry = |case: &AuthoredCase, apple_family, sign_off| ReferenceGapEntry { case_id: case.case_id.clone(), name: case.name.clone(), @@ -791,7 +776,7 @@ fn a_reference_gap_is_counted_apart_and_held_to_the_users_sign_off() { fn a_reviewed_reading_that_disagrees_with_the_store_is_reported() { let bounded = case(1, "bounded"); let other = case(2, "other"); - let lavapipe = new_row(&bounded, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); + let lavapipe = new_row(&bounded, LAVAPIPE, &DEVICE, &METAL); let input = C3Input { cases: vec![bounded.clone()], metals: vec![metal(&bounded, &METAL)], @@ -1112,7 +1097,7 @@ fn a_device_interpolation_row_stays_a_mismatch() { assert!(!DEFERRED_NEAR_EQUIVALENTS.contains(¬e)); let drawn = case(1, "drawn"); let noted = |output: &[u8]| { - let mut row = new_row(&drawn, Backend::Vulkan, LAVAPIPE, output, &METAL); + let mut row = new_row(&drawn, LAVAPIPE, output, &METAL); row.census = Some(ExecutedCensus { out_of_bounds: None, rate_map_pass: None, @@ -1209,7 +1194,7 @@ fn deferred_and_never_reviewed(note: PrecisionNote, label: &str) { use crate::coverage::{ExecutedCensus, ModuleCensus}; let sampled = case(1, "sampled"); let noted = |output: &[u8]| { - let mut row = new_row(&sampled, Backend::Vulkan, LAVAPIPE, output, &METAL); + let mut row = new_row(&sampled, LAVAPIPE, output, &METAL); row.census = Some(ExecutedCensus { out_of_bounds: None, rate_map_pass: None, @@ -1305,7 +1290,7 @@ fn deferred_and_never_reviewed(note: PrecisionNote, label: &str) { #[test] fn metals_latitude_may_be_signed_off_and_the_fma_cause_is_gone() { let fma = case(3, "fma"); - let row = new_row(&fma, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); + let row = new_row(&fma, LAVAPIPE, &DEVICE, &METAL); assert!( serde_json::from_str::("\"pinned_by_metal_not_vulkan\"").is_err(), "a superseded cause parses" @@ -1330,7 +1315,7 @@ fn metals_latitude_may_be_signed_off_and_the_fma_cause_is_gone() { #[test] fn an_apple_reading_is_signed_off_only_with_well_formed_lanes() { let bounded = case(1, "bounded"); - let row = new_row(&bounded, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); + let row = new_row(&bounded, LAVAPIPE, &DEVICE, &METAL); let list = |change: &dyn Fn(&mut Reading)| { let mut entry = reading(&bounded, vec![reviewed(&row, &METAL)]); change(&mut entry); @@ -1423,7 +1408,7 @@ fn a_signed_off_apple_reading_holds_only_while_every_differing_word_is_within_ap let bounded = case(1, "bounded"); let at = |device: f32, entry: &dyn Fn(&mut Reading)| { let device = device.to_le_bytes(); - let row = new_row(&bounded, Backend::Vulkan, LAVAPIPE, &device, &METAL); + let row = new_row(&bounded, LAVAPIPE, &device, &METAL); let mut reading = reading(&bounded, vec![reviewed(&row, &METAL)]); entry(&mut reading); let input = C3Input { @@ -1542,10 +1527,7 @@ fn an_unstated_word_the_product_approximates_keeps_its_reading_open() { } let report_of = |word: &Word, notes: &[PrecisionNote]| { let case = case(word.tag, word.computes); - let row = noting( - new_row(&case, Backend::Vulkan, LAVAPIPE, &word.device, &word.metal), - notes, - ); + let row = noting(new_row(&case, LAVAPIPE, &word.device, &word.metal), notes); let mut reading = reading(&case, vec![reviewed(&row, &word.metal)]); reading.lanes = vec![lane(word.computes, Math::Fast, &word.operands)]; let input = C3Input { @@ -1643,10 +1625,7 @@ fn a_word_within_apples_bound_that_shows_a_recorded_near_equivalent_keeps_its_re notes: &[PrecisionNote]| { let case = case(5, "product"); let (golden, output) = (golden.to_le_bytes(), output.to_le_bytes()); - let row = noting( - new_row(&case, Backend::Vulkan, LAVAPIPE, &output, &golden), - notes, - ); + let row = noting(new_row(&case, LAVAPIPE, &output, &golden), notes); let mut reading = reading(&case, vec![reviewed(&row, &golden)]); let operands = operands.iter().map(|x| x.to_bits()).collect::>(); reading.lanes = vec![lane(computes, math, &operands)]; @@ -1751,11 +1730,11 @@ fn each_venue_covers_its_own_population() { ..C3Input::default() }; // One real GPU ran the public and the private case. - let radv = |case: &AuthoredCase| new_row(case, Backend::Vulkan, RADV, &METAL, &METAL); + let radv = |case: &AuthoredCase| new_row(case, RADV, &METAL, &METAL); input.vulkan = vec![ radv(&public), radv(&private), - new_row(&public, Backend::Vulkan, LAVAPIPE, &METAL, &METAL), + new_row(&public, LAVAPIPE, &METAL, &METAL), ]; let report = report_of( &input, @@ -1802,7 +1781,7 @@ fn a_case_a_venue_never_recorded_is_missing_and_selected_by_its_lane() { cases: vec![private.clone(), unqualified.clone()], metals: vec![metal(&private, &METAL)], // Only one real GPU recorded the private case; nothing recorded the unqualified one. - vulkan: vec![new_row(&private, Backend::Vulkan, RADV, &METAL, &METAL)], + vulkan: vec![new_row(&private, RADV, &METAL, &METAL)], ..C3Input::default() }; let judge = |input: &C3Input| { @@ -1844,7 +1823,7 @@ fn a_case_a_venue_never_recorded_is_missing_and_selected_by_its_lane() { for venue in [GPU, LAVAPIPE] { recorded .vulkan - .push(new_row(&private, Backend::Vulkan, venue, &METAL, &METAL)); + .push(new_row(&private, venue, &METAL, &METAL)); } let report = judge(&recorded); for venue in [GPU, LAVAPIPE] { @@ -1870,7 +1849,7 @@ fn a_row_recorded_under_another_driver_is_stale_never_current() { vulkan: rows, ..C3Input::default() }; - let declared = new_row(&bounded, Backend::Vulkan, RADV, &METAL, &METAL); + let declared = new_row(&bounded, RADV, &METAL, &METAL); let mut updated = declared.clone(); updated.environment["driver_info"] = "Mesa 26.2.5".into(); updated.environment["driver_version"] = 109060101.into(); @@ -1924,9 +1903,9 @@ fn a_row_recorded_under_another_driver_is_stale_never_current() { // Another device, and a row that records no identity, are stale too; so is a mismatching // row's reviewed reading, which is no longer current evidence. - let mut other_device = new_row(&bounded, Backend::Vulkan, RADV, &DEVICE, &METAL); + let mut other_device = new_row(&bounded, RADV, &DEVICE, &METAL); other_device.environment["device_id"] = 0x1681.into(); - let mut unrecorded = new_row(&bounded, Backend::Vulkan, RADV, &METAL, &METAL); + let mut unrecorded = new_row(&bounded, RADV, &METAL, &METAL); unrecorded .environment .as_object_mut() @@ -1964,8 +1943,8 @@ fn a_row_recorded_under_another_driver_is_stale_never_current() { #[test] fn a_reading_reviewed_in_one_venue_does_not_cover_another() { let bounded = case(1, "bounded"); - let lavapipe = new_row(&bounded, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); - let radv = new_row(&bounded, Backend::Vulkan, RADV, &DEVICE, &METAL); + let lavapipe = new_row(&bounded, LAVAPIPE, &DEVICE, &METAL); + let radv = new_row(&bounded, RADV, &DEVICE, &METAL); assert_eq!( (&lavapipe.spv_sha256, &lavapipe.candidate_output_sha256), (&radv.spv_sha256, &radv.candidate_output_sha256) @@ -2022,12 +2001,7 @@ fn unbounded_by(row: CandidateObservation, notes: &[PrecisionNote]) -> Candidate #[test] fn a_fast_math_blend_of_a_half_output_shows_the_regrouping_cause() { let blend = case(1, "half_blend"); - let row = |notes: &[PrecisionNote]| { - unbounded_by( - new_row(&blend, Backend::Vulkan, GPU, &DEVICE, &METAL), - notes, - ) - }; + let row = |notes: &[PrecisionNote]| unbounded_by(new_row(&blend, GPU, &DEVICE, &METAL), notes); let regrouping = Cause::FastMathRegrouping; assert!(regrouping.shown_by(&row(&[PrecisionNote::HalfOutputFastMathBlend]))); assert!(regrouping.shown_by(&row(&[PrecisionNote::FastMathRewrites]))); @@ -2046,9 +2020,9 @@ fn a_regrouping_reading_is_keyed_by_its_cause_in_every_slot() { let regroup = [PrecisionNote::FastMathRewrites]; let fft = case(1, "fft"); let mut rows = [ - new_row(&fft, Backend::Vulkan, GPU, &DEVICE, &METAL), - new_row(&fft, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL), - new_row(&fft, Backend::Vulkan, RADV, &OTHER, &METAL), + new_row(&fft, GPU, &DEVICE, &METAL), + new_row(&fft, LAVAPIPE, &DEVICE, &METAL), + new_row(&fft, RADV, &OTHER, &METAL), ] .map(|row| unbounded_by(row, ®roup)); for (at, row) in rows.iter_mut().enumerate() { @@ -2101,7 +2075,7 @@ fn a_regrouping_reading_is_keyed_by_its_cause_in_every_slot() { // A row that no longer records the cause is an open mismatch in its own slot alone. let mut pinned = rows.clone(); - pinned[2] = new_row(&fft, Backend::Vulkan, RADV, &OTHER, &METAL); + pinned[2] = new_row(&fft, RADV, &OTHER, &METAL); let report = judge(&input_of(&pinned), &list); assert_eq!( verdicts(&report), @@ -2112,7 +2086,7 @@ fn a_regrouping_reading_is_keyed_by_its_cause_in_every_slot() { // In the reviewed observation's own slot, the reading reads changed too: review it again. let mut pinned = rows.clone(); - pinned[1] = new_row(&fft, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); + pinned[1] = new_row(&fft, LAVAPIPE, &DEVICE, &METAL); let report = judge(&input_of(&pinned), &list); assert_eq!( verdicts(&report), @@ -2123,10 +2097,7 @@ fn a_regrouping_reading_is_keyed_by_its_cause_in_every_slot() { // A row that now matches Metal is a match, and the reading no longer describes its slot. let mut matched = rows.clone(); - matched[1] = unbounded_by( - new_row(&fft, Backend::Vulkan, LAVAPIPE, &METAL, &METAL), - ®roup, - ); + matched[1] = unbounded_by(new_row(&fft, LAVAPIPE, &METAL, &METAL), ®roup); let report = judge(&input_of(&matched), &list); assert_eq!( verdicts(&report), @@ -2137,7 +2108,7 @@ fn a_regrouping_reading_is_keyed_by_its_cause_in_every_slot() { // A deferred near-equivalent beside the cause keeps its row open with its reason. let mut deferred = rows.clone(); deferred[2] = unbounded_by( - new_row(&fft, Backend::Vulkan, RADV, &OTHER, &METAL), + new_row(&fft, RADV, &OTHER, &METAL), &[ PrecisionNote::FastMathRewrites, PrecisionNote::SparseResidency, @@ -2344,8 +2315,7 @@ fn a_venue_profile_is_a_capture_of_the_venues_own_device() { } /// Each committed venue keys its native engine slot with its committed profile's translation key, -/// which a record holds only by recording it; a venue is found by its operator environment and -/// backend. +/// which a record holds only by recording it; a venue is found by its operator environment. #[test] fn each_venue_keys_its_slots_with_its_profiles_key() { let committed = Venues::load(&Venues::committed_path()).unwrap(); @@ -2356,25 +2326,18 @@ fn each_venue_keys_its_slots_with_its_profiles_key() { VenueProfile::key_of(&profile.description).unwrap(), profile.fingerprint ); - let backend = venue.backend(); let slot = engine_slot(&venue.environment_id, None); - assert_eq!( - keys.expected(backend, &slot), - Some(profile.fingerprint.as_str()) - ); + assert_eq!(keys.expected(&slot), Some(profile.fingerprint.as_str())); let mut environment = serde_json::json!({}); - assert!(!keys.holds(backend, &slot, &environment)); + assert!(!keys.holds(&slot, &environment)); environment[VENUE_PROFILE] = profile.record(); - assert!(keys.holds(backend, &slot, &environment)); + assert!(keys.holds(&slot, &environment)); assert_eq!( VenueProfile::recorded_stem(&environment), Some(venue.profile.as_str()) ); - assert_eq!(keys.expected(backend, &venue.environment_id), None); - assert_eq!( - committed.venue_of(&venue.environment_id, backend), - Some(venue) - ); + assert_eq!(keys.expected(&venue.environment_id), None); + assert_eq!(committed.venue_of(&venue.environment_id), Some(venue)); } } @@ -2441,16 +2404,12 @@ fn a_subgroup_gap_names_a_mismatch_only_where_the_device_has_it() { public_air: [counted.air_sha256.clone(), other.air_sha256.clone()].into(), ..C3Input::default() }; - input.vulkan.push(new_row( - &counted, - Backend::Vulkan, - LAVAPIPE, - &DEVICE, - &METAL, - )); input .vulkan - .push(new_row(&other, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL)); + .push(new_row(&counted, LAVAPIPE, &DEVICE, &METAL)); + input + .vulkan + .push(new_row(&other, LAVAPIPE, &DEVICE, &METAL)); let gap = AnswerGap::FragmentSubgroupUnderTwoQuads; let list = ReviewedList { answer_gaps: vec![AnswerGapEntry { @@ -2504,9 +2463,7 @@ fn a_subgroup_gap_names_a_mismatch_only_where_the_device_has_it() { // The other case matching, the listed case alone keeps the slot open. input.vulkan.retain(|row| row.case_id != other.case_id); - input - .vulkan - .push(new_row(&other, Backend::Vulkan, LAVAPIPE, &METAL, &METAL)); + input.vulkan.push(new_row(&other, LAVAPIPE, &METAL, &METAL)); let report = judged(&input, &keys, &list); let stated = slot(&report, LAVAPIPE); assert!(!stated.holds()); @@ -2540,7 +2497,7 @@ fn the_clipped_primitive_split_names_a_mismatch_only_where_the_case_meets_it() { cases: vec![split.clone()], metals: vec![metal(&split, &METAL)], public_air: [split.air_sha256.clone()].into(), - vulkan: vec![new_row(&split, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL)], + vulkan: vec![new_row(&split, LAVAPIPE, &DEVICE, &METAL)], ..C3Input::default() }; let gap = AnswerGap::ClippedPrimitiveSplit; @@ -2832,7 +2789,7 @@ fn a_refused_case_reads_refused_never_missing() { // A row in the slot is judged, not a refusal beside it. let mut ran = input.clone(); - ran.vulkan = vec![new_row(&refused, Backend::Vulkan, RADV, &METAL, &METAL)]; + ran.vulkan = vec![new_row(&refused, RADV, &METAL, &METAL)]; assert_eq!( verdict_of(slot(&judge(&ran), RADV), &refused), Verdict::Match @@ -3014,7 +2971,7 @@ fn a_deferred_near_equivalent_stays_open_with_its_reason() { use crate::case::{RateMapLayerLiteral, RateMapLiteral, RateSample}; use crate::coverage::{ExecutedCensus, ModuleCensus}; let decoded = case(1, "decoded"); - let mut row = new_row(&decoded, Backend::Vulkan, LAVAPIPE, &DEVICE, &METAL); + let mut row = new_row(&decoded, LAVAPIPE, &DEVICE, &METAL); row.census = Some(ExecutedCensus { out_of_bounds: None, rate_map_pass: None, @@ -3141,14 +3098,13 @@ fn a_refused_restriction_is_a_device_refusal_of_its_restricted_slot_only() { assert_eq!(refusal.refusal.class, RefusalClass::Device); assert!(crate::index::refusal_is_current( &refused, - Backend::Vulkan, &refusal, &VenueKeys::default() )); let input = C3Input { cases: vec![refused.clone()], metals: vec![metal(&refused, &METAL)], - vulkan: vec![new_row(&refused, Backend::Vulkan, RADV, &METAL, &METAL)], + vulkan: vec![new_row(&refused, RADV, &METAL, &METAL)], refusals: vec![refusal], ..C3Input::default() }; diff --git a/crates/metal2vulkan-validation/src/c3/venues.rs b/crates/metal2vulkan-validation/src/c3/venues.rs index bd416cac5..e60f4fb28 100644 --- a/crates/metal2vulkan-validation/src/c3/venues.rs +++ b/crates/metal2vulkan-validation/src/c3/venues.rs @@ -3,8 +3,8 @@ //! device and driver its rows must have run on. //! //! The list is data (`validation/cutover/c3-venues.json`): another device is one more entry, never -//! new code. The report treats every venue alike; a venue's kind decides only which store backend -//! holds its rows and which device type its lane runs. +//! new code. The report treats every venue alike; a venue's kind decides only which device type +//! its lane runs. //! //! **Driver drift.** Every engine row records the device it ran on (`environment`: the device //! name, vendor and device IDs, and the driver's ID, version, and info string). A venue declares @@ -35,7 +35,6 @@ use super::AnswerGap; use crate::authored_compile::{CurrentArtifacts, ProfileStem}; use crate::candidate::engine::artifact::ExecutedArtifact; use crate::cutover::list_path; -use crate::observation::Backend; use metal2vulkan::device::ApiVersion; use metal2vulkan::device::DeviceDescription; use metal2vulkan::vk; @@ -63,13 +62,6 @@ impl VenueKind { Self::NativeGpu => "native_gpu", } } - - /// The store backend that holds the venue's rows. - pub fn backend(self) -> Backend { - match self { - Self::CpuIcd | Self::NativeGpu => Backend::Vulkan, - } - } } /// The cases a venue's slot must cover. @@ -255,10 +247,6 @@ pub struct VenueDevice { } impl Venue { - pub fn backend(&self) -> Backend { - self.kind.backend() - } - /// Whether a record of `identity` ran on a device the venue allows. pub fn allows(&self, identity: &DeviceIdentity) -> bool { self.devices @@ -486,10 +474,10 @@ impl Venues { } /// What each venue's records must hold. The key: by engine slot (each venue's native slot), the -/// venue's backend and its committed profile's [`VenueProfile::fingerprint`]. The -/// one currency rule (`index::candidate_slot_state`, `index::refusal_is_current`) reads a record in -/// such a slot of that backend stale unless it recorded that fingerprint; a record anywhere else is -/// no venue's, and the rule asks nothing of it. +/// venue's committed profile's [`VenueProfile::fingerprint`]. The one currency rule +/// (`index::candidate_slot_state`, `index::refusal_is_current`) reads a record in such a slot +/// stale unless it recorded that fingerprint; a record anywhere else is no venue's, and the rule +/// asks nothing of it. /// /// The artifacts: this build's digest of each case on each venue's profile /// ([`CurrentArtifacts`]). A venue's record of another build is current for its product while @@ -505,7 +493,6 @@ pub struct VenueKeys { /// A venue's native engine slot. #[derive(Clone, Debug, PartialEq, Eq)] struct VenueSlot { - backend: Backend, /// The committed profile's fingerprint. fingerprint: String, /// The committed profile. @@ -513,19 +500,12 @@ struct VenueSlot { } impl VenueKeys { - /// Hold `environment_id`'s native slot in `backend` to `fingerprint`, the key of the - /// committed profile `profile` (its stem). - pub fn insert( - &mut self, - environment_id: &str, - backend: Backend, - fingerprint: &str, - profile: &str, - ) { + /// Hold `environment_id`'s native slot to `fingerprint`, the key of the committed profile + /// `profile` (its stem). + pub fn insert(&mut self, environment_id: &str, fingerprint: &str, profile: &str) { self.by_slot.insert( crate::candidate::engine::engine_environment_id(environment_id), VenueSlot { - backend, fingerprint: fingerprint.into(), profile: ProfileStem { stem: profile.into(), @@ -554,39 +534,32 @@ impl VenueKeys { self.gaps.get(slot).is_some_and(|gaps| gaps.contains(&gap)) } - /// The venue slot `slot` of `backend` is, when it is one. - fn slot(&self, backend: Backend, slot: &str) -> Option<&VenueSlot> { + /// The fingerprint a record in `slot` must have recorded, when it is a venue's. + pub fn expected(&self, slot: &str) -> Option<&str> { self.by_slot .get(slot) - .filter(|venue_slot| venue_slot.backend == backend) - } - - /// The fingerprint a record in `slot` of `backend` must have recorded, when it is a venue's. - pub fn expected(&self, backend: Backend, slot: &str) -> Option<&str> { - self.slot(backend, slot) .map(|venue_slot| venue_slot.fingerprint.as_str()) } - /// Whether a record of `backend` in `slot` whose environment is `environment` holds the key its - /// venue requires: always for a record no venue keys. - pub fn holds(&self, backend: Backend, slot: &str, environment: &Value) -> bool { - self.expected(backend, slot).is_none_or(|expected| { + /// Whether a record in `slot` whose environment is `environment` holds the key its venue + /// requires: always for a record no venue keys. + pub fn holds(&self, slot: &str, environment: &Value) -> bool { + self.expected(slot).is_none_or(|expected| { VenueProfile::recorded_fingerprint(environment) == Some(expected) }) } - /// Whether a venue's record of `case_id` in `slot` of `backend` executed `executed`, this + /// Whether a venue's record of `case_id` in `slot` executed `executed`, this /// build's artifact of the case on the slot's profile (`ExecutedArtifact::is_current`). /// Never for a record no venue keys, one that recorded no digest, or a case and profile this /// build's file holds no digest of. pub fn artifact_is_current( &self, - backend: Backend, slot: &str, case_id: &str, executed: Option<&ExecutedArtifact>, ) -> bool { - self.slot(backend, slot).is_some_and(|venue_slot| { + self.by_slot.get(slot).is_some_and(|venue_slot| { executed.is_some_and(|executed| { executed.is_current(self.artifacts.get(case_id, &venue_slot.profile)) }) @@ -661,19 +634,14 @@ impl Venues { } /// What every venue's records must hold ([`VenueKeys`]): each venue's committed profile's - /// fingerprint, in its backend, and `artifacts`, this build's digests + /// fingerprint, and `artifacts`, this build's digests /// (`CurrentArtifacts::load` of the corpus whose records are judged). pub fn keys(&self, artifacts: CurrentArtifacts) -> Result { let mut keys = VenueKeys::default().with_artifacts(artifacts); for venue in &self.venues { let profile = VenueProfile::committed(&venue.profile) .map_err(|error| format!("C3 venue {:?}: {error}", venue.environment_id))?; - keys.insert( - &venue.environment_id, - venue.backend(), - &profile.fingerprint, - &venue.profile, - ); + keys.insert(&venue.environment_id, &profile.fingerprint, &venue.profile); let derived = crate::acceptance::derived_profile(profile.description.clone()) .map_err(|error| format!("C3 venue {:?}: {error}", venue.environment_id))?; keys.insert_gaps( @@ -684,12 +652,12 @@ impl Venues { Ok(keys) } - /// The venue whose rows of `backend` are recorded under the operator environment - /// `environment_id`, if one is. - pub fn venue_of(&self, environment_id: &str, backend: Backend) -> Option<&Venue> { + /// The venue whose rows are recorded under the operator environment `environment_id`, if one + /// is. + pub fn venue_of(&self, environment_id: &str) -> Option<&Venue> { self.venues .iter() - .find(|venue| venue.environment_id == environment_id && venue.backend() == backend) + .find(|venue| venue.environment_id == environment_id) } /// Read and check the venue list at `path`; an error names the file. diff --git a/crates/metal2vulkan-validation/src/candidate.rs b/crates/metal2vulkan-validation/src/candidate.rs index 18030d2c5..8e6389f53 100644 --- a/crates/metal2vulkan-validation/src/candidate.rs +++ b/crates/metal2vulkan-validation/src/candidate.rs @@ -1,5 +1,4 @@ use crate::gpu::DeviceType; -use crate::observation::Backend; use std::sync::OnceLock; /// The exit statuses of the candidate executor's processes (`corpus-vulkan`): one per [`ExecutorError`](crate::check::admission::ExecutorError) kind that is not a failure, so a caller that runs them as processes @@ -114,8 +113,9 @@ pub(crate) fn echo_validation_messages() { platform::echo_validation_messages(); } -fn validate_backend_host(backend: Backend) -> Result<(), String> { - if backend == Backend::Vulkan && cfg!(target_os = "macos") { +/// Refuse candidate execution on macOS: its Vulkan is MoltenVK's, which no candidate runs on. +fn validate_host() -> Result<(), String> { + if cfg!(target_os = "macos") { return Err("Vulkan candidate execution is not available on macOS".into()); } Ok(()) @@ -182,7 +182,6 @@ mod platform { &super::engine::ChildCommand, ) -> Result, _registered: &[metal2vulkan::bind::ReplayVariant], - _backend: Backend, ) -> super::engine::RunAttempt { super::engine::RunAttempt::of(Err( "candidate execution is supported only on Linux and macOS".into(), @@ -206,7 +205,6 @@ mod platform { &metal2vulkan::bind::BindShape, &super::engine::ChildCommand, ) -> Result, - _backend: Backend, ) -> super::engine::RunAttempt { super::engine::RunAttempt::of(Err( "candidate execution is supported only on Linux and macOS".into(), diff --git a/crates/metal2vulkan-validation/src/candidate/engine.rs b/crates/metal2vulkan-validation/src/candidate/engine.rs index 9e7754868..91038a09a 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine.rs @@ -2317,7 +2317,6 @@ pub fn execute( root: &Path, case: AuthoredCase, device_type: DeviceType, - backend: Backend, metal_environment_id: &str, environment_id: &str, worker: &CompileWorker, @@ -2333,7 +2332,6 @@ pub fn execute( device_type, root, admitted, - backend, metal_environment_id, environment_id, worker, @@ -2349,7 +2347,6 @@ pub fn execute_case( device: DeviceType, root: &Path, admitted: AdmittedCase, - backend: Backend, metal_environment_id: &str, environment_id: &str, worker: &CompileWorker, @@ -2357,7 +2354,6 @@ pub fn execute_case( execute_prepared( root, prepare_case(device, admitted)?, - backend, metal_environment_id, environment_id, worker, @@ -3115,7 +3111,7 @@ pub(crate) fn run_on_device(input: &DeviceInput) -> DeviceOutcome { match prepare_on_device(input) { Ok((prepared, worker)) => { let clock = crate::budgets::CreationClock::start(); - let attempt = run_on_context(&prepared, input.backend, &worker); + let attempt = run_on_context(&prepared, &worker); let timing = CaseTiming::of_one(clock.read()); DeviceOutcome { result: attempt.result.map(|run| DeviceRun { @@ -3199,28 +3195,22 @@ fn prepare_on_device(input: &DeviceInput) -> Result<(PreparedCase, CompileWorker /// Compile (in `worker`), bind, and execute one prepared case on the executor's context: a /// kernel case as one dispatch, a vertex or fragment case as one draw. The run's row or refusal /// records what it compiled, by content ([`artifact::CaseArtifact`]). -fn run_on_context(prepared: &PreparedCase, backend: Backend, worker: &CompileWorker) -> RunAttempt { +fn run_on_context(prepared: &PreparedCase, worker: &CompileWorker) -> RunAttempt { let case = &prepared.checked.primary.case; let templates = &prepared.templates; // The worker assembles a row that retains no bitcode (a public fixture), and a companion. let library = RowSource::of_row(&prepared.checked.primary.source); let linked = &prepared.linked; - // A case the runtime runs, run so in this process's default run: the native backend and no - // profiles-layer restriction. It records no artifact: the runtime keeps what it compiled to + // A case the runtime runs, run so in this process's default run: no profiles-layer + // restriction. It records no artifact: the runtime keeps what it compiled to // itself. if let Mapped::Compute(compute) = &prepared.mapped { - if backend == Backend::Vulkan - && runs_through_runtime(case, compute) - && super::requested_restriction().is_none() - { + if runs_through_runtime(case, compute) && super::requested_restriction().is_none() { return run_on_runtime(prepared, compute); } } if let Mapped::Render(render) = &prepared.mapped { - if backend == Backend::Vulkan - && runs_render_through_runtime(case, render) - && super::requested_restriction().is_none() - { + if runs_render_through_runtime(case, render) && super::requested_restriction().is_none() { return run_render_on_runtime(prepared, render); } } @@ -3261,7 +3251,6 @@ fn run_on_context(prepared: &PreparedCase, backend: Backend, worker: &CompileWor }, children, ®istered, - backend, ) } Mapped::Render(render) => { @@ -3290,7 +3279,6 @@ fn run_on_context(prepared: &PreparedCase, backend: Backend, worker: &CompileWor Ok(compiled) }, children, - backend, ) } // A run's preparation refuses a mesh case before it maps (`prepare_case`); only the @@ -3475,7 +3463,6 @@ fn replay_variant_request<'a>( pub fn execute_prepared( root: &Path, prepared: PreparedCase, - backend: Backend, metal_environment_id: &str, environment_id: &str, worker: &CompileWorker, @@ -3490,7 +3477,7 @@ pub fn execute_prepared( ) .into()); } - super::validate_backend_host(backend)?; + super::validate_host()?; let PreparedCase { device, checked, .. } = prepared; @@ -3511,7 +3498,7 @@ pub fn execute_prepared( let venue = match restricted_to { Some(_) => None, None => Venues::load(&Venues::committed_path())? - .venue_of(environment_id, backend) + .venue_of(environment_id) .map(|venue| VenueRun { environment_id: environment_id.into(), profile: venue.profile.clone(), @@ -3526,7 +3513,6 @@ pub fn execute_prepared( root: root.to_path_buf(), case: case.clone(), device, - backend, input_sha256: checked.primary.input_sha256.clone(), wait_timeout_ms: u64::try_from(wait_timeout().as_millis()).unwrap_or(u64::MAX), restricted_to, @@ -3547,7 +3533,7 @@ pub fn execute_prepared( air_sha256: case.air_sha256.clone(), input_sha256: input.input_sha256.clone(), translator_fingerprint: opened.translator_fingerprint, - backend, + backend: Backend::Vulkan, environment_id: engine_slot(environment_id, input.restricted_to.as_deref()), environment: opened.environment, executor_abi: ENGINE_EXECUTOR_ABI.into(), @@ -3586,7 +3572,7 @@ pub fn execute_prepared( translator_fingerprint: run.translator_fingerprint.clone(), candidate_output_sha256, output_b64: base64::engine::general_purpose::STANDARD.encode(&run.output), - backend, + backend: Backend::Vulkan, environment_id: slot.clone(), environment: run.environment, executor_abi: ENGINE_EXECUTOR_ABI.into(), @@ -3603,7 +3589,6 @@ pub fn execute_prepared( metal: &metal, spv_sha256: run.spv_sha256.as_deref(), translator_fingerprint: &run.translator_fingerprint, - backend, environment_id: &slot, executor_abi: ENGINE_EXECUTOR_ABI, }; diff --git a/crates/metal2vulkan-validation/src/candidate/platform/compute.rs b/crates/metal2vulkan-validation/src/candidate/platform/compute.rs index 0fb337615..d433a6cc4 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/compute.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/compute.rs @@ -36,7 +36,7 @@ use crate::gpu::wait::{with_submission_label, SubmissionLabel}; use crate::gpu::DeviceType; use crate::hash::sha256_bytes; use crate::literal::LiteralTexture; -use crate::observation::{Backend, TRANSLATOR_FINGERPRINT}; +use crate::observation::TRANSLATOR_FINGERPRINT; use crate::worker::compile::WorkerDevice; use ash::vk; use metal2vulkan::bind::BindingPlan; @@ -88,20 +88,12 @@ pub fn execute_engine( &ChildCommand, ) -> Result, registered: &[ReplayVariant], - backend: Backend, ) -> RunAttempt { if let Some(refused) = refused_attempt(device_type, "engine-compute") { return refused; } with_validated_context(device_type, |context| { - let result = run( - context, - case_id, - case, - (compile, children), - registered, - backend, - ); + let result = run(context, case_id, case, (compile, children), registered); Ok(attempt(context, result, "engine-compute")) }) .unwrap_or_else(|error| RunAttempt::of(Err(ExecutorError::Failed(error)))) @@ -231,18 +223,6 @@ pub(super) fn opened_device(context: &VulkanContext) -> Result Result<(), ExecutorError> { - let moltenvk = context.driver.driver_id == vk::DriverId::MOLTENVK.as_raw(); - match backend { - Backend::Vulkan if moltenvk => Err("the vulkan backend opened MoltenVK".into()), - Backend::Vulkan => Ok(()), - } -} - fn run( context: &VulkanContext, case_id: &str, @@ -257,9 +237,7 @@ fn run( ) -> Result, ), registered: &[ReplayVariant], - backend: Backend, ) -> Result { - check_backend(context, backend)?; let target = opened_device(context)?; let addressed = context .enabled diff --git a/crates/metal2vulkan-validation/src/candidate/platform/render.rs b/crates/metal2vulkan-validation/src/candidate/platform/render.rs index b8d1c33ca..d24268186 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/render.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/render.rs @@ -71,7 +71,7 @@ use super::acceptance::{unmet_requirements, LayoutError, LayoutObjects}; use super::buffers::{create_host_buffer, HostBuffer}; use super::compute::{ - allocate, allocate_in, attempt, check_backend, command_replay, environment, executed_census, + allocate, allocate_in, attempt, command_replay, environment, executed_census, incompatible_binding, module_censuses, opened_device, refused_attempt, replay_commands, table_bytes, upload_root_table, Allocation, CompileChild, Live, OnDevice, Replay, ReplayPath, }; @@ -99,7 +99,6 @@ use crate::gpu::wait::{with_submission_label, SubmissionLabel}; use crate::gpu::DeviceType; use crate::hash::sha256_bytes; use crate::literal::{LiteralDepthStencil, LiteralTexture}; -use crate::observation::Backend; use crate::worker::compile::WorkerDevice; use ash::vk; use metal2vulkan::bind::{ @@ -137,13 +136,12 @@ pub fn execute_engine_render( &BindShape, &ChildCommand, ) -> Result, - backend: Backend, ) -> RunAttempt { if let Some(refused) = refused_attempt(device_type, "engine-render") { return refused; } with_validated_context(device_type, |context| { - let result = run(context, case_id, case, (compile, children), backend); + let result = run(context, case_id, case, (compile, children)); Ok(attempt(context, result, "engine-render")) }) .unwrap_or_else(|error| RunAttempt::of(Err(ExecutorError::Failed(error)))) @@ -162,9 +160,7 @@ fn run( &ChildCommand, ) -> Result, ), - backend: Backend, ) -> Result { - check_backend(context, backend)?; let target = opened_device(context)?; let addressed = context .enabled diff --git a/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs b/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs index 66a0f2801..c6872b0fa 100644 --- a/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs +++ b/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs @@ -15,8 +15,6 @@ use metal2vulkan::library::FunctionConstantValues; use metal2vulkan_devtools::{engine_dir, llvm_assemble}; use std::collections::BTreeMap; -pub(crate) const BACKEND: Backend = Backend::Vulkan; - pub(crate) fn case(entry: &str, buffer: Vec, dispatch: Dispatch) -> ComputeCase { let length = buffer.len() as u64; ComputeCase { @@ -86,7 +84,6 @@ fn run_linked( }, |_, token, _, _| Err(format!("no template has pipeline token {token}").into()), &[], - BACKEND, ) .result } diff --git a/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs b/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs index 879fcfa54..e3410b16f 100644 --- a/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs +++ b/crates/metal2vulkan-validation/src/candidate/tests/engine_render.rs @@ -4,7 +4,6 @@ //! (y-up clip space, pixel-center coverage). `G-linux`'s `m2v_cpu_icd` step runs these on lavapipe. //! The looping fragment runs as compiled on both lanes. -use super::engine_compute::BACKEND; use super::*; use crate::candidate::engine::graphics::tests::{ checked_companion, draw_request, reflected_imageblock, two_stage_case, RenderLibraries, @@ -39,7 +38,6 @@ fn run(case: &RenderCase, libraries: RenderLibraries<'_>) -> Result) -> (ScratchDir, AuthoredCase) { let scratch = ScratchDir::new("admission").unwrap(); @@ -205,7 +202,6 @@ fn a_metal_row_from_an_earlier_oracle_needs_metal_qualification() { root.path(), case.clone(), device, - HOST_BACKEND, environment_id, "admission-candidate", // The run stops before any compile, so no worker is started. @@ -285,7 +281,6 @@ fn the_engine_candidate_is_admitted_whatever_its_loops() { root.path(), case.clone(), device, - HOST_BACKEND, "admission-oracle", "admission-candidate", // The run stops before any compile, so no worker is started. diff --git a/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs b/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs index e1ef556b3..f5982f1c3 100644 --- a/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs +++ b/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs @@ -614,7 +614,6 @@ fn dependencies<'a>( metal, spv_sha256: Some(SPV_SHA256), translator_fingerprint: TRANSLATOR, - backend: crate::observation::Backend::Vulkan, environment_id: "vk-env", executor_abi: "executor-v1", } diff --git a/crates/metal2vulkan-validation/src/index.rs b/crates/metal2vulkan-validation/src/index.rs index 6b0d9070c..24820ecd4 100644 --- a/crates/metal2vulkan-validation/src/index.rs +++ b/crates/metal2vulkan-validation/src/index.rs @@ -1,6 +1,6 @@ use crate::candidate::engine::{engine_fingerprint_of, is_engine_slot, ENGINE_EXECUTOR_ABI}; use crate::metal::ORACLE_ABI; -use crate::observation::{Backend, CandidateDependencies, MetalStatus}; +use crate::observation::{CandidateDependencies, MetalStatus}; use crate::source::{ private_store_present, public_source_set, shard_index_from_path, source_shards_dir, PublicSources, SourceIndexLocation, SourceRow, @@ -405,18 +405,6 @@ fn rebuild_index_counting( oracle_abi TEXT NOT NULL, PRIMARY KEY(case_id, environment_id) ); - CREATE TABLE candidate_observations ( - case_id TEXT NOT NULL REFERENCES cases(case_id), - backend TEXT NOT NULL, - environment_id TEXT NOT NULL, - input_sha256 TEXT NOT NULL, - golden_output_sha256 TEXT NOT NULL, - spv_sha256 TEXT NOT NULL, - translator_fingerprint TEXT NOT NULL, - executor_abi TEXT NOT NULL, - status TEXT NOT NULL, - PRIMARY KEY(case_id, backend, environment_id) - ); CREATE TABLE indexed_source_shards ( shard INTEGER PRIMARY KEY, size INTEGER NOT NULL, @@ -438,6 +426,9 @@ fn rebuild_index_counting( CREATE INDEX metal_case_dependencies ON metal_observations(case_id, input_sha256, oracle_abi);", ) .map_err(|error| format!("create index schema: {error}"))?; + connection + .execute_batch(CANDIDATE_TABLE) + .map_err(|error| format!("create candidate index table: {error}"))?; ensure_reference_gap_table(&connection)?; let transaction = connection .transaction() @@ -560,7 +551,7 @@ pub fn sync_index_with( .map_err(|error| format!("open index {}: {error}", destination.display()))?; keep_write_ahead_log(&connection, destination)?; ensure_source_location_columns(&connection)?; - ensure_candidate_fingerprint_column(&connection)?; + ensure_candidate_columns(&connection)?; ensure_case_tracking(&connection)?; ensure_reference_gap_table(&connection)?; connection @@ -1614,7 +1605,23 @@ fn ensure_source_membership_table(connection: &Connection) -> Result<(), String> .map_err(|error| format!("upgrade source-membership index: {error}")) } -fn ensure_candidate_fingerprint_column(connection: &Connection) -> Result<(), String> { +/// The candidate rows' table: one row per candidate observation, keyed by its slot. +const CANDIDATE_TABLE: &str = "CREATE TABLE candidate_observations ( + case_id TEXT NOT NULL REFERENCES cases(case_id), + environment_id TEXT NOT NULL, + input_sha256 TEXT NOT NULL, + golden_output_sha256 TEXT NOT NULL, + spv_sha256 TEXT NOT NULL, + translator_fingerprint TEXT NOT NULL, + executor_abi TEXT NOT NULL, + status TEXT NOT NULL, + PRIMARY KEY(case_id, environment_id) + );"; + +/// Give an older index's candidate table this build's columns ([`CANDIDATE_TABLE`]). The table +/// keeps nothing across syncs (each sync clears it and refills it from the shards), so a table +/// without `translator_fingerprint`, or with the former `backend` column, is made again. +fn ensure_candidate_columns(connection: &Connection) -> Result<(), String> { let mut statement = connection .prepare("PRAGMA table_info(candidate_observations)") .map_err(|error| format!("inspect candidate index columns: {error}"))?; @@ -1624,15 +1631,14 @@ fn ensure_candidate_fingerprint_column(connection: &Connection) -> Result<(), St .collect::, _>>() .map_err(|error| format!("read candidate index columns: {error}"))?; drop(statement); - if !columns.contains("translator_fingerprint") { - connection - .execute( - "ALTER TABLE candidate_observations ADD COLUMN translator_fingerprint TEXT NOT NULL DEFAULT ''", - [], - ) - .map_err(|error| format!("add translator_fingerprint index column: {error}"))?; + if columns.contains("translator_fingerprint") && !columns.contains("backend") { + return Ok(()); } - Ok(()) + connection + .execute_batch(&format!( + "DROP TABLE IF EXISTS candidate_observations; {CANDIDATE_TABLE}" + )) + .map_err(|error| format!("remake candidate index table: {error}")) } /// Lazily backfill byte locations for one private source shard. @@ -1751,18 +1757,17 @@ fn insert_compact_rows( ) .map_err(|error| format!("index Metal observation: {error}"))?; } - let backend = Backend::Vulkan; - for observation in store.read_candidates(backend)? { + for observation in store.read_candidates()? { if unavailable_cases.contains(&observation.case_id) { unavailable.candidate_observations += 1; continue; } transaction .execute( - "INSERT INTO candidate_observations (case_id, backend, environment_id, input_sha256, golden_output_sha256, spv_sha256, translator_fingerprint, executor_abi, status) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)", - params![observation.case_id, backend.directory(), observation.environment_id, observation.input_sha256, observation.golden_output_sha256, observation.spv_sha256.as_deref().unwrap_or_default(), observation.translator_fingerprint, observation.executor_abi, format!("{:?}", observation.status).to_ascii_lowercase()], + "INSERT INTO candidate_observations (case_id, environment_id, input_sha256, golden_output_sha256, spv_sha256, translator_fingerprint, executor_abi, status) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)", + params![observation.case_id, observation.environment_id, observation.input_sha256, observation.golden_output_sha256, observation.spv_sha256.as_deref().unwrap_or_default(), observation.translator_fingerprint, observation.executor_abi, format!("{:?}", observation.status).to_ascii_lowercase()], ) - .map_err(|error| format!("index {} observation: {error}", backend.directory()))?; + .map_err(|error| format!("index candidate observation: {error}"))?; } Ok(match public_keys { None => IndexScope::Complete, @@ -1884,7 +1889,7 @@ fn logical_snapshot(index: &Path) -> Result, String> { "SELECT 'case|' || quote(case_id) || '|' || quote(air_sha256) || '|' || quote(name) || '|' || quote(input_sha256) FROM cases ORDER BY case_id", "SELECT 'metal|' || quote(case_id) || '|' || quote(environment_id) || '|' || quote(input_sha256) || '|' || quote(output_sha256) || '|' || quote(oracle_abi) FROM metal_observations ORDER BY case_id, environment_id", "SELECT 'metal-gap|' || quote(case_id) || '|' || quote(environment_id) || '|' || quote(input_sha256) || '|' || quote(apple_family) || '|' || quote(oracle_abi) FROM metal_reference_gaps ORDER BY case_id, environment_id", - "SELECT 'candidate|' || quote(case_id) || '|' || quote(backend) || '|' || quote(environment_id) || '|' || quote(input_sha256) || '|' || quote(golden_output_sha256) || '|' || quote(spv_sha256) || '|' || quote(translator_fingerprint) || '|' || quote(executor_abi) || '|' || quote(status) FROM candidate_observations ORDER BY case_id, backend, environment_id", + "SELECT 'candidate|' || quote(case_id) || '|' || quote(environment_id) || '|' || quote(input_sha256) || '|' || quote(golden_output_sha256) || '|' || quote(spv_sha256) || '|' || quote(translator_fingerprint) || '|' || quote(executor_abi) || '|' || quote(status) FROM candidate_observations ORDER BY case_id, environment_id", "SELECT 'source-shard|' || quote(shard) || '|' || quote(size) || '|' || quote(modified_ns) FROM indexed_source_shards ORDER BY shard", ]; let mut snapshot = Vec::new(); @@ -1995,14 +2000,11 @@ pub fn evidence_status( }); let metals = store.read_metal()?; // The engine slots only: the old engine's rows are no evidence (cutover X2b). - let engine_rows = |backend| { - store.read_candidates(backend).map(|rows| { - rows.into_iter() - .filter(|row| is_engine_slot(&row.environment_id)) - .collect::>() - }) - }; - let vulkan = engine_rows(Backend::Vulkan)?; + let vulkan = store + .read_candidates()? + .into_iter() + .filter(|row| is_engine_slot(&row.environment_id)) + .collect::>(); let (judge, _) = crate::c3::reference::Judge::new(references, &cases, &metals); let mut rows = Vec::new(); for case in cases { @@ -2047,8 +2049,7 @@ pub fn evidence_status( } else { EvidenceState::Stale }; - let vulkan_state = - candidate_state(&case, Backend::Vulkan, ¤t_metals, &vulkan, venues); + let vulkan_state = candidate_state(&case, ¤t_metals, &vulkan, venues); let mut slots = case_metals .iter() .map(|observation| EvidenceSlot { @@ -2062,15 +2063,9 @@ pub fn evidence_status( .iter() .filter(|observation| observation.case_id == case.case_id) .map(|observation| EvidenceSlot { - backend: Backend::Vulkan.directory(), + backend: "vulkan", environment_id: observation.environment_id.clone(), - state: candidate_slot_state( - &case, - Backend::Vulkan, - ¤t_metals, - observation, - venues, - ), + state: candidate_slot_state(&case, ¤t_metals, observation, venues), }), ); slots.sort_by(|left, right| { @@ -2090,10 +2085,9 @@ pub fn evidence_status( Ok(rows) } -/// The summary of `case`'s `backend` slots among `candidates`. +/// The summary of `case`'s slots among `candidates`. fn candidate_state( case: &crate::case::AuthoredCase, - backend: Backend, metals: &[&crate::observation::MetalObservation], candidates: &[crate::observation::CandidateObservation], venues: &crate::c3::VenueKeys, @@ -2107,7 +2101,7 @@ fn candidate_state( } let states = candidates .iter() - .map(|candidate| candidate_slot_state(case, backend, metals, candidate, venues)) + .map(|candidate| candidate_slot_state(case, metals, candidate, venues)) .collect::>(); summarize_existing_states(&states) } @@ -2177,9 +2171,8 @@ pub enum Dependency { /// profile its venue holds that slot to ([`crate::c3::VenueKeys::holds`]). A record in any /// other slot is no venue's, and holds it. Venue, - /// Every other dependency: its content or comparison class, its case's AIR or inputs, its - /// backend, or, for a row, a current Metal row it compared against with the status it - /// records. + /// Every other dependency: its content or comparison class, its case's AIR or inputs, or, for + /// a row, a current Metal row it compared against with the status it records. Other, } @@ -2257,7 +2250,7 @@ impl std::fmt::Debug for Staleness { } } -/// [`Staleness`] of one candidate row of `case` in `backend` under this build. `metals` are the +/// [`Staleness`] of one candidate row of `case` under this build. `metals` are the /// case's current Metal rows (`MetalObservation::dependency_matches` under the current oracle): /// the row's Metal dependency holds when one of them is the row it compared against and the /// recorded status is the verdict of its class on that row's output. `venues` holds each venue's @@ -2265,7 +2258,6 @@ impl std::fmt::Debug for Staleness { /// product while it executed this build's artifact. pub(crate) fn candidate_staleness( case: &crate::case::AuthoredCase, - backend: Backend, metals: &[&crate::observation::MetalObservation], candidate: &crate::observation::CandidateObservation, venues: &crate::c3::VenueKeys, @@ -2288,16 +2280,11 @@ pub(crate) fn candidate_staleness( ( Dependency::Product, same_build - || venues.artifact_is_current( - backend, - &candidate.environment_id, - &case.case_id, - executed, - ), + || venues.artifact_is_current(&candidate.environment_id, &case.case_id, executed), ), ( Dependency::Venue, - venues.holds(backend, &candidate.environment_id, &candidate.environment), + venues.holds(&candidate.environment_id, &candidate.environment), ), // Every other dependency, the build's own facts taken as the row records them. ( @@ -2308,7 +2295,6 @@ pub(crate) fn candidate_staleness( metal, spv_sha256: candidate.spv_sha256.as_deref(), translator_fingerprint: &candidate.translator_fingerprint, - backend, environment_id: &candidate.environment_id, executor_abi: &candidate.executor_abi, }) @@ -2322,12 +2308,11 @@ pub(crate) fn candidate_staleness( /// `metals` are the case's current Metal rows. pub(crate) fn candidate_slot_state( case: &crate::case::AuthoredCase, - backend: Backend, metals: &[&crate::observation::MetalObservation], candidate: &crate::observation::CandidateObservation, venues: &crate::c3::VenueKeys, ) -> EvidenceState { - if !candidate_staleness(case, backend, metals, candidate, venues).is_current() { + if !candidate_staleness(case, metals, candidate, venues).is_current() { return EvidenceState::Stale; } match candidate.status { @@ -2336,15 +2321,14 @@ pub(crate) fn candidate_slot_state( } } -/// [`Staleness`] of a refusal record of `case` (`crate::refusal`) in `backend` under this build, by +/// [`Staleness`] of a refusal record of `case` (`crate::refusal`) under this build, by /// the rule a row is held to: the new executor's ABI, the translator fingerprint this product /// derives from the profile fingerprint it recorded (or, for a venue's refusal made after it /// compiled, this build's artifact), for a venue's refusal the venue profile `venues` holds its -/// slot to, and a well-formed record of this case's AIR and inputs in `backend`. A refusal compares +/// slot to, and a well-formed record of this case's AIR and inputs. A refusal compares /// nothing with Metal, so no Metal row is a dependency. pub(crate) fn refusal_staleness( case: &crate::case::AuthoredCase, - backend: Backend, refusal: &crate::refusal::RefusalObservation, venues: &crate::c3::VenueKeys, ) -> Staleness { @@ -2357,7 +2341,6 @@ pub(crate) fn refusal_staleness( Dependency::Product, this_build(&refusal.environment, &refusal.translator_fingerprint) || venues.artifact_is_current( - backend, &refusal.environment_id, &case.case_id, refusal.artifact.as_ref(), @@ -2365,7 +2348,7 @@ pub(crate) fn refusal_staleness( ), ( Dependency::Venue, - venues.holds(backend, &refusal.environment_id, &refusal.environment), + venues.holds(&refusal.environment_id, &refusal.environment), ), ( Dependency::Other, @@ -2374,8 +2357,7 @@ pub(crate) fn refusal_staleness( && refusal.air_sha256 == case.air_sha256 && case .computed_input_sha256() - .is_ok_and(|digest| digest == refusal.input_sha256) - && refusal.backend == backend, + .is_ok_and(|digest| digest == refusal.input_sha256), ), ]) } @@ -2384,11 +2366,10 @@ pub(crate) fn refusal_staleness( /// report judges refusals by it (`c3`). pub(crate) fn refusal_is_current( case: &crate::case::AuthoredCase, - backend: Backend, refusal: &crate::refusal::RefusalObservation, venues: &crate::c3::VenueKeys, ) -> bool { - refusal_staleness(case, backend, refusal, venues).is_current() + refusal_staleness(case, refusal, venues).is_current() } #[cfg(test)] @@ -2400,7 +2381,7 @@ mod tests { ResourceRole, Stage, }; use crate::observation::{ - CandidateObservation, CandidateStatus, MetalObservation, MetalStatus, + Backend, CandidateObservation, CandidateStatus, MetalObservation, MetalStatus, }; use crate::observation_contract::ComparisonClass; use crate::source::public_sources; @@ -3072,7 +3053,6 @@ mod tests { let state = |candidate: &CandidateObservation| { candidate_slot_state( &case, - Backend::Vulkan, &[&metal], candidate, &crate::c3::VenueKeys::default(), @@ -3199,11 +3179,11 @@ mod tests { row.environment[crate::c3::VENUE_PROFILE] = base.record(); let keys = |profile: &crate::c3::VenueProfile| { let mut keys = crate::c3::VenueKeys::default(); - keys.insert("toy-env", Backend::Vulkan, &profile.fingerprint, "toy"); + keys.insert("toy-env", &profile.fingerprint, "toy"); keys }; let state = |row: &CandidateObservation, keys: &crate::c3::VenueKeys| { - candidate_slot_state(&case, Backend::Vulkan, &[&metal], row, keys) + candidate_slot_state(&case, &[&metal], row, keys) }; assert_eq!(state(&row, &keys(&base)), EvidenceState::Current); let refusal = crate::refusal::RefusalObservation { @@ -3221,12 +3201,7 @@ mod tests { ), artifact: None, }; - assert!(refusal_is_current( - &case, - Backend::Vulkan, - &refusal, - &keys(&base) - )); + assert!(refusal_is_current(&case, &refusal, &keys(&base))); for (what, edit) in edits { let moved = venue_profile(edit); assert_ne!(moved.fingerprint, base.fingerprint, "{what} moves no key"); @@ -3236,7 +3211,7 @@ mod tests { "a row of the profile before {what} changed" ); assert!( - !refusal_is_current(&case, Backend::Vulkan, &refusal, &keys(&moved)), + !refusal_is_current(&case, &refusal, &keys(&moved)), "a refusal of the profile before {what} changed" ); } @@ -3282,7 +3257,6 @@ mod tests { let state = |candidate: &CandidateObservation| { candidate_slot_state( &case, - Backend::Vulkan, &[&metal], candidate, &crate::c3::VenueKeys::default(), @@ -3310,13 +3284,7 @@ mod tests { let old = old_engine_row(&case); assert_eq!(state(&old), EvidenceState::Stale); assert_eq!( - candidate_staleness( - &case, - Backend::Vulkan, - &[&metal], - &old, - &crate::c3::VenueKeys::default() - ), + candidate_staleness(&case, &[&metal], &old, &crate::c3::VenueKeys::default()), Staleness::of([Dependency::Executor, Dependency::Product]) ); // A current row whose output differs from Metal's is a failure, not staleness. @@ -3340,13 +3308,13 @@ mod tests { let none = crate::c3::VenueKeys::default(); // The candidate's own slot held to a key it did not record. let mut keyed = crate::c3::VenueKeys::default(); - keyed.insert("toy-env", Backend::Vulkan, &"77".repeat(32), "toy"); + keyed.insert("toy-env", &"77".repeat(32), "toy"); assert_eq!( - keyed.expected(Backend::Vulkan, &candidate.environment_id), + keyed.expected(&candidate.environment_id), Some("77".repeat(32).as_str()) ); let staleness = |candidate: &CandidateObservation| { - candidate_staleness(&case, Backend::Vulkan, &[&metal], candidate, &none) + candidate_staleness(&case, &[&metal], candidate, &none) }; let only = |executor: bool, product: bool, venue: bool, other: bool| { Staleness::judge([ @@ -3358,11 +3326,11 @@ mod tests { }; assert!(staleness(&candidate).is_current()); assert_eq!( - candidate_slot_state(&case, Backend::Vulkan, &[&metal], &candidate, &none), + candidate_slot_state(&case, &[&metal], &candidate, &none), EvidenceState::Current ); assert_eq!( - candidate_staleness(&case, Backend::Vulkan, &[&metal], &candidate, &keyed), + candidate_staleness(&case, &[&metal], &candidate, &keyed), only(false, false, true, false) ); let mut executor = candidate.clone(); @@ -3376,7 +3344,7 @@ mod tests { assert_eq!(staleness(&both), only(true, true, false, false)); for row in [&executor, &product, &both] { assert_eq!( - candidate_slot_state(&case, Backend::Vulkan, &[&metal], row, &none), + candidate_slot_state(&case, &[&metal], row, &none), EvidenceState::Stale ); } @@ -3397,7 +3365,7 @@ mod tests { assert_eq!(staleness(&censused), only(false, true, false, false)); // No current Metal row: another dependency. assert_eq!( - candidate_staleness(&case, Backend::Vulkan, &[], &candidate, &none), + candidate_staleness(&case, &[], &candidate, &none), only(false, false, false, true) ); @@ -3417,13 +3385,12 @@ mod tests { ), artifact: None, }; - let judged = |refusal: &crate::refusal::RefusalObservation| { - refusal_staleness(&case, Backend::Vulkan, refusal, &none) - }; + let judged = + |refusal: &crate::refusal::RefusalObservation| refusal_staleness(&case, refusal, &none); assert!(judged(&refusal).is_current()); - assert!(refusal_is_current(&case, Backend::Vulkan, &refusal, &none)); + assert!(refusal_is_current(&case, &refusal, &none)); assert_eq!( - refusal_staleness(&case, Backend::Vulkan, &refusal, &keyed), + refusal_staleness(&case, &refusal, &keyed), only(false, false, true, false) ); let mut executor = refusal.clone(); @@ -3516,7 +3483,7 @@ mod tests { // What the binaries judge by: the venue's key, and the corpus's file at this build. let keys = || { let mut keys = crate::c3::VenueKeys::default(); - keys.insert("toy-env", Backend::Vulkan, &profile.fingerprint, "toy"); + keys.insert("toy-env", &profile.fingerprint, "toy"); keys.with_artifacts(CurrentArtifacts::load(root).unwrap()) }; let judged = || { @@ -3525,9 +3492,8 @@ mod tests { .remove(0) .vulkan }; - let staleness = |row: &CandidateObservation| { - candidate_staleness(&case, Backend::Vulkan, &[&metal], row, &keys()) - }; + let staleness = + |row: &CandidateObservation| candidate_staleness(&case, &[&metal], row, &keys()); let product = Staleness::of([Dependency::Product]); // No file: the build that recorded it. @@ -3574,17 +3540,16 @@ mod tests { // The slot is judged on its profile's digest; a slot no venue keys, on its build alone. bless(&ArtifactBuild::this(), &digest); let stated_slot = engine_environment_id("toy-env"); - let current = |slot: &str, backend: Backend, sha256: &str| { + let current = |slot: &str, sha256: &str| { keys().artifact_is_current( - backend, slot, &case.case_id, executed(Some(sha256), RUNTIME_VERSION).as_ref(), ) }; - assert!(current(&stated_slot, Backend::Vulkan, &digest)); - assert!(!current(&stated_slot, Backend::Vulkan, &moved)); - assert!(!current("another-env@engine", Backend::Vulkan, &digest)); + assert!(current(&stated_slot, &digest)); + assert!(!current(&stated_slot, &moved)); + assert!(!current("another-env@engine", &digest)); // A refusal the venue's run made after it compiled is held to the same digest. let mut refusal = crate::refusal::RefusalObservation { @@ -3602,24 +3567,11 @@ mod tests { ), artifact: executed(Some(&digest), RUNTIME_VERSION), }; - assert!(refusal_is_current( - &case, - Backend::Vulkan, - &refusal, - &keys() - )); + assert!(refusal_is_current(&case, &refusal, &keys())); refusal.artifact = executed(Some(&moved), RUNTIME_VERSION); - assert_eq!( - refusal_staleness(&case, Backend::Vulkan, &refusal, &keys()), - product - ); + assert_eq!(refusal_staleness(&case, &refusal, &keys()), product); bless(&another_build, &moved); - assert!(!refusal_is_current( - &case, - Backend::Vulkan, - &refusal, - &keys() - )); + assert!(!refusal_is_current(&case, &refusal, &keys())); } /// The currency rule's one decision: a record is stale in exactly the dependencies whose check diff --git a/crates/metal2vulkan-validation/src/observation.rs b/crates/metal2vulkan-validation/src/observation.rs index d85ea0751..a18aca5de 100644 --- a/crates/metal2vulkan-validation/src/observation.rs +++ b/crates/metal2vulkan-validation/src/observation.rs @@ -215,20 +215,14 @@ pub struct CandidateObservation { pub status: CandidateStatus, } +/// The backend a stored candidate row or refusal names: always `vulkan`, the rows' literal +/// field, which no reader decides anything by. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum Backend { Vulkan, } -impl Backend { - pub fn directory(self) -> &'static str { - match self { - Self::Vulkan => "vulkan", - } - } -} - #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum CandidateStatus { @@ -348,7 +342,6 @@ pub struct CandidateDependencies<'a> { pub metal: &'a MetalObservation, pub spv_sha256: Option<&'a str>, pub translator_fingerprint: &'a str, - pub backend: Backend, pub environment_id: &'a str, pub executor_abi: &'a str, } @@ -514,7 +507,6 @@ impl CandidateObservation { && self.golden_output_sha256 == dependencies.metal.metal_output_sha256 && self.spv_sha256.as_deref() == dependencies.spv_sha256 && self.translator_fingerprint == dependencies.translator_fingerprint - && self.backend == dependencies.backend && self.environment_id == dependencies.environment_id && self.executor_abi == dependencies.executor_abi && base64::engine::general_purpose::STANDARD @@ -822,7 +814,6 @@ mod tests { metal: &metal, spv_sha256: Some(&spv_sha256), translator_fingerprint: &candidate.translator_fingerprint, - backend: Backend::Vulkan, environment_id: "vk-env", executor_abi: "executor-v1", }; diff --git a/crates/metal2vulkan-validation/src/store.rs b/crates/metal2vulkan-validation/src/store.rs index 7f1c79a43..0406dffd5 100644 --- a/crates/metal2vulkan-validation/src/store.rs +++ b/crates/metal2vulkan-validation/src/store.rs @@ -1,6 +1,6 @@ use crate::case::{AuthoredCase, OutputSelection}; use crate::jsonl::to_sorted_json_string; -use crate::observation::{Backend, CandidateObservation, MetalObservation}; +use crate::observation::{CandidateObservation, MetalObservation}; use crate::refusal::RefusalObservation; use crate::source::{shard_index_for_hash, shard_index_from_path, shard_name}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; @@ -99,20 +99,8 @@ impl CorpusStore { let mut errors = Vec::new(); shard_layout_errors::(&self.root, "cases", &mut errors)?; shard_layout_errors::(&self.root, "observations/metal", &mut errors)?; - shard_layout_errors::( - &self.root, - "observations/vulkan", - &mut errors, - )?; - let backend = Backend::Vulkan; - let directory = refusal_directory(backend); - shard_layout_errors::( - &self.root, - directory - .to_str() - .ok_or("the refusal directory is not UTF-8")?, - &mut errors, - )?; + shard_layout_errors::(&self.root, CANDIDATE_DIRECTORY, &mut errors)?; + shard_layout_errors::(&self.root, REFUSAL_DIRECTORY, &mut errors)?; Ok(errors) } @@ -302,16 +290,13 @@ impl CorpusStore { let name = shard_name(index); let case_path = PathBuf::from("cases").join(&name); let metal_path = PathBuf::from("observations/metal").join(&name); - let vulkan_path = PathBuf::from("observations/vulkan").join(&name); + let vulkan_path = PathBuf::from(CANDIDATE_DIRECTORY).join(&name); let mut metal: Vec> = read_stored_if_exists(&self.root.join(&metal_path))?; let mut vulkan: Vec> = read_stored_if_exists(&self.root.join(&vulkan_path))?; validate_aligned_observation_rows(rows_of(&metal), index)?; validate_aligned_observation_rows(rows_of(&vulkan), index)?; - if rows_of(&vulkan).any(|row| row.backend != Backend::Vulkan) { - return Err("candidate observation is stored in the wrong backend directory".into()); - } reject_duplicate_metal_slots(rows_of(&metal))?; reject_duplicate_candidate_slots(rows_of(&vulkan))?; if let Some(case_id) = cascaded_case_id { @@ -329,9 +314,9 @@ impl CorpusStore { let mut deletions = Vec::new(); // A refusal follows its case as a row does; a refusal shard the bucket does not have is // not created. - let path = refusal_directory(Backend::Vulkan).join(&name); + let path = PathBuf::from(REFUSAL_DIRECTORY).join(&name); if self.root.join(&path).exists() { - let mut refusals = self.read_refusal_shard(&path, index, Backend::Vulkan)?; + let mut refusals = self.read_refusal_shard(&path, index)?; if let Some(case_id) = cascaded_case_id { refusals.retain(|stored| stored.row.case_id != case_id); } @@ -344,22 +329,15 @@ impl CorpusStore { self.commit_changes(files, deletions) } - /// The refusal shard `relative` (shard `index` of `backend`'s refusals), validated. + /// The refusal shard `relative` (shard `index` of the refusals), validated. fn read_refusal_shard( &self, relative: &Path, index: usize, - backend: Backend, ) -> Result>, String> { let rows: Vec> = read_stored_if_exists(&self.root.join(relative))?; validate_aligned_observation_rows(rows_of(&rows), index)?; - if rows_of(&rows).any(|row| row.backend != backend) { - return Err(format!( - "a refusal is stored outside its {} directory", - backend.directory() - )); - } reject_duplicate_refusal_slots(rows_of(&rows))?; Ok(rows) } @@ -401,24 +379,17 @@ impl CorpusStore { &row.input_sha256, Some(&row.output_b64), )?; - let relative = PathBuf::from("observations") - .join(row.backend.directory()) - .join(shard_name(index)); + let relative = PathBuf::from(CANDIDATE_DIRECTORY).join(shard_name(index)); let mut rows: Vec> = read_stored_if_exists(&self.root.join(&relative))?; validate_aligned_observation_rows(rows_of(&rows), index)?; - if rows_of(&rows).any(|existing| existing.backend != row.backend) { - return Err("candidate observation is stored in the wrong backend directory".into()); - } reject_duplicate_candidate_slots(rows_of(&rows))?; rows.retain(|old| { - !(old.row.case_id == row.case_id - && old.row.backend == row.backend - && old.row.environment_id == row.environment_id) + !(old.row.case_id == row.case_id && old.row.environment_id == row.environment_id) }); // A slot holds a row or a refusal, never both: the row replaces the slot's refusal. - let refusal_path = refusal_directory(row.backend).join(shard_name(index)); - let mut refusals = self.read_refusal_shard(&refusal_path, index, row.backend)?; + let refusal_path = PathBuf::from(REFUSAL_DIRECTORY).join(shard_name(index)); + let mut refusals = self.read_refusal_shard(&refusal_path, index)?; let refused = refusals.len(); refusals.retain(|old| { !(old.row.case_id == row.case_id && old.row.environment_id == row.environment_id) @@ -454,16 +425,13 @@ impl CorpusStore { &refusal.air_sha256, &refusal.input_sha256, )?; - let backend = refusal.backend; - let refusal_path = refusal_directory(backend).join(shard_name(index)); - let mut refusals = self.read_refusal_shard(&refusal_path, index, backend)?; + let refusal_path = PathBuf::from(REFUSAL_DIRECTORY).join(shard_name(index)); + let mut refusals = self.read_refusal_shard(&refusal_path, index)?; refusals.retain(|old| { !(old.row.case_id == refusal.case_id && old.row.environment_id == refusal.environment_id) }); - let row_path = PathBuf::from("observations") - .join(backend.directory()) - .join(shard_name(index)); + let row_path = PathBuf::from(CANDIDATE_DIRECTORY).join(shard_name(index)); let mut rows: Vec> = read_stored_if_exists(&self.root.join(&row_path))?; validate_aligned_observation_rows(rows_of(&rows), index)?; @@ -482,7 +450,7 @@ impl CorpusStore { self.commit_changes(files, Vec::new()) } - /// Rewrite every venue row and refusal, of either backend, that recorded a rekey's `from` to + /// Rewrite every venue row and refusal that recorded a rekey's `from` to /// record its `to` ([`crate::c3::VenueRekey`], which the caller has checked), in one /// recoverable transaction. Every other line of every shard keeps its bytes; a rewritten one is /// serialized as the store writes rows. Returns how many rows and refusals each rekey rewrote. @@ -494,8 +462,7 @@ impl CorpusStore { self.recover_transactions()?; let mut counts = vec![(0, 0); rekeys.len()]; let mut files = Vec::new(); - let backend = Backend::Vulkan; - let rows_dir = PathBuf::from("observations").join(backend.directory()); + let rows_dir = PathBuf::from(CANDIDATE_DIRECTORY); for path in shard_paths(&self.root.join(&rows_dir))? { let mut rows: Vec> = read_stored_if_exists(&path)?; let rewritten = rekey_stored(&mut rows, rekeys, |row| &mut row.environment); @@ -509,7 +476,7 @@ impl CorpusStore { )); } } - let refusals_dir = refusal_directory(backend); + let refusals_dir = PathBuf::from(REFUSAL_DIRECTORY); for path in shard_paths(&self.root.join(&refusals_dir))? { let mut refusals: Vec> = read_stored_if_exists(&path)?; let rewritten = rekey_stored(&mut refusals, rekeys, |row| &mut row.environment); @@ -529,16 +496,10 @@ impl CorpusStore { Ok(counts) } - /// Every refusal of `backend`, each of a known case with its AIR and inputs, no slot twice. - pub fn read_refusals(&self, backend: Backend) -> Result, String> { + /// Every refusal, each of a known case with its AIR and inputs, no slot twice. + pub fn read_refusals(&self) -> Result, String> { let rows: Vec = - read_aligned_observations(&self.root.join(refusal_directory(backend)))?; - if rows.iter().any(|row| row.backend != backend) { - return Err(format!( - "a refusal is stored outside its {} directory", - backend.directory() - )); - } + read_aligned_observations(&self.root.join(REFUSAL_DIRECTORY))?; reject_duplicate_refusal_slots(&rows)?; let cases = self.read_all_cases()?; let cases = cases @@ -643,18 +604,11 @@ impl CorpusStore { Ok(rows) } - pub fn read_candidates(&self, backend: Backend) -> Result, String> { + pub fn read_candidates(&self) -> Result, String> { let rows: Vec = - read_aligned_observations(&self.root.join("observations").join(backend.directory()))?; + read_aligned_observations(&self.root.join(CANDIDATE_DIRECTORY))?; for row in &rows { row.validate_content()?; - if row.backend != backend { - return Err(format!( - "{} observation found in {} directory", - row.backend.directory(), - backend.directory() - )); - } } self.validate_observation_cases(rows.iter().map(|row| { ( @@ -932,7 +886,7 @@ fn shard_paths(directory: &Path) -> Result, String> { /// A row of an aligned shard: the AIR whose hash places it in its shard, and the key its shard is /// ordered by. Every writer of case and observation shards sorts a shard it writes by /// [`ShardRow::order_key`] through [`sort_stored`]. The key names one slot (a case's name within -/// its AIR, or a Metal or candidate experiment slot within a backend's directory), so a shard's +/// its AIR, or a Metal or candidate experiment slot), so a shard's /// keys strictly increase. pub(crate) trait ShardRow: DeserializeOwned { fn air_sha256(&self) -> &str; @@ -959,8 +913,7 @@ impl ShardRow for MetalObservation { } } -/// A candidate shard holds one backend's rows (its directory), so its slot is the case and the -/// environment. +/// A refusal's slot is its case and its environment, as a candidate row's is. impl ShardRow for RefusalObservation { fn air_sha256(&self) -> &str { &self.air_sha256 @@ -1178,21 +1131,21 @@ fn reject_duplicate_refusal_slots<'a>( Ok(()) } -/// Where `backend`'s refusals are stored, relative to the corpus root (`observations/refusals/ -/// `), sharded by AIR as its rows are. -pub fn refusal_directory(backend: Backend) -> PathBuf { - PathBuf::from("observations/refusals").join(backend.directory()) -} +/// Where the candidate rows are stored, relative to the corpus root, sharded by AIR. +pub const CANDIDATE_DIRECTORY: &str = "observations/vulkan"; + +/// Where the refusals are stored, relative to the corpus root, sharded by AIR as the rows are. +pub const REFUSAL_DIRECTORY: &str = "observations/refusals/vulkan"; fn reject_duplicate_candidate_slots<'a>( rows: impl IntoIterator, ) -> Result<(), String> { let mut slots = std::collections::HashSet::new(); for row in rows { - if !slots.insert((&row.case_id, row.backend, &row.environment_id)) { + if !slots.insert((&row.case_id, &row.environment_id)) { return Err(format!( - "duplicate candidate experiment slot ({}, {:?}, {})", - row.case_id, row.backend, row.environment_id + "duplicate candidate experiment slot ({}, {})", + row.case_id, row.environment_id )); } } @@ -1243,7 +1196,7 @@ mod tests { use crate::case::{ BufferResource, Comparison, Dispatch, ExecutionSafety, OutputSelection, ResourceRole, Stage, }; - use crate::observation::{CandidateStatus, MetalStatus}; + use crate::observation::{Backend, CandidateStatus, MetalStatus}; use crate::observation_contract::ComparisonClass; use crate::ScratchDir; use std::collections::BTreeMap; @@ -1446,11 +1399,7 @@ mod tests { assert!(store.read_metal_of_case(&case).is_err()); } - fn candidate( - case: &AuthoredCase, - backend: Backend, - environment_id: &str, - ) -> CandidateObservation { + fn candidate(case: &AuthoredCase, environment_id: &str) -> CandidateObservation { let output_sha256 = crate::hash::sha256_bytes(&[42, 0, 0, 0]); CandidateObservation { timing: Some(crate::observation::test_timing()), @@ -1462,7 +1411,7 @@ mod tests { translator_fingerprint: "44".repeat(32), candidate_output_sha256: output_sha256, output_b64: "KgAAAA==".into(), - backend, + backend: Backend::Vulkan, environment_id: environment_id.into(), environment: serde_json::json!({}), executor_abi: "v1".into(), @@ -1521,18 +1470,16 @@ mod tests { crate::observation::test_timing().least_micros ); - let mut untimed = candidate(&case, Backend::Vulkan, "vk-env"); + let mut untimed = candidate(&case, "vk-env"); untimed.timing = None; let refused = store.upsert_candidate(untimed).unwrap_err(); assert!( refused.contains("records no timing") && refused.contains("vk-env"), "{refused}" ); - assert!(store.read_candidates(Backend::Vulkan).unwrap().is_empty()); - store - .upsert_candidate(candidate(&case, Backend::Vulkan, "vk-env")) - .unwrap(); - let mut rows = store.read_candidates(Backend::Vulkan).unwrap(); + assert!(store.read_candidates().unwrap().is_empty()); + store.upsert_candidate(candidate(&case, "vk-env")).unwrap(); + let mut rows = store.read_candidates().unwrap(); assert_eq!(rows.len(), 1); assert!(rows.pop().unwrap().timing.is_some()); @@ -1545,9 +1492,9 @@ mod tests { refused.contains("records no timing") && refused.contains("env@engine"), "{refused}" ); - assert!(store.read_refusals(Backend::Vulkan).unwrap().is_empty()); + assert!(store.read_refusals().unwrap().is_empty()); store.upsert_refusal(refusal(&case, "env@engine")).unwrap(); - let mut refusals = store.read_refusals(Backend::Vulkan).unwrap(); + let mut refusals = store.read_refusals().unwrap(); assert_eq!(refusals.len(), 1); assert!(refusals.pop().unwrap().timing.is_some()); @@ -1596,7 +1543,7 @@ mod tests { for case in [&first, &second] { for environment in ["env-b", "env-a"] { store - .upsert_candidate(candidate(case, Backend::Vulkan, environment)) + .upsert_candidate(candidate(case, environment)) .unwrap(); } } @@ -1645,9 +1592,7 @@ mod tests { let store = CorpusStore::new(scratch.path()); let case = make_case("slot", "AAAAAA=="); store.put_case(case.clone()).unwrap(); - store - .upsert_candidate(candidate(&case, Backend::Vulkan, "mvk-env")) - .unwrap(); + store.upsert_candidate(candidate(&case, "mvk-env")).unwrap(); // A valid row in a form a rewrite would not keep (a trailing space), as legacy rows are. let shard = shard_name(shard_index_for_hash(&case.air_sha256).unwrap()); let shard_file = scratch.path().join("observations/vulkan").join(&shard); @@ -1665,7 +1610,7 @@ mod tests { assert_eq!(store.read_all_cases().unwrap(), vec![annotated]); // The observation shards are not rewritten at all. assert_eq!(std::fs::read(&shard_file).unwrap(), observations); - assert_eq!(store.read_candidates(Backend::Vulkan).unwrap().len(), 1); + assert_eq!(store.read_candidates().unwrap().len(), 1); let mut renamed = case.clone(); renamed.name = "other".into(); let error = store.put_case(renamed).unwrap_err(); @@ -1685,7 +1630,7 @@ mod tests { let store = CorpusStore::new(scratch.path()); let case = make_case("slot", "AAAAAA=="); store.put_case(case.clone()).unwrap(); - let mut old = candidate(&case, Backend::Vulkan, "env-old"); + let mut old = candidate(&case, "env-old"); old.census = Some(ExecutedCensus { device: None, product: "p".into(), @@ -1742,13 +1687,11 @@ mod tests { .join(",") ); fs::write(&metal, &reversed).unwrap(); - assert_eq!(store.read_candidates(Backend::Vulkan).unwrap().len(), 1); + assert_eq!(store.read_candidates().unwrap().len(), 1); assert_eq!(store.read_metal().unwrap().len(), 1); // A row of another slot in the same shard: the legacy row stays as it was. - store - .upsert_candidate(candidate(&case, Backend::Vulkan, "env-new")) - .unwrap(); + store.upsert_candidate(candidate(&case, "env-new")).unwrap(); let lines = fs::read_to_string(&shard_file).unwrap(); assert!( lines.lines().any(|line| line == legacy.trim_end()), @@ -1775,7 +1718,7 @@ mod tests { .unwrap(); store.put_case(make_case("other", "AQAAAA==")).unwrap(); store - .upsert_candidate(candidate(&case, Backend::Vulkan, "env@engine")) + .upsert_candidate(candidate(&case, "env@engine")) .unwrap(); let lines = fs::read_to_string(&shard_file).unwrap(); assert!( @@ -1809,9 +1752,7 @@ mod tests { status: MetalStatus::Qualified, }) .unwrap(); - store - .upsert_candidate(candidate(case, Backend::Vulkan, "vk-env")) - .unwrap(); + store.upsert_candidate(candidate(case, "vk-env")).unwrap(); } let replacement = make_case("slot", "AgAAAA=="); @@ -1828,8 +1769,7 @@ mod tests { let metal = store.read_metal().unwrap(); assert_eq!(metal.len(), 1); assert_eq!(metal[0].case_id, sibling.case_id); - let backend = Backend::Vulkan; - let rows = store.read_candidates(backend).unwrap(); + let rows = store.read_candidates().unwrap(); assert_eq!(rows.len(), 1); assert_eq!(rows[0].case_id, sibling.case_id); } @@ -1858,14 +1798,11 @@ mod tests { store.upsert_metal(row.clone()).unwrap(); assert_eq!(store.read_metal().unwrap(), vec![row]); - let mut candidate = candidate(&case, Backend::Vulkan, "env"); + let mut candidate = candidate(&case, "env"); store.upsert_candidate(candidate.clone()).unwrap(); candidate.spv_sha256 = Some("44".repeat(32)); store.upsert_candidate(candidate.clone()).unwrap(); - assert_eq!( - store.read_candidates(Backend::Vulkan).unwrap(), - vec![candidate] - ); + assert_eq!(store.read_candidates().unwrap(), vec![candidate]); } /// A context the profiles layer restricts without a request opens and runs, but the row it @@ -1876,7 +1813,7 @@ mod tests { let store = CorpusStore::new(scratch.path()); let case = make_case("restricted", "AAAAAA=="); store.put_case(case.clone()).unwrap(); - let mut row = candidate(&case, Backend::Vulkan, "env"); + let mut row = candidate(&case, "env"); row.environment = serde_json::json!({ "tools": [ {"layer": "VK_LAYER_KHRONOS_validation"}, @@ -1885,12 +1822,12 @@ mod tests { }); let refused = store.upsert_candidate(row.clone()).unwrap_err(); assert!(refused.contains("requested no restriction"), "{refused}"); - assert_eq!(store.read_candidates(Backend::Vulkan).unwrap(), vec![]); + assert_eq!(store.read_candidates().unwrap(), vec![]); row.environment = serde_json::json!({ "tools": [{"layer": "VK_LAYER_KHRONOS_validation"}], }); store.upsert_candidate(row.clone()).unwrap(); - assert_eq!(store.read_candidates(Backend::Vulkan).unwrap(), vec![row]); + assert_eq!(store.read_candidates().unwrap(), vec![row]); } #[test] @@ -1919,7 +1856,7 @@ mod tests { store.upsert_metal(empty_metal.clone()).unwrap(); assert_eq!(store.read_metal().unwrap(), vec![empty_metal]); - let mut nonempty_for_none = candidate(&empty_case, Backend::Vulkan, "vk-env"); + let mut nonempty_for_none = candidate(&empty_case, "vk-env"); nonempty_for_none.golden_output_sha256 = nonempty_for_none.candidate_output_sha256.clone(); assert!(store .upsert_candidate(nonempty_for_none) @@ -2007,9 +1944,7 @@ mod tests { let first = over("first", "AAAAAA=="); let second = over("second", "AQAAAA=="); assert_eq!(store.put_case(first.clone()).unwrap(), PutCaseResult::Added); - store - .upsert_candidate(candidate(&first, Backend::Vulkan, "env")) - .unwrap(); + store.upsert_candidate(candidate(&first, "env")).unwrap(); assert_eq!( store.put_case(second.clone()).unwrap(), PutCaseResult::Added @@ -2017,10 +1952,7 @@ mod tests { let mut cases = store.read_all_cases().unwrap(); cases.sort_by(|left, right| left.entry.cmp(&right.entry)); assert_eq!(cases, [first.clone(), second.clone()]); - assert_eq!( - store.read_candidates(Backend::Vulkan).unwrap(), - [candidate(&first, Backend::Vulkan, "env")] - ); + assert_eq!(store.read_candidates().unwrap(), [candidate(&first, "env")]); // The same slot again is a replacement of that entry's case alone. let replacement = over("second", "AgAAAA=="); @@ -2048,10 +1980,7 @@ mod tests { store.read_all_cases().unwrap(), std::slice::from_ref(&first) ); - assert_eq!( - store.read_candidates(Backend::Vulkan).unwrap(), - [candidate(&first, Backend::Vulkan, "env")] - ); + assert_eq!(store.read_candidates().unwrap(), [candidate(&first, "env")]); } #[test] @@ -2062,12 +1991,8 @@ mod tests { let kept = make_case("kept", "AQAAAA=="); store.put_case(removed.clone()).unwrap(); store.put_case(kept.clone()).unwrap(); - store - .upsert_candidate(candidate(&removed, Backend::Vulkan, "env")) - .unwrap(); - store - .upsert_candidate(candidate(&kept, Backend::Vulkan, "env")) - .unwrap(); + store.upsert_candidate(candidate(&removed, "env")).unwrap(); + store.upsert_candidate(candidate(&kept, "env")).unwrap(); assert_eq!( store @@ -2077,8 +2002,8 @@ mod tests { ); assert_eq!(store.read_all_cases().unwrap(), vec![kept.clone()]); assert_eq!( - store.read_candidates(Backend::Vulkan).unwrap(), - vec![candidate(&kept, Backend::Vulkan, "env")] + store.read_candidates().unwrap(), + vec![candidate(&kept, "env")] ); } @@ -2101,7 +2026,7 @@ mod tests { } /// A venue rekey rewrites exactly the records that recorded its stem at its `from` key, rows - /// and refusals of either backend: a record of the same profile at another key, one of another + /// and refusals: a record of the same profile at another key, one of another /// profile at the same key, and one that recorded no venue keep their bytes, and a second run /// rewrites nothing. #[test] @@ -2125,17 +2050,17 @@ mod tests { }, }) }; - for (slot, backend, environment) in [ - ("a@engine", Backend::Vulkan, venue("profile-a", &old)), - ("a2@engine", Backend::Vulkan, venue("profile-a", &other)), - ("b@engine", Backend::Vulkan, venue("profile-b", &old)), - ("plain", Backend::Vulkan, serde_json::json!({})), - ("m@engine", Backend::Vulkan, venue("profile-a", &old)), + for (slot, environment) in [ + ("a@engine", venue("profile-a", &old)), + ("a2@engine", venue("profile-a", &other)), + ("b@engine", venue("profile-b", &old)), + ("plain", serde_json::json!({})), + ("m@engine", venue("profile-a", &old)), ] { store .upsert_candidate(CandidateObservation { environment, - ..candidate(&case, backend, slot) + ..candidate(&case, slot) }) .unwrap(); } @@ -2171,11 +2096,10 @@ mod tests { crate::c3::VenueProfile::recorded_fingerprint(environment).map(String::from) }; let mut recorded = BTreeMap::new(); - let backend = Backend::Vulkan; - for row in store.read_candidates(backend).unwrap() { + for row in store.read_candidates().unwrap() { recorded.insert(row.environment_id.clone(), fingerprint(&row.environment)); } - for refused in store.read_refusals(Backend::Vulkan).unwrap() { + for refused in store.read_refusals().unwrap() { recorded.insert( refused.environment_id.clone(), fingerprint(&refused.environment), @@ -2216,42 +2140,33 @@ mod tests { store.put_case(kept.clone()).unwrap(); let slot = "env@engine"; let shard = shard_name(shard_index_for_hash(&refused.air_sha256).unwrap()); - let refusal_shard = scratch - .path() - .join(refusal_directory(Backend::Vulkan)) - .join(&shard); + let refusal_shard = scratch.path().join(REFUSAL_DIRECTORY).join(&shard); - store - .upsert_candidate(candidate(&refused, Backend::Vulkan, slot)) - .unwrap(); + store.upsert_candidate(candidate(&refused, slot)).unwrap(); assert!(!refusal_shard.exists(), "a row creates no refusal shard"); // A refusal replaces the slot's row, and only that slot's. - store - .upsert_candidate(candidate(&kept, Backend::Vulkan, slot)) - .unwrap(); + store.upsert_candidate(candidate(&kept, slot)).unwrap(); store.upsert_refusal(refusal(&refused, slot)).unwrap(); assert_eq!( - store.read_candidates(Backend::Vulkan).unwrap(), - vec![candidate(&kept, Backend::Vulkan, slot)] + store.read_candidates().unwrap(), + vec![candidate(&kept, slot)] ); assert_eq!( - store.read_refusals(Backend::Vulkan).unwrap(), + store.read_refusals().unwrap(), vec![refusal(&refused, slot)] ); // A refusal in another slot is its own. let off = "env@engine@runtime-floor"; store.upsert_refusal(refusal(&refused, off)).unwrap(); store.upsert_refusal(refusal(&kept, off)).unwrap(); - assert_eq!(store.read_refusals(Backend::Vulkan).unwrap().len(), 3); + assert_eq!(store.read_refusals().unwrap().len(), 3); assert!(store.layout_errors().unwrap().is_empty()); // A row replaces the slot's refusal. - store - .upsert_candidate(candidate(&refused, Backend::Vulkan, slot)) - .unwrap(); + store.upsert_candidate(candidate(&refused, slot)).unwrap(); let mut expected = vec![refusal(&kept, off), refusal(&refused, off)]; expected.sort_by(|a, b| a.order_key().cmp(&b.order_key())); - assert_eq!(store.read_refusals(Backend::Vulkan).unwrap(), expected); - assert_eq!(store.read_candidates(Backend::Vulkan).unwrap().len(), 2); + assert_eq!(store.read_refusals().unwrap(), expected); + assert_eq!(store.read_candidates().unwrap().len(), 2); // A refusal of an unknown case is not stored. let unknown = make_case("unknown", "AgAAAA=="); assert!(store @@ -2262,14 +2177,11 @@ mod tests { // Replacing a case drops its old identity's refusals; deleting one drops its own. let replacement = make_case("refused", "AwAAAA=="); store.put_case(replacement).unwrap(); - assert_eq!( - store.read_refusals(Backend::Vulkan).unwrap(), - vec![refusal(&kept, off)] - ); + assert_eq!(store.read_refusals().unwrap(), vec![refusal(&kept, off)]); store .delete_named_case(&kept.air_sha256, None, &kept.name) .unwrap(); - assert!(store.read_refusals(Backend::Vulkan).unwrap().is_empty()); + assert!(store.read_refusals().unwrap().is_empty()); assert!( !refusal_shard.exists(), "an emptied refusal shard is removed" @@ -2304,9 +2216,9 @@ mod tests { let slot = "env@engine@runtime-floor"; store.upsert_refusal(restricted(slot)).unwrap(); store - .upsert_candidate(candidate(&case, Backend::Vulkan, "env@engine")) + .upsert_candidate(candidate(&case, "env@engine")) .unwrap(); - let stored = store.read_refusals(Backend::Vulkan).unwrap(); + let stored = store.read_refusals().unwrap(); assert_eq!(stored, vec![restricted(slot)]); assert_eq!( stored[0].refusal.class, @@ -2321,7 +2233,7 @@ mod tests { .detail .contains("profile runtime-floor states 1 capabilities the device lacks: formats.VK_FORMAT_R8_SNORM")); // The venue's own slot keeps its row. - assert_eq!(store.read_candidates(Backend::Vulkan).unwrap().len(), 1); + assert_eq!(store.read_candidates().unwrap().len(), 1); assert!(store.layout_errors().unwrap().is_empty()); } @@ -2375,11 +2287,11 @@ mod tests { assert_eq!(text.matches("\"at_bind\":false").count(), 1, "{text}"); let shard = scratch .path() - .join(refusal_directory(Backend::Vulkan)) + .join(REFUSAL_DIRECTORY) .join(shard_name(shard_index_for_hash(&case.air_sha256).unwrap())); fs::create_dir_all(shard.parent().unwrap()).unwrap(); fs::write(&shard, &bytes).unwrap(); - let read = store.read_refusals(Backend::Vulkan).unwrap(); + let read = store.read_refusals().unwrap(); assert_eq!(read, rows); assert_eq!(serialized(&read), bytes); assert!(store.layout_errors().unwrap().is_empty()); diff --git a/crates/metal2vulkan-validation/src/vulkan_batch.rs b/crates/metal2vulkan-validation/src/vulkan_batch.rs index 402bec902..813dad540 100644 --- a/crates/metal2vulkan-validation/src/vulkan_batch.rs +++ b/crates/metal2vulkan-validation/src/vulkan_batch.rs @@ -57,12 +57,11 @@ use crate::gpu::wait::{SubmissionBackend, HANG_EXIT_CODE}; use crate::gpu::DeviceType; use crate::metal::{ORACLE_ABI, REFERENCE_GAP_EXIT}; use crate::observation::{ - Backend, CandidateObservation, CandidateStatus, MetalObservation, MetalStatus, - TRANSLATOR_FINGERPRINT, + CandidateObservation, CandidateStatus, MetalObservation, MetalStatus, TRANSLATOR_FINGERPRINT, }; use crate::refusal::RefusalObservation; use crate::source::shard_name_for_hash; -use crate::store::{refusal_directory, CorpusStore}; +use crate::store::{CorpusStore, CANDIDATE_DIRECTORY, REFUSAL_DIRECTORY}; use crate::worker::device::VALIDATION_FINGERPRINT; use crate::ScratchDir; use base64::Engine as _; @@ -588,7 +587,7 @@ impl BatchDevice { } } -/// Whose rows a batch records: a candidate backend's (its executor's engine runs), or Metal's +/// Whose rows a batch records: the Vulkan candidate's (its executor's engine runs), or Metal's /// (the oracle's qualifications). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] @@ -598,27 +597,11 @@ pub enum BatchBackend { } impl BatchBackend { - /// The candidate backend, for a candidate batch. - pub fn candidate(self) -> Option { - match self { - Self::Vulkan => Some(Backend::Vulkan), - Self::Metal => None, - } - } - /// Its rows' directory under `observations/` (`vulkan`, `metal`). pub fn directory(self) -> &'static str { - match self.candidate() { - Some(backend) => backend.directory(), - None => "metal", - } - } -} - -impl From for BatchBackend { - fn from(backend: Backend) -> Self { - match backend { - Backend::Vulkan => Self::Vulkan, + match self { + Self::Vulkan => "vulkan", + Self::Metal => "metal", } } } @@ -1023,18 +1006,18 @@ fn hang( /// A job's store at `store`: links to `corpus`'s cases, reviews, private sources, and library /// modules (each that exists), and the rows `backend`'s runs read; and empty shard directories of -/// its own for the rows they write. A candidate run reads the Metal rows and writes `backend`'s +/// its own for the rows they write. A candidate run reads the Metal rows and writes the candidate /// rows and refusals; a Metal run reads no rows and writes Metal's. fn worker_store(corpus: &Path, store: &Path, backend: BatchBackend) -> Result<(), String> { - let (own, read) = match backend.candidate() { - Some(backend) => ( + let (own, read) = match backend { + BatchBackend::Vulkan => ( vec![ - Path::new("observations").join(backend.directory()), - refusal_directory(backend), + PathBuf::from(CANDIDATE_DIRECTORY), + PathBuf::from(REFUSAL_DIRECTORY), ], vec![PathBuf::from("observations/metal")], ), - None => (vec![PathBuf::from("observations/metal")], Vec::new()), + BatchBackend::Metal => (vec![PathBuf::from("observations/metal")], Vec::new()), }; for own in own { let own = store.join(own); @@ -1126,13 +1109,12 @@ fn execute_run(config: &BatchConfig, store: &Path, run: &Run) -> Result { - let backend = config - .backend - .candidate() - .ok_or("a Metal batch runs no engine")?; + if config.backend == BatchBackend::Metal { + return Err("a Metal batch runs no engine".into()); + } let slot = engine_slot(&config.environment_id, config.restricted_to.as_deref()); - let row = find_row(store, backend, run, &slot)?; - let refusal = find_refusal(store, backend, run, &slot)?; + let row = find_row(store, run, &slot)?; + let refusal = find_refusal(store, run, &slot)?; Recorded { outcome: classify( ended, @@ -1253,10 +1235,9 @@ fn wait_until(child: &mut Child, deadline: Instant) -> Result { } } -/// The store line and status of `run`'s row of `backend` in `slot`, if the job store holds one. +/// The store line and status of `run`'s candidate row in `slot`, if the job store holds one. fn find_row( store: &Path, - backend: Backend, run: &Run, slot: &str, ) -> Result, String> { @@ -1266,26 +1247,21 @@ fn find_row( environment_id: String, status: CandidateStatus, } - let directory = store.join("observations").join(backend.directory()); + let directory = store.join(CANDIDATE_DIRECTORY); Ok(find_line::(&directory, run, |key| { key.case_id == run.case_id && key.environment_id == slot })? .map(|(line, key)| (line, key.status))) } -/// The store line of `run`'s refusal of `backend` in `slot`, if the job store holds one. -fn find_refusal( - store: &Path, - backend: Backend, - run: &Run, - slot: &str, -) -> Result, String> { +/// The store line of `run`'s refusal in `slot`, if the job store holds one. +fn find_refusal(store: &Path, run: &Run, slot: &str) -> Result, String> { #[derive(serde::Deserialize)] struct Key { case_id: String, environment_id: String, } - let directory = store.join(refusal_directory(backend)); + let directory = store.join(REFUSAL_DIRECTORY); Ok(find_line::(&directory, run, |key| { key.case_id == run.case_id && key.environment_id == slot })? @@ -1382,11 +1358,10 @@ pub struct Installed { /// row ([`ROWS`]), a typed refusal its last refusal ([`REFUSALS`]; a refusal before a device /// opened recorded none, and installs nothing). Evidence no finished run lists (an append cut /// before its done-list line) is not installed. The store keeps a slot's row or its refusal, -/// never both, so the installed one replaces the other. Every row and refusal must be of -/// `backend`, and so must the out directory's record (one without a record is Vulkan's). The -/// record is returned: only rows of this build ([`BatchBuild::is_this_build`]) are current once +/// never both, so the installed one replaces the other. The out directory's record must be a +/// Vulkan batch's (one without a record is). The record is returned: only rows of this build ([`BatchBuild::is_this_build`]) are current once /// installed, which the caller checks before it commits them. -pub fn install(out: &Path, store: &CorpusStore, backend: Backend) -> Result { +pub fn install(out: &Path, store: &CorpusStore) -> Result { #[derive(Clone, Copy, PartialEq, Eq)] enum Evidence { Row, @@ -1396,12 +1371,11 @@ pub fn install(out: &Path, store: &CorpusStore, backend: Backend) -> Result Result DeviceInput { root: PathBuf::from("/nonexistent/device-worker-corpus"), case: crate::case::attachmentless_fragment_test_case("00".repeat(32), "frag".into()), device, - backend: Backend::Vulkan, input_sha256: "11".repeat(32), wait_timeout_ms: 7_000, restricted_to: None, diff --git a/crates/metal2vulkan-validation/tests/integration/committed_shards_keep_the_store_layout.rs b/crates/metal2vulkan-validation/tests/integration/committed_shards_keep_the_store_layout.rs index ba2692953..2984aa013 100644 --- a/crates/metal2vulkan-validation/tests/integration/committed_shards_keep_the_store_layout.rs +++ b/crates/metal2vulkan-validation/tests/integration/committed_shards_keep_the_store_layout.rs @@ -10,7 +10,6 @@ //! MoltenVK shards. Byte-level canonical form is not part of this check: rows of executor v34 still //! carry the legacy `containment.device_addresses` field that a rewrite drops. -use metal2vulkan_validation::observation::Backend; use metal2vulkan_validation::store::CorpusStore; #[test] @@ -30,7 +29,7 @@ fn committed_shards_keep_the_store_layout() { let cases = store.read_all_cases().expect("committed cases"); let metal = store.read_metal().expect("committed Metal observations"); let vulkan = store - .read_candidates(Backend::Vulkan) + .read_candidates() .expect("committed Vulkan observations"); assert!( !cases.is_empty() && !metal.is_empty() && !vulkan.is_empty(), @@ -42,7 +41,7 @@ fn committed_shards_keep_the_store_layout() { } /// Every committed observation and every committed refusal record names a committed case, with -/// that case's AIR. The store's readers check this when they read a backend's rows or refusals, so +/// that case's AIR. The store's readers check this when they read the rows or refusals, so /// this reads every one of them from the committed store. A case re-keyed or deleted on one branch /// while another committed rows or refusals of its old id leaves records that name no case: /// `corpus-status --c3` then refuses the whole store (a case was once re-keyed while six refusals @@ -56,13 +55,12 @@ fn every_committed_observation_and_refusal_names_a_committed_case() { errors.push(format!("Metal observations: {error}")); } let mut refusals = 0; - let backend = Backend::Vulkan; - if let Err(error) = store.read_candidates(backend) { - errors.push(format!("{} observations: {error}", backend.directory())); + if let Err(error) = store.read_candidates() { + errors.push(format!("vulkan observations: {error}")); } - match store.read_refusals(backend) { + match store.read_refusals() { Ok(rows) => refusals += rows.len(), - Err(error) => errors.push(format!("{} refusals: {error}", backend.directory())), + Err(error) => errors.push(format!("vulkan refusals: {error}")), } assert!( errors.is_empty(), diff --git a/crates/metal2vulkan-validation/tests/integration/device_worker.rs b/crates/metal2vulkan-validation/tests/integration/device_worker.rs index c9c6a3cde..5ab2a32a4 100644 --- a/crates/metal2vulkan-validation/tests/integration/device_worker.rs +++ b/crates/metal2vulkan-validation/tests/integration/device_worker.rs @@ -22,7 +22,7 @@ const CASE: &str = r#"{"acceleration_structures":[{"binding":5,"kind":"primitive /// claiming a checked-input digest the case does not have. fn input(restricted_to: Option<&str>, generated_commands: bool) -> String { format!( - r#"{{"root":"/nonexistent/device-worker-corpus","case":{CASE},"device":"Cpu","backend":"vulkan","input_sha256":"{}","wait_timeout_ms":10000,"restricted_to":{},"generated_commands":{generated_commands}}}"#, + r#"{{"root":"/nonexistent/device-worker-corpus","case":{CASE},"device":"Cpu","input_sha256":"{}","wait_timeout_ms":10000,"restricted_to":{},"generated_commands":{generated_commands}}}"#, "0".repeat(64), serde_json::to_string(&restricted_to).unwrap() )