Remove the host GPU locks: the validation batch's run lock and device-lane's --wrap
GPU work now runs under the cluster scheduler's exclusive GPU hold, which already gives a job the GPU to itself, so the repo's own cross-process GPU locks only duplicated it. - vulkan_batch: delete run_lock.rs, the ~/.cache/m2v-gpu/run.lock + run.turn flock that made GPU batches on one host take turns run by run, and its two tests. A GPU batch already runs one executor at a time (it refuses jobs != 1), and it still reads the hang tripwire before every run and writes it on a hang; the tripwire is a stop, not a lock, and stays. - scripts/device-lane: drop --wrap, which existed to put each shard under a host GPU lock and a memory cap; the report's "wrapped" column and totals become the run's. - docs/VALIDATION.md: the device-lane section says to run it under the host's exclusive GPU hold instead of a --wrap lock. - Comments that told the reader to run probes under `maclock` or spoke of "the Mac's GPU lock" now say the run has the GPU to itself (Metal probes, recording.rs, stage-input-split, two runtime test modules, which are outside the runtime-sources pin). Checked on a Linux node before landing: cargo clippy -p metal2vulkan-validation --all-targets --all-features (plain and --cfg m2v_gpu) -D warnings, the vulkan_batch tests, and the runtime-sources guard (the pin is unchanged).
This commit is contained in:
1 parent
555b13d57e
commit
7d7085f9d0
15 files changed
+29
-442
No files matched your search
@@ -23,7 +23,7 @@
|
||||
// So Metal's coverage is not floor(alpha * n): the conformance family `alpha_coverage_pairs` reads
|
||||
// one pixel at alphas whose alpha * n is an integer, and 0.5 at one sample, where the two agree.
|
||||
//
|
||||
// Run it WITHOUT MTL_DEBUG_LAYER, on the Mac's GPU lock:
|
||||
// Run it WITHOUT MTL_DEBUG_LAYER, with the Mac's GPU to itself:
|
||||
//
|
||||
// clang -fobjc-arc -framework Metal -framework Foundation -o alpha_coverage_sweep alpha_coverage_sweep.m
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
// WHAT IT MEASURED, Apple M3 Max, macOS 27.0.1: see the module docs of the translator's
|
||||
// `bind::astc_decode` and the runtime's `astc.rs`, which state Metal's answers.
|
||||
//
|
||||
// Build outside the Mac's GPU lock, then run each case WITHOUT MTL_DEBUG_LAYER on it:
|
||||
// Build it, then run each case WITHOUT MTL_DEBUG_LAYER, with the Mac's GPU to itself:
|
||||
//
|
||||
// clang -fobjc-arc -framework Metal -framework Foundation -o astc_hdr_textures \
|
||||
// astc_hdr_textures.m
|
||||
// maclock /usr/bin/env -u MTL_DEBUG_LAYER ./astc_hdr_textures create
|
||||
// /usr/bin/env -u MTL_DEBUG_LAYER ./astc_hdr_textures create
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
// WHAT IT MEASURED, Apple M3 Max, macOS 27.0.1: see the module docs of the runtime's `astc.rs`,
|
||||
// which state Metal's answers.
|
||||
//
|
||||
// Build outside the Mac's GPU lock, then run each case WITHOUT MTL_DEBUG_LAYER on it:
|
||||
// Build it, then run each case WITHOUT MTL_DEBUG_LAYER, with the Mac's GPU to itself:
|
||||
//
|
||||
// clang -fobjc-arc -framework Metal -framework Foundation -o astc_passes_writes_footprints \
|
||||
// astc_passes_writes_footprints.m
|
||||
// maclock /usr/bin/env -u MTL_DEBUG_LAYER ./astc_passes_writes_footprints pass 204 clear store 1
|
||||
// /usr/bin/env -u MTL_DEBUG_LAYER ./astc_passes_writes_footprints pass 204 clear store 1
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
@@ -67,10 +67,10 @@
|
||||
// exponent: that horizontal edge is biased by the triangle's slope, and an edge at z = 0.3 of a
|
||||
// triangle whose third vertex is at 0.9 by 2^-4 for a constant of 2^20.
|
||||
//
|
||||
// Run it WITHOUT MTL_DEBUG_LAYER, each case on the Mac's GPU lock:
|
||||
// Run it WITHOUT MTL_DEBUG_LAYER, each case with the Mac's GPU to itself:
|
||||
//
|
||||
// clang -fobjc-arc -framework Metal -framework Foundation -o line_widths line_widths.m
|
||||
// maclock /usr/bin/env -u MTL_DEBUG_LAYER ./line_widths lane
|
||||
// /usr/bin/env -u MTL_DEBUG_LAYER ./line_widths lane
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
// - `interpolate_at_offset(0.5, 0.5)` differs from `interpolate_at_center` in the last bits;
|
||||
// - only `pm_sample_id` runs once per sample at 4 samples.
|
||||
//
|
||||
// Run it WITHOUT MTL_DEBUG_LAYER, each case on the Mac's GPU lock:
|
||||
// Run it WITHOUT MTL_DEBUG_LAYER, each case with the Mac's GPU to itself:
|
||||
//
|
||||
// clang -fobjc-arc -framework Metal -framework Foundation -o pull_model_interpolation \
|
||||
// pull_model_interpolation.m
|
||||
// maclock /usr/bin/env -u MTL_DEBUG_LAYER ./pull_model_interpolation lane \
|
||||
// /usr/bin/env -u MTL_DEBUG_LAYER ./pull_model_interpolation lane \
|
||||
// ../../metal2vulkan-validation/fixtures/public/engine/pull_model_interpolants.metal
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
//! is the same statement from the other side.
|
||||
//!
|
||||
//! So the call's cost is **ours**, and the cells split it (Apple M3 Max, macOS 27.0.1, MoltenVK
|
||||
//! 1.4.2, release, under the GPU lock, the median of the 28 calls after the first; two runs at
|
||||
//! 1.4.2, release, with the GPU to itself, the median of the 28 calls after the first; two runs at
|
||||
//! one-minute loads of 6.65 and 6.21, whose absolutes move 1.3x and whose share does not):
|
||||
//!
|
||||
//! | part | us a call | share |
|
||||
|
||||
@@ -545,7 +545,7 @@ fn temp_beside(path: &std::path::Path) -> std::path::PathBuf {
|
||||
///
|
||||
/// A plain `std::fs::write` truncates the target and then fills it, so a process killed in that
|
||||
/// window leaves a recording half-written and unparseable -- and a whole-set write does this 722
|
||||
/// times in a row, with a `maclock` ticket that another stream may need back. Building the text
|
||||
/// times in a row, while holding the Mac's GPU that other work may be waiting for. Building the text
|
||||
/// in a sibling file and renaming it over the target closes the window: `rename` replaces the
|
||||
/// directory entry in one step, so a reader sees one file or the other and never a partial one.
|
||||
/// An interrupt can still leave a *stray temporary*, which is harmless by name, and the next
|
||||
|
||||
@@ -210,7 +210,7 @@ fn a_rebind_waits_for_nothing_where_its_encoding_again_finds_the_pipeline_made()
|
||||
const WATCHED_COMPLETION: Duration = Duration::from_millis(500);
|
||||
|
||||
/// The safety net: a second hold dropped after this, so a regression that makes the rebind block
|
||||
/// again ends this test instead of wedging it while it holds the Mac's GPU lock.
|
||||
/// again ends this test instead of wedging it while it holds the GPU.
|
||||
const NET: Duration = Duration::from_secs(30);
|
||||
|
||||
/// The segment the encoding again leaves is a pending dispatch's, awaited where the first
|
||||
|
||||
@@ -69,7 +69,7 @@ const WATCHED_COMPLETION: Duration = Duration::from_millis(500);
|
||||
|
||||
/// The safety net: the pool's hold goes after this whatever the leg is doing, so a regression that
|
||||
/// makes the rebind block again ends the leg on its assertions instead of wedging it while it holds
|
||||
/// the Mac's GPU lock. The leg's own release comes long before.
|
||||
/// the GPU. The leg's own release comes long before.
|
||||
const NET: Duration = Duration::from_secs(20);
|
||||
|
||||
/// The pass's tile and render area: one whole 16x16 tile, so the fixture's slot
|
||||
@@ -324,7 +324,7 @@ fn leg(memo: Memo) {
|
||||
|
||||
// From now on the pool starts no piece: a making handed to it stays in flight. The one hold is
|
||||
// a thread's, which drops it when the leg says so or after `NET`, whichever comes first: a leg
|
||||
// that blocks in the rebind cannot keep it and wedge the Mac's GPU lock.
|
||||
// that blocks in the rebind cannot keep it and hold the GPU wedged.
|
||||
let hold = held::hold();
|
||||
let (release, released_at) = std::sync::mpsc::channel::<()>();
|
||||
let watchdog = std::thread::spawn(move || {
|
||||
|
||||
@@ -22,10 +22,8 @@
|
||||
//! outlived the per-run timeout, writing the tripwire for that last itself (its submission may
|
||||
//! still be running; the executor's own protocol writes it for the other two, and the batch
|
||||
//! writes it too when it is absent). A human follows the suspected-hang protocol in
|
||||
//! `docs/VALIDATION.md` before the next run. GPU batches running at once on one host take turns:
|
||||
//! each run holds the host's GPU run lock (`run_lock`) until it is recorded, so one run is on the
|
||||
//! GPU at a time, a hang names that run's case alone, and a batch waiting for the lock starts
|
||||
//! nothing while a tripwire exists.
|
||||
//! `docs/VALIDATION.md` before the next run. A GPU batch takes the GPU as its own: whatever
|
||||
//! schedules it holds the GPU for the batch, so a hang names that run's case alone.
|
||||
//! - **Bounded.** At most `jobs` executors run at once (the bin defaults to the available
|
||||
//! parallelism on a CPU device, which in a container is its CPU share, and to one on a GPU), each
|
||||
//! under a per-run timeout; at most `limit` cases run per invocation. A run's executor starts its
|
||||
@@ -69,7 +67,6 @@ use crate::source::shard_name_for_hash;
|
||||
use crate::store::{refusal_directory, CorpusStore};
|
||||
use crate::ScratchDir;
|
||||
use base64::Engine as _;
|
||||
use run_lock::RunLock;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||
@@ -864,17 +861,6 @@ pub fn run_batch(
|
||||
let Some(run) = runs.get(next.fetch_add(1, Ordering::Relaxed)) else {
|
||||
break;
|
||||
};
|
||||
// On a GPU the run holds the host's run lock until it is recorded, a
|
||||
// hang's tripwire included, and the tripwire is read again under the lock:
|
||||
// a hang of another batch's run stops this one before it starts.
|
||||
let _gpu = match &config.device {
|
||||
BatchDevice::Gpu(tripwire) => {
|
||||
let lock = RunLock::acquire(tripwire, run, config.timeout)?;
|
||||
tripwire.refuse_if_tripped()?;
|
||||
Some(lock)
|
||||
}
|
||||
BatchDevice::Cpu => None,
|
||||
};
|
||||
let executed = execute_run(config, &store, run)?;
|
||||
let mut outputs = outputs
|
||||
.lock()
|
||||
@@ -1907,7 +1893,6 @@ mod session {
|
||||
}
|
||||
|
||||
pub mod metal;
|
||||
mod run_lock;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -1,190 +0,0 @@
|
||||
//! The host's GPU run lock. A GPU batch holds it around each run: the run's start, its submissions
|
||||
//! and their bounded waits, and its end, the hang protocol's tripwire included. So batches running
|
||||
//! at once on one host (a Metal lane beside a MoltenVK lane, or two agents' lanes) put one run on
|
||||
//! the GPU at a time. A hang then has exactly one run in flight to name, and no batch's run can
|
||||
//! wait behind another batch's stuck submission: a batch waiting for the lock has not started its
|
||||
//! run, so no device wait of its own is running. The lock is the host's, beside its tripwire
|
||||
//! (`~/.cache/m2v-gpu/run.lock`), and is held through `flock`, which the kernel releases when the
|
||||
//! holder's file is closed, its process killed included. A CPU batch takes no lock.
|
||||
//!
|
||||
//! Batches take the lock in turn: a batch waiting for it first takes the turnstile beside it
|
||||
//! (`run.turn`) and holds that while it waits, so a holder coming back for its next run waits
|
||||
//! behind it instead of taking the lock again at once. Two batches alternate run by run.
|
||||
//!
|
||||
//! While it waits, a batch looks at the tripwire: one the holder's run left (written before the
|
||||
//! holder lets go) stops it before it starts anything. The holder records its process, its run,
|
||||
//! and the latest time its run can end (the run's timeout and the session's teardown after its
|
||||
//! start); a holder that keeps the lock well past that time stops the waiting batch with an error
|
||||
//! naming it, so no wait for the lock is unbounded.
|
||||
|
||||
use super::Run;
|
||||
use crate::gpu::tripwire::TripwirePaths;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{Seek as _, SeekFrom, Write as _};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
/// Beyond the run's own timeout: the session's teardown and the run's recording.
|
||||
const TEARDOWN: Duration = Duration::from_secs(30);
|
||||
|
||||
/// How long a waiting batch lets the holder keep the lock past the end it recorded.
|
||||
const GRACE: Duration = Duration::from_secs(60);
|
||||
|
||||
/// How often a waiting batch tries the turnstile or the lock again and looks at the tripwire.
|
||||
const POLL: Duration = Duration::from_millis(20);
|
||||
|
||||
/// The run lock of the host whose tripwire is `tripwire`: the file `run.lock` beside it.
|
||||
pub(crate) fn lock_path(tripwire: &TripwirePaths) -> PathBuf {
|
||||
tripwire.current.with_file_name("run.lock")
|
||||
}
|
||||
|
||||
/// The held lock. Dropping it clears the holder's record, then releases the lock.
|
||||
pub(crate) struct RunLock {
|
||||
file: File,
|
||||
}
|
||||
|
||||
impl RunLock {
|
||||
/// Hold the run lock of the host whose tripwire is `tripwire` for `run`, which ends within
|
||||
/// `timeout` (the batch's per-run timeout): take the turnstile, then the lock, then let the
|
||||
/// turnstile go. While another batch holds either, wait, and fail as soon as the tripwire
|
||||
/// exists, or once the lock's holder has kept it [`GRACE`] past the end it recorded.
|
||||
pub(crate) fn acquire(
|
||||
tripwire: &TripwirePaths,
|
||||
run: &Run,
|
||||
timeout: Duration,
|
||||
) -> Result<Self, String> {
|
||||
let path = lock_path(tripwire);
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.map_err(|error| format!("create {}: {error}", parent.display()))?;
|
||||
}
|
||||
let turnstile_path = path.with_file_name("run.turn");
|
||||
let turnstile = open(&turnstile_path)?;
|
||||
let mut file = open(&path)?;
|
||||
wait_for(&turnstile, &turnstile_path, tripwire, &path)?;
|
||||
wait_for(&file, &path, tripwire, &path)?;
|
||||
// Closing the turnstile lets the next waiting batch take it.
|
||||
drop(turnstile);
|
||||
let ends = unix_seconds(SystemTime::now() + timeout + TEARDOWN);
|
||||
file.set_len(0)
|
||||
.and_then(|()| file.seek(SeekFrom::Start(0)).map(drop))
|
||||
.and_then(|()| {
|
||||
writeln!(
|
||||
file,
|
||||
"{}\t{}\t{}\t{ends}",
|
||||
std::process::id(),
|
||||
run.case_id,
|
||||
run.pass.label()
|
||||
)
|
||||
})
|
||||
.and_then(|()| file.flush())
|
||||
.map_err(|error| {
|
||||
format!(
|
||||
"record the GPU run lock's holder {}: {error}",
|
||||
path.display()
|
||||
)
|
||||
})?;
|
||||
Ok(Self { file })
|
||||
}
|
||||
}
|
||||
|
||||
/// The lock file at `path`, created when missing (never truncated: it may hold a holder's record).
|
||||
fn open(path: &Path) -> Result<File, String> {
|
||||
OpenOptions::new()
|
||||
.create(true)
|
||||
.truncate(false)
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(path)
|
||||
.map_err(|error| format!("open {}: {error}", path.display()))
|
||||
}
|
||||
|
||||
/// Take `file`'s lock (at `path`), trying every [`POLL`]; between tries, fail as soon as the
|
||||
/// tripwire exists, or once the run lock's holder (its record at `lock`) has kept it [`GRACE`]
|
||||
/// past the end it recorded.
|
||||
fn wait_for(file: &File, path: &Path, tripwire: &TripwirePaths, lock: &Path) -> Result<(), String> {
|
||||
loop {
|
||||
if try_lock(file).map_err(|error| format!("lock {}: {error}", path.display()))? {
|
||||
return Ok(());
|
||||
}
|
||||
tripwire.refuse_if_tripped()?;
|
||||
if let Some(holder) = Holder::read(lock) {
|
||||
if unix_seconds(SystemTime::now()) > holder.ends + GRACE.as_secs() {
|
||||
return Err(format!(
|
||||
"the host's GPU run lock {} is held by process {} for case {} ({}) more than \
|
||||
{} s past the end its run recorded: a run that outlived its own timeout may \
|
||||
still hold the GPU; follow the suspected-hang protocol in docs/VALIDATION.md",
|
||||
lock.display(),
|
||||
holder.pid,
|
||||
holder.case_id,
|
||||
holder.pass,
|
||||
GRACE.as_secs()
|
||||
));
|
||||
}
|
||||
}
|
||||
std::thread::sleep(POLL);
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RunLock {
|
||||
fn drop(&mut self) {
|
||||
// A stale record must not outlive the hold; closing the file releases the lock.
|
||||
let _ = self.file.set_len(0);
|
||||
}
|
||||
}
|
||||
|
||||
/// What the holder recorded: its process, its run, and the latest time (Unix seconds) its run
|
||||
/// ends.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Holder {
|
||||
pid: u32,
|
||||
case_id: String,
|
||||
pass: String,
|
||||
ends: u64,
|
||||
}
|
||||
|
||||
impl Holder {
|
||||
/// The record at `path`, if it holds a whole one (none between holds, or while it is written).
|
||||
fn read(path: &Path) -> Option<Self> {
|
||||
let text = fs::read_to_string(path).ok()?;
|
||||
let line = text.strip_suffix('\n')?;
|
||||
let [pid, case_id, pass, ends] = line.split('\t').collect::<Vec<_>>()[..] else {
|
||||
return None;
|
||||
};
|
||||
Some(Self {
|
||||
pid: pid.parse().ok()?,
|
||||
case_id: case_id.into(),
|
||||
pass: pass.into(),
|
||||
ends: ends.parse().ok()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn unix_seconds(time: SystemTime) -> u64 {
|
||||
time.duration_since(UNIX_EPOCH)
|
||||
.map_or(0, |since| since.as_secs())
|
||||
}
|
||||
|
||||
/// Take `file`'s exclusive `flock` without waiting: `true` when taken, `false` when another open
|
||||
/// file holds it.
|
||||
#[cfg(unix)]
|
||||
fn try_lock(file: &File) -> std::io::Result<bool> {
|
||||
use std::os::unix::io::AsRawFd as _;
|
||||
// SAFETY: a plain syscall on a descriptor `file` owns for the call.
|
||||
if unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) } == 0 {
|
||||
return Ok(true);
|
||||
}
|
||||
let error = std::io::Error::last_os_error();
|
||||
match error.kind() {
|
||||
std::io::ErrorKind::WouldBlock => Ok(false),
|
||||
_ => Err(error),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn try_lock(_file: &File) -> std::io::Result<bool> {
|
||||
Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Unsupported,
|
||||
"the GPU run lock needs a Unix host",
|
||||
))
|
||||
}
|
||||
@@ -1830,195 +1830,3 @@ kill -SEGV $$
|
||||
assert_eq!(record.backend, SubmissionBackend::Metal);
|
||||
assert_eq!(record.case_id.as_deref(), Some(first.case_id.as_str()));
|
||||
}
|
||||
|
||||
/// A fake GPU executor for the run-lock tests: it claims the one "GPU" (`busy`, a directory only
|
||||
/// one run can make), notes its case in `started` and its job store (so its batch) in
|
||||
/// `started.stores`, and, for the case `stuck`, stays on it a second and leaves as a timed-out
|
||||
/// device wait does; every other run stays a fifth of a second and matches. A run that finds the
|
||||
/// GPU taken fails (exit 9).
|
||||
#[cfg(unix)]
|
||||
fn run_lock_executor(
|
||||
path: &Path,
|
||||
cases: &[&AuthoredCase],
|
||||
busy: &Path,
|
||||
started: &Path,
|
||||
stuck: &str,
|
||||
) {
|
||||
let shards = cases
|
||||
.iter()
|
||||
.map(|case| {
|
||||
format!(
|
||||
" {}) shard={} ;;\n",
|
||||
case.case_id,
|
||||
shard_name_for_hash(&case.air_sha256).unwrap()
|
||||
)
|
||||
})
|
||||
.collect::<String>();
|
||||
executable(
|
||||
path,
|
||||
&format!(
|
||||
r#"#!/bin/sh
|
||||
store= id= slot={ENV}@engine
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--corpus) store=$2; shift 2 ;;
|
||||
--case-id) id=$2; shift 2 ;;
|
||||
--robustness-off) slot={ENV}@engine+robustness-off; shift ;;
|
||||
*) shift 2 ;;
|
||||
esac
|
||||
done
|
||||
case "$id" in
|
||||
{shards} *) exit 9 ;;
|
||||
esac
|
||||
mkdir '{busy}' 2>/dev/null || {{ echo "another run is on the GPU" >&2; exit 9; }}
|
||||
echo "$id" >> '{started}'
|
||||
echo "$store" >> '{started}.stores'
|
||||
if [ "$id" = '{stuck}' ]; then
|
||||
sleep 1; rmdir '{busy}'; echo 'device wait timed out' >&2; exit {HANG_EXIT_CODE}
|
||||
fi
|
||||
sleep 0.2
|
||||
rmdir '{busy}'
|
||||
printf '{{"case_id":"%s","environment_id":"%s","status":"match"}}\n' "$id" "$slot" \
|
||||
>> "$store/observations/vulkan/$shard"
|
||||
exit 0
|
||||
"#,
|
||||
busy = busy.display(),
|
||||
started = started.display(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Two GPU batches at once on one host take turns: each run holds the host's GPU run lock, so no
|
||||
/// two runs are on the GPU together, the batches alternate run by run (the turnstile), and both
|
||||
/// finish. When one batch's run hangs, the tripwire it leaves names that run's case alone, and the
|
||||
/// other batch, waiting for the lock meanwhile, starts no run: no wait of its own ever runs behind
|
||||
/// the stuck submission.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn two_gpu_batches_at_once_take_turns_and_a_hang_names_one_case() {
|
||||
let scratch = ScratchDir::new("batch-run-lock").unwrap();
|
||||
let corpus = scratch.path().join("corpus");
|
||||
let store = CorpusStore::new(&corpus);
|
||||
let cases = [case(1, "a"), case(2, "b"), case(3, "c"), case(4, "d")];
|
||||
for case in &cases {
|
||||
store.put_case(case.clone()).unwrap();
|
||||
}
|
||||
fs::create_dir_all(corpus.join("observations/vulkan")).unwrap();
|
||||
let busy = scratch.path().join("gpu-busy");
|
||||
let started = scratch.path().join("started");
|
||||
let executor = scratch.path().join("fake-corpus-vulkan");
|
||||
let batch = |out: &str| BatchConfig {
|
||||
out: scratch.path().join(out),
|
||||
..gpu_config(scratch.path(), executor.clone(), Duration::from_secs(60))
|
||||
};
|
||||
let BatchDevice::Gpu(tripwire) = batch("out").device else {
|
||||
unreachable!()
|
||||
};
|
||||
let all = cases.iter().collect::<Vec<_>>();
|
||||
|
||||
// Both batches run every case in both legs, at once.
|
||||
run_lock_executor(&executor, &all, &busy, &started, "none");
|
||||
let legs = [Leg::Stated, Leg::RobustnessOff].map(Pass::Leg);
|
||||
let runs = plan(&cases, &legs, &[], None);
|
||||
let (first, second) = (batch("out-1"), batch("out-2"));
|
||||
let (one, two) = std::thread::scope(|scope| {
|
||||
let one = scope.spawn(|| run_batch(&first, &runs, |_| {}));
|
||||
let two = scope.spawn(|| run_batch(&second, &runs, |_| {}));
|
||||
(one.join().unwrap(), two.join().unwrap())
|
||||
});
|
||||
for (config, finished) in [(&first, one), (&second, two)] {
|
||||
let finished = finished.unwrap();
|
||||
assert_eq!(finished.len(), 8);
|
||||
let listed = read_done_list(&config.out.join(DONE_LIST)).unwrap();
|
||||
assert!(
|
||||
listed.iter().all(|run| run.outcome == Outcome::Match),
|
||||
"{listed:#?}"
|
||||
);
|
||||
}
|
||||
assert_eq!(fs::read_to_string(&started).unwrap().lines().count(), 16);
|
||||
// The batches alternated: nearly every run follows one of the other batch.
|
||||
let stores = fs::read_to_string(started.with_extension("stores")).unwrap();
|
||||
let stores = stores.lines().collect::<Vec<_>>();
|
||||
let turns = stores.windows(2).filter(|pair| pair[0] != pair[1]).count();
|
||||
assert!(turns >= 12, "{turns} turns in 15: {stores:#?}");
|
||||
let lock = run_lock::lock_path(&tripwire);
|
||||
assert_eq!(fs::read_to_string(&lock).unwrap(), "", "no holder is left");
|
||||
|
||||
// One batch's first run hangs while the other waits for the lock.
|
||||
fs::remove_file(&started).unwrap();
|
||||
fs::remove_file(started.with_extension("stores")).unwrap();
|
||||
let (stuck, waiting) = (&cases[0], &cases[1..]);
|
||||
run_lock_executor(&executor, &all, &busy, &started, &stuck.case_id);
|
||||
let (hung_batch, waiting_batch) = (batch("out-3"), batch("out-4"));
|
||||
let stuck_runs = plan(
|
||||
std::slice::from_ref(stuck),
|
||||
&[Pass::Leg(Leg::Stated)],
|
||||
&[],
|
||||
None,
|
||||
);
|
||||
let waiting_runs = plan(waiting, &[Pass::Leg(Leg::Stated)], &[], None);
|
||||
let (hung, waited) = std::thread::scope(|scope| {
|
||||
let hung = scope.spawn(|| run_batch(&hung_batch, &stuck_runs, |_| {}));
|
||||
let deadline = std::time::Instant::now() + Duration::from_secs(20);
|
||||
while !started.exists() {
|
||||
assert!(
|
||||
std::time::Instant::now() < deadline,
|
||||
"the stuck run never started"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
let waited = run_batch(&waiting_batch, &waiting_runs, |_| {});
|
||||
(hung.join().unwrap(), waited)
|
||||
});
|
||||
let error = hung.unwrap_err();
|
||||
assert!(error.contains("the batch stops"), "{error}");
|
||||
let error = waited.unwrap_err();
|
||||
assert!(error.contains("GPU hang tripwire"), "{error}");
|
||||
assert_eq!(
|
||||
fs::read_to_string(&started).unwrap(),
|
||||
format!("{}\n", stuck.case_id),
|
||||
"the waiting batch started a run behind the stuck one"
|
||||
);
|
||||
assert!(read_done_list(&waiting_batch.out.join(DONE_LIST))
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
let listed = read_done_list(&hung_batch.out.join(DONE_LIST)).unwrap();
|
||||
assert_eq!(listed.len(), 1);
|
||||
assert_eq!(listed[0].outcome, Outcome::WaitTimeout);
|
||||
let record = crate::gpu::tripwire::read_record(&tripwire.current).unwrap();
|
||||
assert_eq!(record.case_id.as_deref(), Some(stuck.case_id.as_str()));
|
||||
assert_eq!(fs::read_to_string(&lock).unwrap(), "", "no holder is left");
|
||||
}
|
||||
|
||||
/// A batch never waits without bound for the host's GPU run lock: a holder that keeps it well past
|
||||
/// the end its run recorded stops the batch, naming the holder, before it starts a run.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_gpu_run_lock_held_past_its_end_stops_the_batch() {
|
||||
use std::os::unix::io::AsRawFd as _;
|
||||
let scratch = ScratchDir::new("batch-run-lock-held").unwrap();
|
||||
fs::create_dir_all(scratch.path().join("corpus")).unwrap();
|
||||
let executor = scratch.path().join("never-run");
|
||||
let config = gpu_config(scratch.path(), executor, Duration::from_secs(60));
|
||||
let BatchDevice::Gpu(tripwire) = &config.device else {
|
||||
unreachable!()
|
||||
};
|
||||
let lock = run_lock::lock_path(tripwire);
|
||||
fs::create_dir_all(lock.parent().unwrap()).unwrap();
|
||||
let holder = fs::File::create(&lock).unwrap();
|
||||
// SAFETY: a plain syscall on a descriptor the test owns.
|
||||
assert_eq!(
|
||||
unsafe { libc::flock(holder.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) },
|
||||
0
|
||||
);
|
||||
let held = case(9, "held");
|
||||
fs::write(&lock, format!("4242\t{}\tstated\t0\n", held.case_id)).unwrap();
|
||||
let runs = plan(&[case(1, "a")], &[Pass::Leg(Leg::Stated)], &[], None);
|
||||
let error = run_batch(&config, &runs, |_| {}).unwrap_err();
|
||||
assert!(error.contains("held by process 4242"), "{error}");
|
||||
assert!(error.contains(&held.case_id), "{error}");
|
||||
assert!(read_done_list(&config.out.join(DONE_LIST))
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
drop(holder);
|
||||
}
|
||||
+4
-6
@@ -112,12 +112,10 @@ scripts/device-lane/device-lane --profile release \
|
||||
- `--list-only` opens no device. `--filter EXPR` intersects a nextest filterset with the lane, and
|
||||
the report then says the coverage is of that slice alone, never of the lane. An expression that
|
||||
leaves the whole lane selected narrowed nothing, and stops the run.
|
||||
- `--wrap 'CMD ARG...'` prefixes each shard run. On a host whose GPU is shared, give it that
|
||||
host's GPU lock and a resident-memory cap: macOS does not enforce `ulimit -v`, and a device test
|
||||
has no worker boundary of its own. Every build and every listing stays outside it. Each shard is
|
||||
compiled by its own `cargo nextest run --no-run` pass first, so the wrapped half has nothing to
|
||||
compile: a lock held across a compile is the form that has wedged this one before, and a sibling
|
||||
cargo on the same target directory can invalidate it between two shards.
|
||||
- Each shard is compiled by its own `cargo nextest run --no-run` pass first, so its run has nothing
|
||||
to compile and its time is the tests' alone; a sibling cargo on the same target directory can
|
||||
invalidate a build between two shards. The lane assumes the GPU is its own for the run: on a
|
||||
shared host, run it under the host's exclusive GPU hold.
|
||||
- The cfg and plain legs keep separate target directories (`--cfg-target`, `--plain-target`),
|
||||
since `RUSTFLAGS` is part of a build's fingerprint. `--help` lists every option.
|
||||
|
||||
|
||||
@@ -18,12 +18,6 @@
|
||||
# it is proved against the lane like a derived one
|
||||
# --max-shard N the most tests a derived shard holds (default 150)
|
||||
# --jobs N nextest's test threads per shard (default 4)
|
||||
# --wrap 'CMD ARG...' a prefix for each shard run, for a host that shares its GPU: its
|
||||
# GPU lock, and a resident-memory cap, since macOS does not enforce
|
||||
# `ulimit -v` and a device test has no worker boundary of its own.
|
||||
# Every build and every listing runs outside it: each shard is compiled
|
||||
# by its own `--no-run` pass first, so the wrapped half has nothing to
|
||||
# compile and the lock never covers a compile
|
||||
# --cfg-target DIR the cfg build's target directory (default target/device-lane-gpu)
|
||||
# --plain-target DIR the plain build's (default target/device-lane-plain).
|
||||
# `RUSTFLAGS` is part of a build's fingerprint, so the two legs cannot
|
||||
@@ -52,7 +46,6 @@ max_shard=150
|
||||
jobs=4
|
||||
cfg_target=
|
||||
plain_target=
|
||||
wrap_words=
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
@@ -63,7 +56,6 @@ while [ $# -gt 0 ]; do
|
||||
--shards) shards_given=${2:-}; shift 2 ;;
|
||||
--max-shard) max_shard=${2:-}; shift 2 ;;
|
||||
--jobs) jobs=${2:-}; shift 2 ;;
|
||||
--wrap) wrap_words=${2:-}; shift 2 ;;
|
||||
--cfg-target) cfg_target=${2:-}; shift 2 ;;
|
||||
--plain-target) plain_target=${2:-}; shift 2 ;;
|
||||
-h | --help) sed -n '2,/^set -euo/p' "$0" | sed 's/^# \{0,1\}//; $d'; exit 0 ;;
|
||||
@@ -103,14 +95,12 @@ say " profile $profile"
|
||||
say " nextest $(cargo nextest --version | head -1)"
|
||||
say " cfg target $cfg_target"
|
||||
say " plain target $plain_target"
|
||||
say " wrap ${wrap_words:-<none>}"
|
||||
say " test threads $jobs"
|
||||
say " selection ${filter:-the whole device lane}"
|
||||
say " output $out"
|
||||
say ""
|
||||
|
||||
# One listing of the workspace. Builds and listings run unwrapped: a build must never hold a
|
||||
# shared GPU lock.
|
||||
# One listing of the workspace.
|
||||
nextest_list() {
|
||||
target=$1
|
||||
flags=$2
|
||||
@@ -170,7 +160,7 @@ if [ -n "$list_only" ]; then
|
||||
fi
|
||||
|
||||
say ""
|
||||
say "running the shards: a build, then one GPU-lock turn, each ..."
|
||||
say "running the shards: a build, then the run, each ..."
|
||||
: > "$out/runs.tsv"
|
||||
while IFS="$(printf '\t')" read -r name binary terms; do
|
||||
[ -n "$name" ] || continue
|
||||
@@ -183,11 +173,10 @@ while IFS="$(printf '\t')" read -r name binary terms; do
|
||||
# it builds are not the ones the listing above built, and the first shard would rebuild the
|
||||
# dependency graph. One scope for the listing and both halves is what keeps the target warm.
|
||||
#
|
||||
# Build first and unwrapped. `--no-run` compiles exactly what the run below executes, so the
|
||||
# wrapped half starts with nothing to compile and a shared host's GPU lock never covers a
|
||||
# compile -- the form that has wedged this lock before. Each shard builds again because a
|
||||
# Build first. `--no-run` compiles exactly what the run below executes, so the run starts with
|
||||
# nothing to compile and its wall time is the tests' alone. Each shard builds again because a
|
||||
# sibling cargo on the same target directory can invalidate it between two shards, and that
|
||||
# rebuild belongs out here.
|
||||
# rebuild is counted as build time.
|
||||
built=$(date +%s)
|
||||
status=0
|
||||
( cd "$repo" \
|
||||
@@ -205,13 +194,12 @@ while IFS="$(printf '\t')" read -r name binary terms; do
|
||||
( cd "$repo" \
|
||||
&& CARGO_TARGET_DIR="$cfg_target" \
|
||||
RUSTFLAGS="--cfg m2v_gpu" \
|
||||
${wrap_words:+$wrap_words} \
|
||||
cargo nextest run --workspace --all-features $profile_args \
|
||||
--no-fail-fast --hide-progress-bar --failure-output immediate-final \
|
||||
--success-output never -j "$jobs" -E "$expression" ) >> "$log" 2>&1 || status=$?
|
||||
wall=$(( $(date +%s) - started ))
|
||||
printf '%s\t%s\t%s\t%s\n' "$name" "$status" "$build_wall" "$wall" >> "$out/runs.tsv"
|
||||
say " $name exit=$status build ${build_wall}s locked ${wall}s"
|
||||
say " $name exit=$status build ${build_wall}s run ${wall}s"
|
||||
done < "$out/shards.tsv"
|
||||
printf 'DONE\n' > "$out/current-shard"
|
||||
|
||||
|
||||
@@ -332,7 +332,7 @@ def do_tally(args):
|
||||
out = [
|
||||
"",
|
||||
"shard results",
|
||||
f" {'shard':<42} {'status':<12}{'ran':>5}{'want':>6}{'build':>8}{'wrapped':>9}",
|
||||
f" {'shard':<42} {'status':<12}{'ran':>5}{'want':>6}{'build':>8}{'run':>9}",
|
||||
]
|
||||
ran_total, unaccounted, short, failed = 0, [], [], []
|
||||
tested = 0.0
|
||||
@@ -376,11 +376,9 @@ def do_tally(args):
|
||||
faults.append(f"{ran_total} tests ran in all, but the selection holds {runnable} runnable")
|
||||
out += [
|
||||
"",
|
||||
f" the wrapped half took {sum(run[2] for run in runs.values())}s in all, over"
|
||||
f" {len(runs)} turn(s): its turn in the host's queue and the run together, which this"
|
||||
" script cannot tell apart",
|
||||
f" the runs took {sum(run[2] for run in runs.values())}s in all, over {len(runs)} shard(s)",
|
||||
f" nextest's own clock says {tested:.1f}s of tests; building took"
|
||||
f" {sum(run[1] for run in runs.values())}s outside the wrap",
|
||||
f" {sum(run[1] for run in runs.values())}s",
|
||||
"",
|
||||
"coverage of the run",
|
||||
f" selected, runnable {runnable}",
|
||||
|
||||
Reference in new issue
Block a user