Skip to content

tests: serve GPU draw cases from one offscreen_check device - #2766

Open
tedin7 wants to merge 10 commits into
R0Y00:mainfrom
tedin7:x2w-fastdraw
Open

tedin7 wants to merge 10 commits into
R0Y00:mainfrom
tedin7:x2w-fastdraw

Conversation

@tedin7

@tedin7 tedin7 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #448

What this unblocks: the GPU draw checks create the D3D12 device once per test instead of once per case, which is where #448 measured most of the time (about 0.25 s of start-up per launch against about 0.03 s per case on a real card with the debug layer on).
Source: Microsoft D3D12 documentation, D3D12CreateDevice and ID3D12Device lifetime; earlier code of this repo (tests/offscreen_check draw cases and their CTest entries in CMakeLists.txt).

What changed

  • offscreen_check <warp|hardware> --serve (tests/offscreen_check.cpp): runs any other operation, case after case, on the one device it already created. One case per stdin line, the operation and its operands separated by tabs, exactly the arguments that follow the adapter name in a one-shot call. Each case goes through the same argument validation, capability gate, debug-layer check and exit-code mapping as a one-shot call (0, 1, 77, 2), and its stdout and stderr text is what the one-shot call prints. Both streams end the case with a marker line so the client can split the text per case; the debug messages are cleared between cases; a removed device ends the loop after answering.
  • tests/gpu_case_runner.py: run(renderer, adapter, args) has the signature and result of subprocess.run([renderer, adapter, *args], capture_output=True, text=True), but starts one --serve process per renderer and adapter and sends the case to it. The adapter banner is repeated in front of every case, so a check that looks for debug_layer=enabled and debug_errors=0 debug_warnings=0 sees it in each case, as in a one-shot call. Only a server that cannot start (an older offscreen_check without --serve, no adapter, X2W_FLAT_SERVER=0) falls back to the one-shot call. Once a case has been sent, a renderer that dies, does not answer within one deadline or answers with the wrong case number gives a FAILED verdict for that case and is never run again, so a crash cannot turn into a pass; both reply indices are validated and the renderer is ended as a whole process group.
  • Adopted by startup_flat_param_check.draw (imported by 50 checks, among them startup_gfx2hlsl_f16_alu_draw), startup_gfx2hlsl_f32_sdwa, startup_gfx2hlsl_f32_nan and startup_image_sample_b. Their cases, references and controls are unchanged. startup_flat_param_check.compile_hlsl now routes DXC compiles through the opt-in X2W_DXC_CACHE cache that pixel_aot_check and compute_store_check already use.
  • tests/gpu_case_runner_check.py (new, gpu_case_runner): a fake offscreen_check that speaks the protocol checks per-case text and exit codes, the banner with every case, skip (77), a renderer without --serve, a crash after the handshake (failed verdict, case not run again), a silent renderer (one deadline), a wrong reply index, a launcher child that keeps the pipes open, a second-case debug warning, and X2W_FLAT_SERVER=0.

Builds on the batching work in #2635, #2654, #2615 and #2690 and the compiler reuse in #2711 (credit to RavenCurseBurg), and on the DXC cache of #448. Those make one test launch fewer processes by batching its references; this adds the same saving for every check that still starts a process per case, without changing any test's cases.

Why it is safe

Every case of the four adopted checks was run twice on Windows Server 2025 WARP, once through the served device and once through the old one-shot call, and compared (exit code, stdout, stderr; the banner is part of each served case and was compared too):

check cases identical wrong-value controls (both paths must fail)
startup_gfx2hlsl_f16_alu_draw 220 220 32 of 32 failed on both, same message
startup_gfx2hlsl_f32_nan 194 194 28 of 28
startup_gfx2hlsl_f32_sdwa 288 288 42 of 42
startup_image_sample_b 72 72 11 of 11

Each control changes one bit of the expected words (or the first byte of the reference file) of every seventh case and runs it through both paths.

Time (Windows Server 2025 WARP, idle host, one run each, DXC cache off)

check one-shot served
startup_gfx2hlsl_f32_nan 8.2 s 2.1 s
startup_gfx2hlsl_f32_sdwa 12.0 s 2.7 s
startup_image_sample_b 4.1 s 1.7 s
startup_gfx2hlsl_f16_alu_draw 26.7 s 20.7 s

f16_alu_draw still spends most of its time compiling one vertex shader per case with DXC and FXC one after the other; that is the next step (compiling in parallel), not part of this change. The saving on a real card is larger, because the debug layer makes each launch more expensive.

What stays the same

Only --startup-flat-param, --startup-pixel-words and --startup-image-2d-array-mips cases changed path; every other operation and every check that is not listed above is untouched. offscreen_check --self-test still validates the operation table, and --serve itself is listed there like any other operation.

Verification

  • python3 -B tests/gpu_case_runner_check.py: all tests OK (Linux).
  • python3 -B tests/startup_flat_param_check.py: controls OK (Linux).
  • Windows Server 2025 (aws-1), dev build of offscreen_check with this change and ctest -R 'gpu_case_runner|startup_gfx2hlsl_f16_alu_draw|startup_gfx2hlsl_f32_sdwa|startup_gfx2hlsl_f32_nan|startup_image_sample_b_(warp|hardware)|startup_flat_param': 15/15 passed.
  • Old versus new per case and the wrong-value controls: the table above, run with the same binary on WARP.
  • RunPod (RTX 3090, Wine + vkd3d-proton, hardware adapter), same old-versus-new comparison on the same binary:
check cases identical wrong-value controls one-shot served
startup_gfx2hlsl_f16_alu_draw 220 220 32 of 32 failed on both 441.7 s 8.1 s
startup_gfx2hlsl_f32_nan 194 194 28 of 28 322.8 s 7.2 s
startup_gfx2hlsl_f32_sdwa 288 288 42 of 42 476.4 s 8.3 s
startup_image_sample_b 72 72 11 of 11 138.5 s 5.4 s

(times are the summed offscreen_check calls only, not compiles.) ctest of the same 15 tests: 15/15 passed.

  • Win2025 WARP (proxmox pool), dev and release on the final head, 17/17 each: cmake --build --preset <dev|release> --target offscreen_check then ctest --preset <dev|release> --no-tests=error -R "gpu_case_runner|startup_gfx2hlsl_f16_alu_draw|startup_gfx2hlsl_f32_sdwa|startup_gfx2hlsl_f32_nan|startup_image_sample_b|startup_flat_param|draw_skip" -V (gpu_case_runner, startup_flat_param_{controls,warp,hardware}, startup_image_sample_b_{controls,warp,hardware}, startup_gfx2hlsl_f32_nan{,_warp,_hardware}, startup_gfx2hlsl_f32_sdwa{,_warp,hardware}, startup_gfx2hlsl_f16_alu_draw{controls,warp,hardware}, startup_gfx2hlsl_draw_skip).

AI-assisted; commands listed were executed locally.

c1 added 4 commits November 26, 2026 07:43
… compiled shaders

offscreen_check --serve runs any operation case after case on one D3D12 device; tests/gpu_case_runner.py starts it once per test and falls back to the one-shot call on any problem. compile_hlsl gets a content-addressed object cache. Adopted by startup_flat_param_check (draw), f32_sdwa, f32_nan and image_sample_b. Builds on R0Y00#2711 and R0Y00#2690.
@R0Y00

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

I reproduced the Linux failure on this head. The f32_nan and f32_sdwa cases now call gpu_case_runner.run, so the existing subprocess.run mock misses them and Popen tries to execute the fake renderer. In startup_gfx2hlsl_draw_skip_check.py, set renderer_runner = getattr(module, "gpu_case_runner", module.subprocess) and patch renderer_runner.run. On Windows Python 3.12 this kept all 18 existing subcases green, including failure-before-skip = 1 and clean skip = 77.

The five runner tests also pass here, but emit ResourceWarning for unclosed pipes and a live child after fallback. Please close the stdio handles and wait for the process on every exit, including failed handshake and dead-server restart. The runner test should verify cleanup before calling the one-shot fallback.

The adopted draw checks now go through gpu_case_runner.run, so the late-skip check patches that instead of subprocess.run.
@RavenCurseBurg

Copy link
Copy Markdown
Contributor

I will check the updated served renderer on native Windows D3D12 on the Intel UHD 770 and RTX 4060, with WARP as a control. I will compare the one-shot and served routes on the same executable, including wrong expected values followed by valid draws, and report the exact head and timings here.

A failed handshake, a dead server and the restart now wait for the process, join the pump threads and close all three pipes; a runner test checks it before the one-shot fallback.
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the repro and the exact fix.

  • Linux failure: fixed in 6c2e55d. startup_gfx2hlsl_draw_skip_check.py now also patches gpu_case_runner.run, next to the existing subprocess.run patch, so the 18 subcases (failure-before-skip = 1, clean skip = 77) stay green. I kept both patches instead of getattr(module, "gpu_case_runner", ...) because the same loop also covers modules that still call subprocess.run.
  • ResourceWarning: fixed in aa6c9bd. Every exit of a served process (failed handshake, skip 77, dead server and its restart, close at exit) now waits for the process, joins the two reader threads and closes stdin, stdout and stderr. New runner test test_every_exit_leaves_no_process_and_no_open_pipe checks that each of those servers has exited and has all three pipes closed, before the one-shot fallback result is used; I also fixed the test's own cleanup order, which emptied the server table before closing the servers. python3 -B -W error::ResourceWarning tests/gpu_case_runner_check.py: 6 tests OK; the four adopted checks also run clean with that flag.
  • Old versus new on a real card (RTX 3090, Wine + vkd3d-proton, same executable): f16_alu_draw 220/220, f32_nan 194/194, f32_sdwa 288/288, image_sample_b 72/72 identical (exit code, stdout, stderr); 113/113 wrong-value controls fail on both routes with the same message. Table in the description.

@RavenCurseBurg, thank you for checking native Windows D3D12 on the Intel UHD 770 and RTX 4060. The head to test is aa6c9bd.

AI-assisted; commands listed were executed locally.

…rdict

Every served case now carries the adapter banner (debug_layer line) like a one-shot call; both reply markers must carry the case number; one deadline per case; a renderer that dies, hangs or answers the wrong case after the handshake fails that case and is never re-run. New runner controls fail on the previous runner.
@R0Y00

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Windows 11 build 26200, Python 3.12, exact 7e0a4e39: python -B -W error::ResourceWarning tests/gpu_case_runner_check.py failed 2/9. The crash reported a 300 s timeout immediately, and the 2 s hang case returned after 60.06 s. The separate draw-skip ordering test passed.

I isolated two causes. The Windows fake runs through a .cmd parent. Killing that parent leaves its sleeping Python child holding stdout/stderr, so cleanup blocks until the child exits. Launching the fake Python renderer directly made the 2 s hang test pass, but the crash still raced EOF against Popen.poll(). With the direct child plus a bounded self.proc.wait(timeout=max(0.0, deadline - time.monotonic())) when the reply is missing, all 9 tests passed with ResourceWarning promoted to an error. The exit-code check and the no-replay assertions stayed in place. Please make the Windows fake a direct child of the runner and preserve the one shared deadline when collecting the process status.

@RavenCurseBurg

Copy link
Copy Markdown
Contributor

Native Windows comparison at 7e0a4e39: all 2,694 one-shot/served pairs matched on exit code, full stdout and full stderr, including the repeated adapter banners. The comparison covers the four adopted checks on WARP, Intel UHD 770 and RTX 4060. The runner stayed attached to the live server throughout each suite.

Suite Fixture calls per adapter Extra wrong-value + restored pairs Total paired calls per adapter
image sample bias 72 4 + 4 80
binary16 ALU 220 32 + 32 284
binary32 NaN 194 13 + 13 220
binary32 SDWA 288 13 + 13 314

Each of the 62 additional wrong-value calls per adapter returned 1 through both routes and printed the same mismatch; the immediately following valid draw returned 0. For timing, one-shot/served summed renderer call times in seconds were WARP 147.86 / 14.99, UHD 770 524.30 / 36.81, RTX 4060 454.01 / 53.20. The three suites of adapter measurements ran concurrently on the same host, with alternating call order and shader compilation outside the timer. These are single-run measurements under load.

Windows 11 build 26100.9711, in-box D3D12, WARP 10.0.26100.9711, Intel 32.0.101.5973, NVIDIA 32.0.15.9579. The debug layer was unavailable. The local Zig 0.13/Clang build included the PR's actual service loop, argument and diagnostic paths, the three adopted operation handlers, desktop GPU setup and D3D12 draw implementations. The local executable selected those operations and explicitly flushed output at one-shot exit for MinGW. All four suites used both DXC and FXC. The comparison script also takes a standard full offscreen_check.exe:

python -B tests/verify_served_native_parity.py <renderer> <dxc> <fxc> <WARP|Intel|NVIDIA> <output-dir>

The separate process-lifecycle unit suite reproduced the two Windows failures already reported above, including the 2-second case returning after 60.43 seconds. The device comparisons above all completed. AI-assisted with Codex.

… missing

The runner accepts the renderer as a command list; the runner tests launch the fake interpreter directly so a kill releases its pipes on Windows too. A missing reply waits for the process only up to the case deadline, so a crash reports its exit code instead of a timeout.
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you both, this is exactly the data I needed.

@R0Y00: both causes fixed in 069f172.

  • The runner now accepts the renderer as a command list, and the runner tests launch the fake interpreter and its script directly, so there is no .cmd or shell parent holding the pipes after a kill.
  • When a reply is missing, the runner waits for the process only up to the same case deadline (proc.wait(timeout=max(0, deadline - now))) before reading its exit status, so a crash reports exited (code 3) and not a timeout. One deadline per case stays.
  • The exit-code check and the no-replay assertion (the case log shows the crashing case once) are unchanged. On Linux: 9 tests OK with -W error::ResourceWarning, and the four adopted checks plus the draw-skip check pass. I cannot run Windows Python 3.12 here, so please re-run python -B -W error::ResourceWarning tests/gpu_case_runner_check.py on 069f172.

@RavenCurseBurg: thank you for the 2,694 matching pairs on WARP, UHD 770 and RTX 4060, wrong-value controls included. Your numbers are for 7e0a4e3; the runner changed only in the process handling since, not in the protocol, the banners or the verdict mapping.

AI-assisted; commands listed were executed locally.

@R0Y00

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Rechecked 069f1722 on native Windows 11 build 26200 with Python 3.12. python -B -W error::ResourceWarning tests/gpu_case_runner_check.py now passes 9/9, including the 2 s deadline and crash exit-code tests. startup_gfx2hlsl_draw_skip_check.py also passes. This resolves my two Windows runner findings. Raven's 2,694 paired GPU results above were on the preceding head; this run covers the revised process-handling tests.

The Wine launcher on RunPod does not pass the end of stdin to the renderer, which stayed alive and held the pipes of the test. The client now writes --end before closing stdin and the service loop stops on it; an older renderer answers 2 and still ends at the end of stdin.
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@R0Y00: thank you for the native Windows re-check of 069f172 (9/9 and the draw-skip check).

Gate status from our independent reviewer: code gate PASS on 069f172. Win2025 dev and release 17/17 each (gpu_case_runner passes there in 13 s), served-versus-one-shot compared on every case of the four adopted checks with the banner included, wrong-value controls included: 0 mismatches. A RunPod run showed one intermittent 1800 s timeout of startup_gfx2hlsl_f32_sdwa_warp on that head; it did not repeat on the next head, and the re-gate on that head is running.

The head is now 43360b0: the client ends the served renderer with an explicit --end line before closing stdin (the service loop stops on it), because a Wine launcher may not pass the end of stdin on. An older renderer answers that line with exit 2 and still ends at the end of stdin. Nothing else changed in the protocol, banners or verdicts.

AI-assisted; commands listed were executed locally.

…a pipe

A Wine launcher leaves the real renderer alive after its wrapper is killed, and it keeps the test's pipes open: closing the pipe then blocked the test for good (seen on RunPod as 1800 s timeouts). The renderer now runs in its own process group, which is killed with it; a pipe is closed only when its reader has ended. New runner test with a launcher child that holds the pipes.
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Independent review of head f5747cc (served GPU draw cases): PASS.

Verification:

  • Windows Server 2025 (D3D12 WARP), dev 17/17 and release 17/17 with ctest --no-tests=error -R 'gpu_case_runner|startup_gfx2hlsl_f16_alu_draw|startup_gfx2hlsl_f32_sdwa|startup_gfx2hlsl_f32_nan|startup_image_sample_b|startup_flat_param|draw_skip': gpu_case_runner, startup_flat_param_{controls,warp,hardware}, startup_image_sample_b_{controls,warp,hardware}, startup_gfx2hlsl_f32_nan{,_warp,_hardware}, startup_gfx2hlsl_f32_sdwa{,_warp,hardware}, startup_gfx2hlsl_f16_alu_draw{controls,warp,hardware}, startup_gfx2hlsl_draw_skip.
  • Same verdicts with and without the fast path: on the previous head, a patched runner sent every case of the four adopted checks through the served device and through the one-shot call and asserted identical exit code, stdout (banner included) and stderr: 16 tests, no mismatch, wrong-value controls included. The commits since only change how the renderer process is ended.
  • Review findings re-checked with controls that fail before the fix: a second-case debug warning now fails the sample_b-style check; a renderer crash after the handshake is a failed verdict and the case is not run again; both reply indices are validated; one deadline per case; a launcher child holding the pipes no longer blocks the end of the test (removing the group kill makes that test fail). Linux python3 -B tests/gpu_case_runner_check.py passes; mutating the failed verdict to a pass, dropping the index check or dropping the per-case banner each fail the check.
  • The PR body now describes the final behaviour (failed verdict instead of a retry, banner with every case, strict comparison).
  • Not run here: RunPod (non-blocking, off). A test that fails without the explicit --end line is still missing; closing stdin also ends the server in the fake renderer, so the line itself is covered only by the real Wine run.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 10:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T10:52:41.975949Z f5747cc Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5747cc0bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/gpu_case_runner.py
Comment on lines +177 to +179
text = ''.join(server._drain(server.err)) if server.proc.poll() is not None else ''
server.kill()
return subprocess.CompletedProcess(server.proc.args, 1, '', 'gpu_case_runner: %s\n%s' % (reason, text))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain renderer diagnostics when a served case is lost

When a renderer writes a diagnostic and then crashes or times out before its end markers, this returns only the generic _Lost message. For crashes, case() has already consumed the unmarked stderr chunk before raising; for timeouts, this skips draining while the renderer is alive and never recovers output after killing it. The empty stdout also drops the cached adapter/driver/debug-layer banner on first-case failures. A fake renderer printing an error before exiting with code 3 reproduces the diagnostic loss. Preserve the collected chunks, post-termination output and banner in the failed result.

AGENTS.md reference: AGENTS.md:L95-L96

Useful? React with 👍 / 👎.

Comment on lines +90 to +93
def setUp(self):
R._servers.clear()
self.addCleanup(R._servers.clear)
self.addCleanup(R._close_all) # runs first: the servers of the test are closed before the table is emptied

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reset the opt-out flag for the served-path unit tests

When X2W_FLAT_SERVER=0 is set to exercise the supported one-shot path, R.SERVER_OFF is already True at import and this fixture never overrides it. The served-path tests consequently execute one-shot calls and fail—for example, test_served_cases_carry_their_own_text_and_exit_code receives the unexpected ONESHOT prefix. Since the runner check is registered in CMake, running the suite with the opt-out produces spurious failures even though the fallback works correctly. Save and restore R.SERVER_OFF in the fixture and set it to False for the served-path tests.

Useful? React with 👍 / 👎.

Comment on lines +195 to +197
os.kill(pid, 0)
except ProcessLookupError:
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Distinguish terminated zombies from live launcher children

In a Linux container whose PID 1 does not reap orphaned children, _close_all() successfully kills the grandchild but its PID remains as a zombie. os.kill(pid, 0) still succeeds for that dead process, so this loop reaches self.fail() and the runner check rejects correct cleanup. This reproduces in the current container, where the child has state Z; all 10 tests pass under a reaping harness. Check whether the child is actually running or arrange for the fixture to reap it instead of requiring the PID to disappear.

Useful? React with 👍 / 👎.

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.

3 participants