Skip to content

ci: run the semantic suite one file per process on every CPU (405 s -> 83 s on 4 jobs) - #4357

Open
tedin7 wants to merge 6 commits into
ItsNotRexed:mainfrom
tedin7:semantic-parallel
Open

tedin7 wants to merge 6 commits into
ItsNotRexed:mainfrom
tedin7:semantic-parallel

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown

Item: new, claimed here.
Depends on: none.

Why

The semantic-tests job runs python -m unittest discover -s tests/semantic -v: 7,456 tests in 365 files, one after another. On Linux (Python 3.13) that takes 405 s, against the job's timeout-minutes: 10, and the same job runs on windows-latest, which is slower. Every PR waits for it.

What

scripts/run_semantic_tests.py (standard library) runs each test file as python -m unittest discover -s tests/semantic -p FILE, the same discovery and imports as the serial command, on --jobs workers (default: the CPU count). Largest files start first so the pool does not end on one long file.

  • A failing file's whole output is printed, then one FAILED: file line per bad file and a total line.
  • Exit 1 when a file fails, errors, runs no test (Python 3.12+ exits 5 there, older 0: both count as not ok), or runs past --timeout (default 300 s per file; the file is stopped and reported, so one stuck file cannot hold the job until the CI limit), and when the folder holds no test file. Else 0.
  • CI's semantic-tests step calls it with --start tests/semantic (tests/test_ci_registration.py reads the folder from there); tests/semantic/README.md and CONTRIBUTING.md mention it next to the serial command, which still works.

Tested

Linux, Python 3.13, at main 79e7cc5e:

  • Serial python -m unittest discover -s tests/semantic: Ran 7456 tests in 405.0 s, FAILED (failures=7, errors=2, expected failures=1).
  • python -I scripts/run_semantic_tests.py --jobs 4: 365 files, 7456 tests, 83.3 s, the same failures in 3 files (test_cmp_class_f64.py, test_loop_ballot_barrier.py, test_mutations.py; they fail on main the same way, unrelated to this change), exit 1.
  • python -I tests/test_run_semantic_tests.py: 5 tests OK (passing files exit 0 with the test count; a failing file exits 1 and its assertion is shown; a stuck file is stopped at --timeout 3 and fails the run; a file that runs no test fails; a folder with no test file fails).
  • tests/test_docs_cli_flags.py, test_docs_repo_paths.py, test_docs_links.py, test_ci_registration.py, tests/semantic/test_spirv_tools_required.py: OK.

Not run: the Windows runner (the script uses only subprocess with sys.executable and UTF-8 output).

AI-assisted. No game files.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks tests/test_ci_registration.py at setUpClass. At 8d772ed5, the workflow line changed from python -m unittest discover -s tests/semantic -v to python -I scripts/run_semantic_tests.py, but ci_rules() (tests/test_ci_registration.py:65) still requires the old spelling:

AssertionError: ci.yml no longer spells unittest discover -s the way
tests/test_ci_registration.py expects it to; update this test together with the workflow
Ran 0 tests ... FAILED (errors=1)

tests/test_run_semantic_tests.py -> 5 tests, OK, so the new runner itself is fine. The fix is to update ci_rules/find in test_ci_registration.py to accept the new command (and still assert the semantic directory is covered), exactly as the guard's message says. Without that, the Windows unittest CI job fails before running any tests.

I could not check the claimed 405 s -> 83 s because the whole semantic suite is long; the registration guard is the blocking part.

@molodayamama

molodayamama commented Nov 23, 2026 •

Copy link
Copy Markdown

Independent Windows check of 8d772ed5b6dd06348ca462ec1f53ccc7729fccdd (Windows 10 22H2, CPython 3.12.12). The five runner unit tests passed. I found a Windows failure-reporting issue with redirected output on an ordinary non-UTF-8 code page.

Put import unittest and a unittest.TestCase whose test calls self.fail("unexpected pixel \U0001F642") in test_unicode.py, then run python -I scripts/run_semantic_tests.py --start <fixture-dir> --jobs 1 with output captured. On this host the parent stdout encoding is cp1251. The child uses forced UTF-8 as intended, but the parent then raises UnicodeEncodeError at print(out.rstrip()). It loses the original assertion and the final FAILED: test_unicode.py/total lines.

I verified locally that calling sys.stdout.reconfigure(errors="backslashreplace") before running the script keeps the failing assertion, diagnostic character escape and final summary, while still returning exit 1. That is one small way to preserve reports even when stdout is redirected on Windows. Synthetic test only. AI-assisted (Codex).

Full Windows run on Ryzen 5 5600, four workers: 365 files, 7,456 tests, 216.7 s. The runner reported failures in the three files listed in the PR description, plus test_vcmp16_opsel.py because spirv-as was absent from PATH (WinError 2). This is the outcome of the full run in this environment, with the separate CP1251 diagnostic repro described above.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @Kam471, my miss: I ran the runner's test and the docs tests but not tests/test_ci_registration.py. Fixed in f9d0db2: the workflow now runs python -I scripts/run_semantic_tests.py --start tests/semantic, so it still names the folder, and ci_rules() reads it from either spelling (unittest discover -s X or run_semantic_tests.py --start X); the runner keeps unittest's default test*.py pattern, which the test assumes. Linux, Python 3.13: test_ci_registration.py OK, tests/semantic/test_spirv_tools_required.py OK, test_run_semantic_tests.py 5 OK.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current head f9d0db26. The runner executes each top-level semantic test file through unittest discovery, reports each failed or timed-out file, and exits nonzero when no tests run. The CI-registration guard was updated with the new --start command, and the independent runner tests cover the failure paths. No blocking issue found.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked \ 9d0db26\ on Windows 11: \ ests/test_ci_registration.py\ -> 8 tests, OK; \ ests/test_run_semantic_tests.py\ -> 5 tests, OK; \git diff --check\ clean. Naming the semantic folder in the runner's command line resolves the registration guard, so the Windows job no longer fails at setUpClass. No blocking issue from me.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @molodayamama, good catch, and thanks for the full Windows run (216.7 s on four workers). Fixed in e9a9a5c: the runner sets errors="backslashreplace" on its own stdout and stderr, so a test's output that the redirected code page cannot encode is escaped instead of raising, and the assertion, the FAILED: lines and the total are kept. New test: a failing file whose message has U+1F642, runner run with PYTHONIOENCODING=ascii; it fails with the previous commit (UnicodeEncodeError) and passes now (exit 1, message shown as \U0001f642, summary present). test_run_semantic_tests.py: 6 tests OK (Linux, Python 3.13). Thanks @Flyander and @Kam471 for the re-checks.

@akimfomin

Copy link
Copy Markdown

Measured a same-machine Windows A/B on an i5-13600KF (Windows 11 28000.3501, CPython 3.12.14, SPIRV-Tools v2026.4-119-g3c8fd352 on PATH, LEONIDA_REQUIRE_SPIRV_TOOLS=1). The timing runs used the same f9d0db26 checkout, whose semantic test source is unchanged from 03b09a08. I ran the two commands one after the other.

  • python -m unittest discover -s tests/semantic -v ran 7,456 tests in 414.1 s.
  • python -I scripts/run_semantic_tests.py --start tests/semantic --jobs 4 ran 7,456 tests in 365 files in 155.3 s (2.67× on this machine).
  • Both returned exit 1. All nine failure/error identifiers matched exactly across test_cmp_class_f64.py, test_loop_ballot_barrier.py and test_mutations.py. No missing-SPIRV-tool failure on this setup.

After e9a9a5cf landed on the branch, I reran the runner tests (6/6, including redirected Unicode output) and CI registration tests (8/8). The full timings above are from f9d0db26. Synthetic tests only. AI-assisted (Codex).

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of e9a9a5c: the semantic runner is registered with the CI regex, propagates failures, timeouts and zero-test runs, and escapes unencodable output so a cp1251 capture cannot lose a failure report. Two suites: 8 and 7 tests OK; compileall and diff check clean.

AI-assisted (OpenCode).

… runs sub-package test files, notes uncounted tests (review)
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Follow-up from our own extra review of the runner (no reviewer on this thread raised these). Three changes in 7e8cc00:

  1. Timeout and grandchildren: each file's child now starts in its own process group (POSIX start_new_session, Windows CREATE_NEW_PROCESS_GROUP). On timeout the whole group is killed (os.killpg; taskkill /T /F /PID on Windows) and the output is collected with a bounded 10 s wait, so a descendant that holds stdout/stderr cannot stop the timeout from being reported. Verification note: on Linux with Python 3.13, subprocess.run did not hang in my reproduction (it kills only the child, then waits without reading the pipes); what I could reproduce is that the sleeping grandchild survived the timeout and kept running. The hang itself is the Windows path of subprocess.run, which I cannot run here. The new test starts a grandchild that inherits stdout, runs with --timeout 3, checks that TIMED OUT is reported well inside the bound and that the grandchild is gone. It fails on the previous commit and passes now.
  2. Sub-packages: the runner now finds test files at the top of --start and in sub-folders that hold an __init__.py, the same rule as unittest discover. A file in pkg/ is run as discover -s start/pkg -t start -p FILE so its imports resolve as in a full discovery, and it is listed as pkg/test_x.py. New test: a failing pkg/test_inner.py fails the run (exit 0 before). The real tests/semantic still yields the same 365 files.
  3. Summary line: when a file timed out it now reads "N tests (timed out, tests not counted)". Asserted in the existing timeout test.

Tests (Proxmox, Python 3.13): tests/test_run_semantic_tests.py 8 passed, tests/test_ci_registration.py 8 passed.

@Atomic258

Copy link
Copy Markdown

Tested 7e8cc009 on Linux, Python 3.10, CPU only, no game files: pass, including a real suite run.

  • python -I tests/test_run_semantic_tests.py → 8/8 and python -I tests/test_ci_registration.py → 8/8.
  • Real run: python -I scripts/run_semantic_tests.py --jobs 4 → 365 files / 7,456 tests in 138 s (claim was ~83 s on 4 jobs; this VM is slower per core). 4 files not ok: test_cmp_class_f64, test_loop_ballot_barrier, test_mutations, test_vcmp16_opsel.
  • Negative control: the same 4 files fail identically on main (python -I tests/semantic/<file>.py), so the failures are pre-existing environment/translator issues (one needs spirv-as, absent here), not the runner. Output and exit code match serial discovery.
  • git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@DoubleD17 DoubleD17 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7e8cc00941ad67440317d97e093d0897f349633a, specifically the new subpackage handling in scripts/run_semantic_tests.py:61-63.

The per-file discovery command can execute the same test twice. unittest discover -s <start> -t <start> -p test_shared.py also descends into packages under <start>; -p is a basename filter, not an exact file selector. With both test_shared.py and pkg/test_shared.py, test_files() schedules two jobs, but the root job discovers both modules and the package job discovers the nested module again. This inflates the count and can run shared side effects concurrently despite the one-file-per-process contract.

I checked the underlying discovery behavior on Windows, CPython 3.13.3, with two hand-written passing tests: serial discovery ran 2 tests; the root per-file command ran 2; the package per-file command ran 1. The nested test identifier appeared in both jobs (3 executions for 2 tests). Please add a same-basename root/package regression and make each worker load only its selected module, while retaining the correct import root. The current package regression uses different filenames, so it misses this overlap.

This is a static review plus an independent standard-library probe, not execution of this PR's runner or its test suite. I did not run the translator, GPU tests, or game data. The current semantic directory is flat, so this concerns the new advertised package support rather than a demonstrated failure in today's semantic CI job.

No game files. AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor

Windows check of 7e8cc00941ad67440317d97e093d0897f349633a (Windows 11, CPython 3.12.0, CPU only, scratch git archive; no game files): pass. This adds the Windows process-tree path to @Atomic258's Linux full-suite run; I did not re-run the 7,456-test suite here.

  • python -I tests/test_run_semantic_tests.py → 8 tests, 7 pass / 1 skip; test_ci_registration.py → 8/8; test_docs_links.py → 6/6; test_i18n_index.py → 5/5.
  • Negative control: the runner tests against untouched origin/main fail 7/8 (the tool is new); test_ci_registration.py passes on both, as expected for the CI spelling check.
  • Static read of kill_tree(): CREATE_NEW_PROCESS_GROUP + taskkill /T /F on Windows and start_new_session + os.killpg on POSIX both target the child's whole tree/group; the bounded second communicate() cannot hang forever on an escaped descendant holding the pipes.
  • compileall on touched Python files and git diff --check origin/main..7e8cc009 clean.

No blocking issue found.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of 7e8cc00: one issue in the new sub-package support, agreeing with DoubleD17. -p is a basename filter, so the per-file discovery command for a root file also descends into packages. With test_shared.py and pkg/test_shared.py, both scheduled jobs discover the nested module and it runs twice. I reproduced that with a two-file synthetic tree: the root command ran 2 tests and the package command ran 1 for the same 2-test corpus. The new regression uses different filenames, so it misses this. Loading the selected module by dotted name (unittest test_shared / unittest pkg.test_shared, with the start directory as the import root) would run each file once. The timeout/process-tree changes look sound: targeted suites 8 tests OK (1 skipped) and 8 tests OK; compileall clean.

AI-assisted (OpenCode).

…me-named file in a sub-package is not run twice (review)
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @DoubleD17 and @sds-228, you were right. unittest discover -p <basename> matches the basename in every package, so with tests/semantic/test_shared.py and tests/semantic/pkg/test_shared.py the root job also ran the nested file, twice and at the same time.

Fixed in 6cd6345. Each worker now loads only its own module by dotted name (unittest.main(argv=['unittest', 'pkg.test_shared'])) with the semantic folder first on sys.path, which is the import root discovery uses. Timeouts, process-group kill and the "no test ran" rule are unchanged.

Test: test_a_file_name_shared_with_a_sub_package_file_runs_once_each in tests/test_run_semantic_tests.py (same basename at the root and in a package, 2 + 2 tests, each file counted once). It fails on the previous runner (root job reports 4 tests, total 6) and passes now.

On the real tests/semantic: still 365 files and 7456 tests, and the same set of files pass or fail as with the previous runner (on my Linux box 8 files fail identically before and after, for environment reasons unrelated to this change).

@SweatierKey

Copy link
Copy Markdown
Contributor

Tested 6cd63450 on Linux (x86_64, Python 3.13.5, SPIRV-Tools on PATH): pass (code read + unit tests + live smoke run).

What I ran:

  • git diff --check 03b09a08..HEAD: clean.
  • python3 -m unittest -v tests/test_run_semantic_tests.py: 9/9 OK (including dotted-module sub-package deduplication, timeout + grandchild process-group kill, non-UTF-8 stdout survival, and empty-file failure).
  • Live smoke test: python3 -I scripts/run_semantic_tests.py --start tests/semantic --pattern "test_buffer_swizzle.py" --jobs 2 → exit 0, 1 files, 9 tests, 0 files not ok.

Code review:

  • Loading each discovered file by dotted module name with start prepended to sys.path cleanly avoids the duplicate-run bug with discover -p <basename> across sub-packages, while keeping unittest import semantics identical.
  • Process-group termination (start_new_session=True + os.killpg on POSIX, taskkill /T /F on Windows) with bounded KILL_WAIT cleanly handles grandchildren holding pipes open.
  • Minor non-blocking note: tests/test_run_semantic_tests.py:106 (int(open(pidfile).read())) emits a ResourceWarning: unclosed file under unittest; Path(pidfile).read_text() or a with open(...) silences it.

@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown

Tested 7e8cc00 on macOS 27.2.1 / CPython 3.15.2, Apple M3 Pro (12 cores), no GPU, no game files: pass.

Same test set, three ways, over tests/semantic (365 files):

run files tests wall result
python -m unittest discover -s tests/semantic - 7456 271.2 s 36 failures + 2 errors (the known macOS/arm64 environment failures: wave64 emulation and float64)
python -I scripts/run_semantic_tests.py --jobs 1 --verbose 365 7456 161.5 s the same 8 failing/erroring entries, same ids
--jobs 4 --verbose 365 7456 46.5 s the same 8 entries

5 files are not ok in both runner runs (test_alu_sdwa_hw.py, test_alu_vop3_mods_hw.py, test_cmp_class_f64.py, test_loop_ballot_barrier.py, test_mutations.py) and they are the same ones the serial discovery fails. So the test count and the failing set are identical between the serial path and the runner at 1 and at 4 jobs; here that is 271 s -> 46.5 s, 5.8x.

tests/test_run_semantic_tests.py 8/8 OK and tests/test_ci_registration.py 8/8 OK on head; compileall and git diff --check clean. Both new files are absent at 03b09a08, so the red side is "the tool and its test do not exist there".

POSIX kill_tree(): with three synthetic files that sleep 45 s each, --jobs 2 and SIGINT after 4 s, no direct child and no grandchild survives (pgrep empty afterwards) and the run leaves no orphans. One non-blocking observation: the runner itself exited only after 45.1 s, when those files ended on their own - Ctrl+C does not stop the files already running, because with ThreadPoolExecutor(...) waits for them, so a cancelled CI job can hold one --timeout (default 300 s) per running file. If that matters, the pool would have to shut down without waiting and kill_tree() the live children. Not a blocker for merging.

AI-assisted.

@Atomic258

Copy link
Copy Markdown

Tested 6cd6345092 on Linux, Python 3.10, CPU only, no game files: pass.

  • python -I tests/test_run_semantic_tests.py → 9/9.
  • python -I scripts/run_semantic_tests.py --jobs 4 --pattern "test_alu*.py" → 93 files, 1,664 tests, 0 files not ok (20.8 s).
  • This head replaces unittest discover -p <basename> with dotted-module loading (LOAD_ONE), which addresses the same-basename-in-two-packages collision raised earlier; the new unit cases cover it.
  • Full 365-file suite not re-run here (ran on the previous head: 4 failing files identical on main); the 93-file smoke covers the changed loading path.
  • git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown

Two data points to add to the run above.

The red side is stronger than "the file does not exist": base's tests/test_ci_registration.py asserts the old python -m unittest discover -s tests/semantic -v line, and run against this head's ci.yml it fails with AssertionError: ci.yml no longer spells unittest discover -s the way tests/test_ci_registration.py expects it to (1 error), while the same test against base's ci.yml is 8/8 OK. So the CI registration check really does pin the new command.

Scaling on 12 cores (same 365 files, 7456 tests, same 5 not-ok files every time): --jobs 1 162.3 s, --jobs 4 46.8 s, --jobs 8 33.0 s, default (12) 34.0 s. No gain past 8, because the floor is the longest single file (test_saveexec_b64.py, about 10.9 s alone). One thing to keep in mind rather than a blocker: --jobs defaults to the CPU count with no cap, and one file peaks at about 131 MB RSS, so 12 jobs is roughly 1.6 GB here and would grow with core count on a bigger runner.

AI-assisted.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of 6cd6345: no issues found. The earlier duplication finding is resolved — each file is now loaded by dotted module name with the semantic folder as import root, so a same-basename root and package file are loaded once each; the new regression covers exactly that case. Timeout/process-tree handling and the zero-test rule are unchanged. Targeted suites: 9 tests OK (1 skipped) and 8 tests OK; compileall and diff check clean.

AI-assisted (OpenCode).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @wavehs, very useful numbers (162 s at 1 job, 47 s at 4, 33 s at 8, nothing more past 8 because the longest file sets the floor). Taken in aee690d: --jobs now defaults to the CPU count capped at 8, so a big runner does not start one ~130 MB worker per core for no gain; an explicit --jobs can still go higher. New test DefaultJobs.test_the_default_is_the_cpu_count_capped (1, 2, 8 and 64 CPUs; fails before, passes now). tests/test_run_semantic_tests.py: 10 tests OK. #4513 (open) also roughly halves that longest file, which lowers the floor.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of aee690d: no issues found. The new delta caps the default worker count at 8 while leaving an explicit --jobs unlimited; the earlier dotted-module deduplication is unchanged. New regression covers 1, 2, 8 and 64 CPUs. Targeted suites: 10 tests OK (1 skipped) and 8 tests OK; compileall and diff check clean.

AI-assisted (OpenCode).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.