Repository navigation
Description
Part of #1801
Problem / Background
scripts/rocm_gpu_guard.sh (from #2061) waits for --idle-secs of idle GPU, runs the command, and rejects the attempt if a 1 Hz monitor sees a foreign GPU process. Two guards started together with the same --idle-secs reach the end of their idle streak in the same second, both start their commands, each monitor sees the other command in /sys/class/kfd/kfd/proc as foreign, both attempts are rejected, and both go back to the same idle wait. They repeat in lockstep until --max-attempts (default 5) runs out and both exit 75. Parallel units in the 2026-10 ROCm run worked around it by picking different windows by hand (45, 55, 60, 75, 90, 120 s).
Current Behavior
scripts/rocm_gpu_guard.sh:146-165wait_idle: counts consecutive idle samples; nothing coordinates two guards, which are bash processes and never appear in the KFD list themselves.scripts/rocm_gpu_guard.sh:181-219: attempt loop; a contended attempt goes straight back towait_idlewith the same window.- Callers:
scripts/rocm_decode_profile.sh:122,129and the commands cited indocs/benchmarks.md:214-218and thedocs/benchmark_results/rocm-*pages. - Tests:
GuardTestsintests/test_rocm_decode_profile.py:52-187, run against a fake KFD directory viaROCM_GPU_GUARD_KFD_DIR.
Proposed Solution
Serialize guards host-wide with flock (util-linux, present at /usr/bin/flock on the gfx1151 host). Randomized backoff is rejected: it lowers the collision rate but still burns whole attempts, and runs started together stay correlated.
- Lock path:
ROCM_GPU_GUARD_LOCK, default/tmp/mlxcel-rocm-gpu-guard.lock. Create it only if missing, with(umask 000; : >>"$LOCK"), then open it read-only (exec {LOCK_FD}<"$LOCK"):flockworks on a read-only descriptor, and anO_CREATopen of another user's file in sticky/tmpfails underfs.protected_regular. - Acquire before the first
wait_idleand hold it across every attempt until the guard exits. Logwaiting for guard lock <path>andacquired guard lock after <N>s. --max-waitbecomes one budget from guard start (bashSECONDS) covering the lock wait and the idle wait:flock -w <remaining>whenMAX_WAIT > 0, blocking otherwise. Lock timeout logsgave up waiting for guard lockand exits 75 without running the command.- Start the command with the descriptor closed (
"$@" {LOCK_FD}<&- &) so a daemon it leaves behind cannot hold the lock, and exportROCM_GPU_GUARD_LOCK_HELD=$$to it. A guard that starts withROCM_GPU_GUARD_LOCK_HELDset skips locking and logslock held by outer guard <pid>, so a nested guard cannot deadlock. flockmissing: exit 2 withrocm_gpu_guard: flock not found (util-linux). Do not silently run unlocked.- Update the header comment (and the
sed -n '2,29p'range inusage()if the header grows) anddocs/benchmarks.md:214-218.
Acceptance Criteria
-
run_guardintests/test_rocm_decode_profile.pysetsROCM_GPU_GUARD_LOCKto a per-test temp path, so tests never touch the host lock. - New test: two guards started together with
--idle-secs 1 --max-attempts 2, each command registering its own pid in the fake KFD dir for about 2 s, both exit 0 with noCONTENDEDline, and the second'sstartlog line comes after the first'sCLEAN. This test fails on main (both exit 75). - New test: lock held by an outside
flockprocess,--max-wait 2exits 75 and the command never runs. - New test: a guard run with
ROCM_GPU_GUARD_LOCK_HELDset while the lock is held completes without waiting. - Existing
GuardTestspass unchanged apart from the helper.
Verification
python3 -m unittest tests/test_rocm_decode_profile.py -v
bash -n scripts/rocm_gpu_guard.shManual, on the ROCm host: start two scripts/rocm_gpu_guard.sh --idle-secs 30 -- scripts/bench_decode.sh <model> at once; both finish, one after the other, with no rejected attempt.
Activity
update(rocm): enable fused add-RMSNorm and RoPE-append by default on …
fix(bench): serialize rocm_gpu_guard.sh runs with a host-wide lock (l…