← Back to Pull requests

Fix POSIX GPU read completion and aligned `O_DIRECT` tail offsets #1244

Closed
unknown closed this pull request without merging on Nov 24, 2026 02:00 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 15:35 UTC
Author

closes #1159

Summary

  • Wait for POSIX-staged GPU copies to complete before CuFileDriver::pread returns, including when a later read or copy fails and pread returns −1. When cudaMemcpy copies 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 legacy cuslide decodes 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 and cuFileRead are unchanged. CUDA copy semantics · CUDA stream ordering · RTX PRO 6000 hang (#1159)

  • Include the requested file offset when reading or writing the final partial block of an aligned O_DIRECT request. Previously, the tail read and the write’s read-modify-write cycle could access the wrong page. Failing wheel job
  • Commits

    1. Complete POSIX-staged GPU reads before returning. Adds a default-stream wait before a successful pread returns after staging through host memory.
    2. Honor file offsets in aligned O_DIRECT tail 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. errno is preserved across the wait.
    4. Cover aligned O_DIRECT tails with device buffers. Runs the same regressions with page-aligned CuPy buffers, which exercise the cudaMemcpy branches of both tail paths.

    CI failures observed

  • V100 Conda nightly. The original #1159 report showed test_batch_read_cuda_memory_cleanup start without a result in two attempts. The third attempt passed. Its relationship to the RTX failures remains open. V100 run

  • RTX PRO 6000 Conda. Full-suite runs stalled in two CUDA array-interface tests. test_bindings_cuimage.py::test_cuda_array_interface reads a crop, and test_tiff_read_region.py::test_cuda_array_interface_support reads the full tiled JPEG TIFF. The Python trace showed the binding test still inside read_region(). Full-image run · Crop run

  • RTX PRO 6000 wheel. test_filesystem_roundtrip requested 16 bytes at offset 4,096 and received bytes 0–15 from the first page. The buggy POSIX O_DIRECT tail 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 timeout
  • Investigation

    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 cuslide submitted 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 run
    2. Isolate input delivery. Buffered host staging passed with the same device-input decoder. Preloading nvJPEG 13.1.0.59 and 13.2.3.58 into the original CUDA 13.0.3 environment reproduced the hang. The first preload attempt stopped at archive extraction because xz was missing, and the completed preload runs confirmed the requested versions. Host staging · Preload setup · nvJPEG 13.1 · nvJPEG 13.2
    3. Isolate synchronization. I/O tracing identified the unaligned POSIX O_DIRECT fallback 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 comparison
    4. Reproduce the offset bug independently. A page-aligned buffer and forced POSIX O_DIRECT reproduced 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 write

    Validation

  • On RTX PRO 6000, the paired control reproduced seven CUDA 700 hangs. Adding a default-stream wait before decode passed all 300 trials. Control · Wait-only job

  • On the local RTX A6000, the CuFileDriver fix passed all 300 focused CUDA trials with POSIX fallback forced. A nonblocking CUDA consumer received the correct bytes across all five tested read paths.

  • With libcucim built from the branch tip b438c19b on an RTX A6000, all 28 tests in test_bindings.py passed, 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.

  • Error-path wait. An LD_PRELOAD shim made the tail pread of an aligned O_DIRECT read return EIO, after the first block had been copied to a CuPy buffer. gdb breakpoints on libcucim's cudaMemcpy and cudaStreamSynchronize recorded the order of calls:

  • - At the tip: libcucim synchronized the default stream after the EIO and before pread returned −1.
    - Before commit 3: pread returned −1 without waiting.
  • Test exit. The binding tests passed and exited cleanly in repeated local runs:

  • - 42 runs with plain pytest;
    - 11 runs with the CI command (eight xdist workers plus coverage).
  • CI before commits 3 and 4. The copy-completion fix passed all 300 focused trials in normal device-read mode on RTX PRO 6000. The log confirms successful waits in the unaligned O_DIRECT fallback. All 33 jobs passed in this diagnostics run at e92fbd6a, which tested the success-path wait alone. The branch tip b438c19b includes all four commits and still needs its own CI run. Focused Conda job · Full run
  • Not in this PR

    Staged GPU reads that extend past end-of-file can loop forever: the copy loops make no progress when ::pread returns 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 |

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gigony Review duration: 4944m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository