Skip to content

fix(bench): two rocm_gpu_guard.sh runs started together reject each other #2146

Closed

Description

@inureyes

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-165 wait_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 to wait_idle with the same window.
  • Callers: scripts/rocm_decode_profile.sh:122,129 and the commands cited in docs/benchmarks.md:214-218 and the docs/benchmark_results/rocm-* pages.
  • Tests: GuardTests in tests/test_rocm_decode_profile.py:52-187, run against a fake KFD directory via ROCM_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"): flock works on a read-only descriptor, and an O_CREAT open of another user's file in sticky /tmp fails under fs.protected_regular.
  • Acquire before the first wait_idle and hold it across every attempt until the guard exits. Log waiting for guard lock <path> and acquired guard lock after <N>s.
  • --max-wait becomes one budget from guard start (bash SECONDS) covering the lock wait and the idle wait: flock -w <remaining> when MAX_WAIT > 0, blocking otherwise. Lock timeout logs gave up waiting for guard lock and 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 export ROCM_GPU_GUARD_LOCK_HELD=$$ to it. A guard that starts with ROCM_GPU_GUARD_LOCK_HELD set skips locking and logs lock held by outer guard <pid>, so a nested guard cannot deadlock.
  • flock missing: exit 2 with rocm_gpu_guard: flock not found (util-linux). Do not silently run unlocked.
  • Update the header comment (and the sed -n '2,29p' range in usage() if the header grows) and docs/benchmarks.md:214-218.

Acceptance Criteria

  • run_guard in tests/test_rocm_decode_profile.py sets ROCM_GPU_GUARD_LOCK to 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 no CONTENDED line, and the second's start log line comes after the first's CLEAN. This test fails on main (both exit 75).
  • New test: lock held by an outside flock process, --max-wait 2 exits 75 and the command never runs.
  • New test: a guard run with ROCM_GPU_GUARD_LOCK_HELD set while the lock is held completes without waiting.
  • Existing GuardTests pass unchanged apart from the helper.

Verification

python3 -m unittest tests/test_rocm_decode_profile.py -v
bash -n scripts/rocm_gpu_guard.sh

Manual, 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.

Related: #2061, #2065, #1801.

Activity

  1. added
    status:ready
    type:bug
    priority:low
    area:benchmark
    platform:linux
    on Oct 6, 2026
  2. added
    status:in-progress
    status:review
    status:done
    and removed
    status:ready
    status:in-progress
    status:review
    on Oct 6, 2026
  3. added a commit that references this issue on Oct 14, 2026
    0ee13df
  4. added this to the 0.8 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:benchmarkplatform:linuxpriority:lowstatus:donetype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions