← Back to Pull requests

Fix `cuMemcpyBatchAsync` with `cuMemHostRegister`-ed host memory on WSL2 #1108

Closed
unknown closed this pull request without merging on Nov 02, 2026 20:41 UTC
View on GitHub
unknown unknown commented on Nov 02, 2026 17:41 UTC
Author

Summary

On WSL2, every KvikIO write from device memory fails with CUDA_ERROR_ILLEGAL_ADDRESS (in FileHandle::pwrite -> posix_device_write), in both compat and GDS modes.

Since #954, posix_device_io copies with cuMemcpyBatchAsync (via cuda_memcpy_async). Writes stage data through CudaPageAlignedPinnedBounceBufferPool, which pins an aligned_alloc buffer with cuMemHostRegister. On devices where CU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM is 0 (as on WSL2), the device address of such memory differs from its host address (for example host 0x7fffa5dfe000 maps to device 0x204e00000). cuMemcpyAsync translates the host address, but cuMemcpyBatchAsync does not: it returns CUDA_SUCCESS and the copy engine writes to the raw host address. The fault only appears at the next cuStreamSynchronize. Reads aren't affected because their bounce buffers come from cuMemHostAlloc, whose addresses match.

This change replaces each pinned host pointer with its cuMemHostGetDevicePointer alias before calling cuMemcpyBatchAsync. Only pointers that cuPointerGetAttribute reports as host memory are translated, so device pointers are passed through unchanged. Where host and device addresses are identical the alias equals the host pointer and behavior does not change.

Two regression tests copy to and from a page-aligned, cuMemHostRegister-ed buffer in both directions.

Dependency

This is stacked on the DevBuffer fix in #1107 (the first commit in this PR), because the new tests are only reliable with it. That PR should merge first; until then this diff also shows its commit.

Testing

On WSL2 (RTX 2070 Super, driver 617.14, CUDA 13.3):

  • The two new tests fail on 3 of 3 runs with CUDA_ERROR_ILLEGAL_ADDRESS without the fix and pass with it.

  • SHIM_CUDA_TEST: 25 of 25 runs pass.

  • Full ctest: 29 of 29 pass. Without the fix, BASIC_IO_TEST and OBSERVATION_TEST fail on this machine.

  • The Python suite passed on an earlier revision of this change, before the final refactor. I have not re-run it on this commit.
  • Diff: 261 lines (+195 / -66) across 3 files Reviewer: wence- Review duration: 179m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 261 lines diff across 3 files
    0.39
    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.333
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1108"
    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: 39.2% (MEDIUM) · Higher = larger blast radius
    39.2%
    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: 15.5% · Safe to merge
    15.5%