Fix POSIX GPU read completion and aligned `O_DIRECT` tail offsets #1244
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1244"
general
weight: 0.35
gigony
closes #1159
Summary
CuFileDriver::preadreturns, including when a later read or copy fails andpreadreturns −1. WhencudaMemcpycopies from pageable host memory to device memory, it blocks until CUDA has copied the bytes into staging memory. The DMA transfer to the GPU can still be pending when the call returns. The copy runs on the default stream, and legacycuslidedecodes on a separate nonblocking stream that can read the buffer before the copy completes. The wait runs only when the read issued a host-to-device copy, so host-buffer reads andcuFileReadare unchanged. CUDA copy semantics · CUDA stream ordering · RTX PRO 6000 hang (#1159)O_DIRECTrequest. Previously, the tail read and the write’s read-modify-write cycle could access the wrong page. Failing wheel jobCommits
1. Complete POSIX-staged GPU reads before returning. Adds a default-stream wait before a successful
preadreturns after staging through host memory.2. Honor file offsets in aligned
O_DIRECTtail I/O. Adds the requested file offset to the tail read and to the write's read-modify-write. New regressions cover reads and writes into page-aligned host buffers at offset 4,096, with and without a preceding full block.3. Complete staged GPU reads on error returns. Host-to-device copies go through one helper that records whether a copy was issued. Every return, including the −1 error returns, then waits for the default stream if one was. This keeps a failed read from returning while a copy into the caller's buffer is still in flight.
errnois preserved across the wait.4. Cover aligned
O_DIRECTtails with device buffers. Runs the same regressions with page-aligned CuPy buffers, which exercise thecudaMemcpybranches of both tail paths.CI failures observed
test_batch_read_cuda_memory_cleanupstart without a result in two attempts. The third attempt passed. Its relationship to the RTX failures remains open. V100 runtest_bindings_cuimage.py::test_cuda_array_interfacereads a crop, andtest_tiff_read_region.py::test_cuda_array_interface_supportreads the full tiled JPEG TIFF. The Python trace showed the binding test still insideread_region(). Full-image run · Crop runtest_filesystem_roundtriprequested 16 bytes at offset 4,096 and received bytes 0–15 from the first page. The buggy POSIXO_DIRECTtail path requires both the buffer and the file offset to be page-aligned. The file offset was already aligned, so the failure depended on whether NumPy placed the 16-byte destination buffer on a page boundary. A later wheel run stopped at 99% and reached its job limit. The progress output left the unfinished test unidentified. Wrong-offset failure · Wheel timeoutInvestigation
1. Reproduce the hang with traces. Diagnostics PR #1240 added pytest stack dumps and native phase markers, then repeated all three suspect CUDA tests 100 times each with eight workers. In the RTX hangs, legacy
cuslidesubmitted the nvJPEG decode successfully. CUDA error 700 surfaced during stream synchronization, and loader teardown then waited on a tile worker until the job timed out. Focused run2. Isolate input delivery. Buffered host staging passed with the same device-input decoder. Preloading nvJPEG
13.1.0.59and13.2.3.58into the original CUDA 13.0.3 environment reproduced the hang. The first preload attempt stopped at archive extraction becausexzwas missing, and the completed preload runs confirmed the requested versions. Host staging · Preload setup · nvJPEG 13.1 · nvJPEG 13.23. Isolate synchronization. I/O tracing identified the unaligned POSIX
O_DIRECTfallback in the failed reads. After a blocking GPU readback, the compressed tile bytes matched a buffered reference read. A follow-up added just a default-stream wait before decode to isolate ordering from the readback and comparison. Readback comparison · Wait-only comparison4. Reproduce the offset bug independently. A page-aligned buffer and forced POSIX
O_DIRECTreproduced the wheel failure locally. A corresponding partial write at offset 4,096 also changed the first page. Both tail paths used the length of the preceding full blocks as an absolute file offset. The regressions exercise reads and writes with and without a preceding full block. Aligned tail read · Aligned tail writeValidation
CuFileDriverfix passed all 300 focused CUDA trials with POSIX fallback forced. A nonblocking CUDA consumer received the correct bytes across all five tested read paths.b438c19bon an RTX A6000, all 28 tests intest_bindings.pypassed, including all 14 filesystem tests. The eight aligned-tail regressions (four host-buffer, four CuPy) all failed on the build with only the wait. A separate probe with a page-aligned CuPy buffer also reproduced incorrect results in six reads and six writes at offset 4,096 on that build. All 12 cases passed with the offset fix.LD_PRELOADshim made the tailpreadof an alignedO_DIRECTread returnEIO, after the first block had been copied to a CuPy buffer. gdb breakpoints on libcucim'scudaMemcpyandcudaStreamSynchronizerecorded the order of calls:- At the tip: libcucim synchronized the default stream after the
EIOand beforepreadreturned −1.- Before commit 3:
preadreturned −1 without waiting.- 42 runs with plain pytest;
- 11 runs with the CI command (eight xdist workers plus coverage).
O_DIRECTfallback. All 33 jobs passed in this diagnostics run ate92fbd6a, which tested the success-path wait alone. The branch tipb438c19bincludes all four commits and still needs its own CI run. Focused Conda job · Full runNot in this PR
Staged GPU reads that extend past end-of-file can loop forever: the copy loops make no progress when
::preadreturns 0. In addition, the aligned tail reports bytes past end-of-file as read. This behavior predates this PR and is not related to the #1159 traces. A separate follow-up change can be made for that issue.Cost of the wait
The added synchronization waits for any DMA still pending on the default stream. With concurrent tile workers, it can also wait for copies that another worker queued on that stream.
An exploratory RTX A6000 benchmark timed a POSIX fallback read followed by a readback on a nonblocking stream. Across three alternating runs per build, the timings showed no consistent change. The run-to-run variation was too large to resolve a small cost.
| Read size | Baseline (µs per read and readback) | With the wait (µs per read and readback) |
| --- | ---: | ---: |
| 2,862 B | 93–188 | 77–193 |
| 1,844,293 B | 3,270–3,340 | 3,180–3,492 |