Repository navigation
Conversation
…d of a fresh one plus gc.collect per translation
|
At One thread. Translate Run from the checkout root with from pathlib import Path
import sys
sys.path.insert(0,str(Path("tests/semantic").resolve()))
import support as s
def check(name, value):
lines=[f"v_mov_b32_e32 v0, {value}", "exp mrt0 v0, v0, v0, v0 done vm", "s_endpgm"]
return s.mrt0_words(s.translate_lines(name,lines))[0]
print([check(name,value) for name,value in (("ps_case",1),("ps_CASE",2),("ps_case",1))])Two threads. With identical names, pause the first call after it writes the listing. Let the second call translate and finish. Resume the first. Both calls return 2. The merge base returns 1 and 2. This case does not depend on filename case. The scheduling hook below calls the real translator in both threads. from pathlib import Path
import sys,threading
from concurrent.futures import ThreadPoolExecutor
from unittest.mock import patch
sys.path.insert(0,str(Path("tests/semantic").resolve()))
import support as s
def check(value):
lines=[f"v_mov_b32_e32 v0, {value}", "exp mrt0 v0, v0, v0, v0 done vm", "s_endpgm"]
return s.mrt0_words(s.translate_lines("ps_shared",lines))[0]
first_ready=threading.Event()
release=threading.Event()
real=s.rdna2spirv.translate
def ordered(path):
if threading.current_thread().name.startswith("worker"):
first_ready.set()
assert release.wait(10)
return real(path)
with patch.object(s.rdna2spirv,"translate",ordered), ThreadPoolExecutor(1,thread_name_prefix="worker") as pool:
a=pool.submit(check,1)
assert first_ready.wait(10)
try: b=check(2)
finally: release.set()
print(a.result(),b)Please keep scratch files private to each active translation or serialize the writes and the translator read. Within each reusable directory, make the cache key match the filesystem's name rules. The three existing AI-assisted. Memory use with distinct names. The new cache keeps the full listing bytes for each name until process exit. After 32, 64, and 128 translations, the cache still holds 1,050,688, 2,101,376, and 4,202,752 listing bytes after garbage collection. The merge base keeps zero listing bytes between calls. These figures count only the listing payloads. The synthetic probe uses a 32 KiB comment to make the growth easy to measure. The existing Run this from the checkout root with import gc
import sys
from pathlib import Path
sys.path.insert(0, str(Path("tests/semantic").resolve()))
import support
for i in range(128):
data=b";"+bytes([65+i%26])*32768+b"\n\tv_mov_b32_e32 v0, 1\n\texp mrt0 v0, v0, v0, v0 done vm\n\ts_endpgm\n"
support.translate_listing(f"ps_retention_{i}",data)
del data
if i+1 in (32,64,128):
gc.collect()
cache=getattr(support,"_scratch",{}).get("files",{})
listings=[v for k,v in cache.items() if k.endswith(".s")]
print(i+1,len(listings),sum(map(len,listings)), flush=True) |
|
Tested Bug confirmed — the scratch cache returns another listing's shader. Reproduced @shdann's one-thread case verbatim (translate
Command: Sanity: Environment note: repro depends on a case-insensitive volume; this host's AI-assisted (Devin); no game files. |
|
Full tests/semantic run, per-test outcomes, on upstream/main (a), main + #4828 (b), main + #4827 (c), main + both (d). Runner: #4357's scripts/run_semantic_tests.py (copied into scratch worktrees, not committed), unmodified, with a thin wrapper that loads each file with a result class printing
|
…and keys files by normcase A listing could be translated after another call overwrote it (two threads, same name), and ps_case/ps_CASE were two cache keys for one file on a case-insensitive volume, so a later write was skipped.
|
Confirmed both, thank you. On Pushed f5d60f2:
New Ran on Linux, CPython 3.12.16: the new file passes 2/2. Negative control: with the previous |
|
Independent CPU + SPIRV-Tools verification on Linux (Python 3.13.5,
Looks good to merge. |
|
Native Windows check of f5d60f2 (the scratch-cache race and case-collision fix), since the earlier run was Linux only. Windows 11, CPython 3.13.1, a detached worktree on the NTFS C: volume, which is case-insensitive (
Worktree deleted afterwards. |
|
Tested f5d60f2 on Windows 11 (26200), Python 3.12: pass. Full |
|
Native Windows run of the files the previous check did not reach, at Files run: the 245
Still not run natively: the one full-directory |
|
Verified against main 3faac55 (clean merge): tests/semantic/test_support_scratch_cache.py passes 2/2 under python -I, and a combined single-process pytest run of the new test plus test_alu_bitfield_rev, test_andn2_exec_b64 and test_vcmp16_opsel passes 62 tests / 1061 subtests (re-run) — the cross-file check that matters for a shared support.py change. tools/rdna2spirv.translate reads only name-derived paths (no directory scan — verified), so the shared scratch directory cannot mix listings; the RLock and normcase keying cover the write/translate race and case-insensitive-name aliasing. One note: test_andn2_exec_b64 cannot start under python -I on this Python 3.14 host — a pre-existing bare-import issue reproduced on plain main, untouched by this PR. CI was pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
|
Tested
|
|
Measured the corrected scratch-cache head with the same six physical CPU cores and six workers for every run. I ran the full synthetic semantic suite in separate fresh processes, in base/head, head/base, base/head order.
Median wall time fell from 43.9 s to 40.5 s (7.7% on this host). The two added tests passed in all three runs. All six suite exits were 1: exactly the same three failing subtests and two errors in CachyOS x86-64, CPython 3.12.13. |
Item: new TEST item, claimed here. Depends on: none. Touches only
tests/semantic/support.py(#4706 also edits that file, in other places; trivial merge either way).What was slow. Every semantic test that goes through
support.translate_listingmade a fresh temp directory, wrote two files, translated, ran a fullgc.collect(), then removed the directory. Profile oftest_vcmp_f32_predicates(Linux 3.12.16):gc.collect3205 calls = 34 of 74 s under the profiler. Profile oftest_vcmpx_formson Windows 3.13.1:open37 of 75 s (file writes in fresh directories); a micro-benchmark gives 4.1 ms per mkdtemp+write+read+rmtree cycle against 0.2 ms for reads of existing files.Fix. One scratch directory per process (removed at exit, with a
gc.collect()retry only if removal fails), files rewritten only when their content changes, no per-callgc.collect(). The translator sees the same input files.Measured (shared, loaded machines; before -> after):
test_vcmp_f32_predicates62 s -> 44.5 s,test_vcmpx_forms51.5 s -> 34.5 s.test_vcmp_f32_predicates14.7 / 52.0 s -> 9.2 / 21.0 s;test_saveexec_b6439.6 / 44.4 s -> 66.1 / 26.4 s (noisy: one slow outlier).Equivalence. 27 semantic files (a seeded sample plus the five slowest,
test_ps_semanticsandtest_mutations) pass on the branch, the same as main. Negative control:test_mutations(13 translator mutations, each must failtest_ps_semantics) still passes with this support.py, so a sabotaged translator is still caught. I did not complete a full-suite run on both main and the branch (the machine was too loaded); that is the gap.AI-assisted.