Skip to content

Commit e7b1620

Browse files
authored
Fix perf-smoke seeder JIT cache isolation (#6543)
## Summary Fixes the L40S baseline seeding failure seen in the post-#6498 staging run: ```text PermissionError: [Errno 13] Permission denied: /tmp/jit-cache/warp/... ``` The seed workflow runs many benchmark containers serially in one job. Reusing one host-mounted JIT cache allowed one container to leave Warp cache directories with ownership/permissions that blocked later samples from compiling Newton/Warp kernels. This change gives the seeder a per-run/per-attempt JIT cache root and a per-sample cache directory, while keeping the Kit cache shared. ## Test plan - [x] `/home/horde/dev/IsaacLab-fork/.venv/bin/python -m pytest tools/perf_smoke_test/test/test_seed_ancestry.py --noconftest -q -p no:cacheprovider` - [x] `/home/horde/dev/IsaacLab-fork/.venv/bin/python -m pytest tools/perf_smoke_test/test/ --noconftest -q -p no:cacheprovider` - [ ] Rerun `Performance Smoke - Seed Baselines` on `perf-smoke/develop-staging` after merge to validate on L40S.
1 parent d47f80a commit e7b1620

2 files changed

Lines changed: 94 additions & 5 deletions

File tree

‎tools/perf_smoke_test/seed_baselines.py‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
from __future__ import annotations
4141

4242
import argparse
43+
import atexit
4344
import json
4445
import os
46+
import shutil
4547
import subprocess
4648
import sys
4749
import tempfile
@@ -348,6 +350,36 @@ def _prepare_seed_source(workdir: Path, seed_src_dir: Path, sha: str) -> None:
348350
subprocess.run(["chmod", "-R", "a+rwX", str(seed_src_dir)], check=False)
349351

350352

353+
def _prepare_jit_cache(cache_dir: Path) -> Path:
354+
"""Create a writable JIT cache directory for one task/backend bucket."""
355+
for subdir in (cache_dir / "warp", cache_dir / "nv"):
356+
subdir.mkdir(parents=True, exist_ok=True)
357+
# Containers can write cache files as a different uid than the runner.
358+
_run(["chmod", "-R", "0777", str(cache_dir)], check=False)
359+
return cache_dir
360+
361+
362+
def _jit_cache_path(cache_root: Path, target_branch: str, commit: str, task_id: str, backend_key: str) -> Path:
363+
"""Return the cache shared by repeated samples of one task/backend bucket."""
364+
return (
365+
cache_root
366+
/ _safe_path_component(target_branch)
367+
/ commit[:8]
368+
/ _safe_path_component(task_id)
369+
/ _safe_path_component(backend_key)
370+
)
371+
372+
373+
def _cleanup_jit_cache(cache_dir: Path) -> None:
374+
"""Remove the disposable JIT cache for one seeder invocation."""
375+
if not cache_dir.exists():
376+
return
377+
subprocess.run(["chmod", "-R", "a+rwX", str(cache_dir)], check=False, capture_output=True, text=True)
378+
shutil.rmtree(cache_dir, ignore_errors=True)
379+
if cache_dir.exists():
380+
print(f"::warning::[seed] Could not fully remove JIT cache {cache_dir}")
381+
382+
351383
def _docker_run_benchmark(
352384
*,
353385
image: str,
@@ -363,6 +395,9 @@ def _docker_run_benchmark(
363395
seed_token = f"--seed {task.seed}" if task.seed is not None else ""
364396
inner = (
365397
"set -e\n"
398+
# Warp creates nested cache directories at runtime. A permissive umask
399+
# keeps them writable when successive containers use different host uids.
400+
"umask 000\n"
366401
"cd /workspace/isaaclab\n"
367402
"rm -f _isaac_sim\n"
368403
"ln -s /isaac-sim _isaac_sim\n"
@@ -589,11 +624,13 @@ def main() -> int:
589624
seed_src_dir = (
590625
Path(args.seed_src_dir).resolve() if args.seed_src_dir else Path(tempfile.gettempdir()) / "perf-seed-src"
591626
)
592-
jit_cache = workdir / "jit-cache"
627+
run_id = os.environ.get("GITHUB_RUN_ID", f"local-{os.getpid()}")
628+
run_attempt = os.environ.get("GITHUB_RUN_ATTEMPT", "0")
629+
jit_cache_root = workdir / "jit-cache" / "seed" / f"run-{run_id}-attempt-{run_attempt}"
630+
atexit.register(_cleanup_jit_cache, jit_cache_root)
593631
kit_cache = workdir / "kit-cache"
594-
for sub in (jit_cache / "warp", jit_cache / "nv", kit_cache):
595-
sub.mkdir(parents=True, exist_ok=True)
596-
_run(["chmod", "-R", "0777", str(jit_cache), str(kit_cache)], check=False)
632+
kit_cache.mkdir(parents=True, exist_ok=True)
633+
_run(["chmod", "-R", "0777", str(kit_cache)], check=False)
597634

598635
plan = _build_seed_plan(args)
599636
plan = _filter_plan_by_ancestry(
@@ -637,6 +674,9 @@ def main() -> int:
637674
prep_skips.append(f"{target_branch}/{short}")
638675
continue
639676
for task in tasks:
677+
task_jit_cache = _prepare_jit_cache(
678+
_jit_cache_path(jit_cache_root, target_branch, commit, task.task_id, task.backend_key)
679+
)
640680
for sample_idx in range(args.samples_per_commit):
641681
total += 1
642682
artifact_dir = (
@@ -658,7 +698,7 @@ def main() -> int:
658698
image=args.image,
659699
task=task,
660700
artifact_dir=artifact_dir,
661-
jit_cache=jit_cache,
701+
jit_cache=task_jit_cache,
662702
kit_cache=kit_cache,
663703
seed_src_dir=seed_src_dir if source_mount else None,
664704
container_name=container,

‎tools/perf_smoke_test/test/test_seed_ancestry.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,52 @@ def test_filter_unresolvable_tip_keeps_when_lenient_raises_when_strict(repo) ->
131131

132132
with pytest.raises(RuntimeError, match="cannot resolve tip"):
133133
seed_baselines._filter_plan_by_ancestry(plan, work, target_sha="", strict=True)
134+
135+
136+
def test_prepare_jit_cache_opens_task_cache(tmp_path: Path) -> None:
137+
"""Each task/backend bucket gets writable Warp/CUDA cache roots."""
138+
cache_dir = tmp_path / "jit-cache" / "seed" / "task" / "newton"
139+
140+
prepared = seed_baselines._prepare_jit_cache(cache_dir)
141+
142+
assert prepared == cache_dir
143+
assert (cache_dir / "warp").is_dir()
144+
assert (cache_dir / "nv").is_dir()
145+
assert cache_dir.stat().st_mode & 0o777 == 0o777
146+
147+
148+
def test_jit_cache_reuses_samples_and_isolates_backends(tmp_path: Path) -> None:
149+
"""Repeated samples share compiled kernels, but different backends do not."""
150+
cache_root = tmp_path / "jit-cache" / "seed" / "run-1-attempt-1"
151+
newton_cache = seed_baselines._jit_cache_path(
152+
cache_root, "perf-smoke/develop-staging", "abcdef123456", "Isaac-Cartpole-Direct", "newton"
153+
)
154+
repeated_newton_cache = seed_baselines._jit_cache_path(
155+
cache_root, "perf-smoke/develop-staging", "abcdef123456", "Isaac-Cartpole-Direct", "newton"
156+
)
157+
physx_cache = seed_baselines._jit_cache_path(
158+
cache_root, "perf-smoke/develop-staging", "abcdef123456", "Isaac-Cartpole-Direct", "physx"
159+
)
160+
161+
_ = seed_baselines._prepare_jit_cache(newton_cache)
162+
compiled_kernel = newton_cache / "warp" / "compiled-kernel.so"
163+
compiled_kernel.write_bytes(b"compiled")
164+
_ = seed_baselines._prepare_jit_cache(repeated_newton_cache)
165+
166+
assert repeated_newton_cache == newton_cache
167+
assert compiled_kernel.read_bytes() == b"compiled"
168+
assert physx_cache != newton_cache
169+
assert not physx_cache.exists()
170+
171+
172+
def test_cleanup_jit_cache_removes_run_tree(tmp_path: Path) -> None:
173+
"""Seeder exit cleanup removes compiled kernels from its run directory."""
174+
cache_dir = tmp_path / "jit-cache" / "seed" / "run-1-attempt-1"
175+
compiled_dir = cache_dir / "warp" / "version" / "module"
176+
compiled_dir.mkdir(parents=True)
177+
(compiled_dir / "kernel.so").write_bytes(b"compiled")
178+
compiled_dir.chmod(0o500)
179+
180+
seed_baselines._cleanup_jit_cache(cache_dir)
181+
182+
assert not cache_dir.exists()

0 commit comments

Comments
 (0)