[cudax] Do not read managed memory from the host after starting work in the stream adaptor #12134
<!-- coderabbit-ai-generated:v1 -->
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/NVIDIA/cccl/pull/12134?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a>
<!-- review_stack_entry_end -->
<!-- This is an auto-generated comment: skip review by coderabbit.ai -->
[!IMPORTANT]
## Review skipped
> Review was skipped as selected files did not have any reviewable changes.
>
>
> <details>
<summary><strong>⚙️ Run configuration</strong></summary>
<dl>
<dd>
> - Source mode: Auto
- Repository: [NVIDIA/cccl](<https://github.com/NVIDIA/cccl>)
- Branch: [main](<https://github.com/NVIDIA/cccl/tree/main>)
- File: [.coderabbit.yaml](<https://github.com/NVIDIA/cccl/blob/b94ca2aa922d45b9b53e3ce4eff9a9a5e252c7f1/.coderabbit.yaml>)
- Commit: [b94ca2a](<https://github.com/NVIDIA/cccl/commit/b94ca2aa922d45b9b53e3ce4eff9a9a5e252c7f1>)
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Enterprise
- Run ID: 2aac8f12-bd8b-44da-9fc1-3d93726e636f> </dd>
</dl>
</details>
> <details>
<summary><strong>📥 Commits</strong></summary>
<dl>
<dd>
> Reviewing files that changed from the base of the PR and between e71d8b43d912b668e48b9dd6d34a76f67b9d9e69 and c13fdef8eb6a82e09792ff06c043d0d761896527.
> </dd>
</dl>
</details>
> You can disable this status message by setting thereviews.review_statustofalsein the CodeRabbit configuration file.
> Use the checkbox below for a quick retry:
- [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review
<!-- end of auto-generated comment: skip review by coderabbit.ai -->
<!-- recent_review_start -->
No actionable comments were generated in the recent review. 🎉
<details>
<summary><strong>ℹ️ Recent review info</strong></summary>
<dl>
<dd>
<details>
<summary><strong>⚙️ Run configuration</strong></summary>
<dl>
<dd>
6c3df3bb-9d80-40a5-9b1d-1d62cd443c8c</dd>
</dl>
</details>
<details>
<summary><strong>📥 Commits</strong></summary>
<dl>
<dd>
Reviewing files that changed from the base of the PR and between 6ad0be74a142127e0cf8a90f54210325b26538ee and 5d8496d776d4c2e4cb3c81643ca5481739e1d98d.
</dd>
</dl>
</details>
<details>
<summary><strong>📒 Files selected for processing: 1</strong></summary>
<dl>
<dd>
cudax/include/cuda/experimental/__execution/stream/adaptor.cuh</dd>
</dl>
</details>
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.
</dd>
</dl>
</details>
<!-- recent_review_end -->
<!-- walkthrough_start -->
<details>
<summary><strong>📝 Summary</strong></summary>
<dl>
<dd>
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
- Improved reliability when launching completion operations on systems without concurrent managed-memory access, including Windows and WSL.
- Prevented potential invalid access to stream state after device work has started.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
The host start path now captures __stream_ before starting the child operation. It uses the local stream reference for the completion-kernel launch.
Changes: Stream adaptor start path
|Layer / File(s)|Summary|
|:---|:---|
|Capture stream and launch completion kernel <br> cudax/include/cuda/experimental/__execution/stream/adaptor.cuh|__host_start copies __stream_ to a local variable before starting the child operation. The completion-kernel launch then uses that local stream.|
Possibly related issues
</dd>
</dl>
</details>
<!-- walkthrough_end -->
<!-- change_assessment_start -->
Priority: ➖ Normal
<!-- change_assessment_commit:"5d8496d776d4c2e4cb3c81643ca5481739e1d98d" -->
Change: Bug fix · Severity of issue fixed: Medium
<!-- change_assessment_end -->
<details>
<summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>5d849</code></summary>
<dl>
<dd>
<!-- final_review_risk_start -->
<!-- final_review_risk_label
Merge Risk: ⚪ Minimal · up to 5d849
-->
<!-- final_review_risk_coverage:{"sourceCommitId":"5d8496d776d4c2e4cb3c81643ca5481739e1d98d","coveredCommitId":"5d8496d776d4c2e4cb3c81643ca5481739e1d98d","kind":"reviewed"} -->
The targeted stream capture fix is ready to merge; no actionable risks remain.
<!-- final_review_risk_end -->
</dd>
</dl>
</details>
<!-- autopilot:start -->
<!-- autopilot:end -->
<!-- tips_start -->
<sub>Comment @coderabbitai help to get the list of available commands.</sub>
<!-- tips_end -->
lgtm
andralex
SUKUNA-AI
Description
Fixes the
stdexec_streamsegfault from #8902. Thevector_addfailure there is a separate problem; see below.On devices where
cudaDevAttrConcurrentManagedAccessis 0 (Windows, and Linux under WSL2), the host must not touch managed memory while a kernel is running.__stream::__opstate_t::__host_startinstream/adaptor.cuh:1. starts the child operation, which launches the predecessor kernels;
2. then calls
::cuda::launch(__stream_, ...), which reads the__stream_member (launch.h:611builds__ensure_current_contextfrom the submitter).When this opstate lives in the
__managed_boxthat the streamsync_waitallocates (sync_wait.cuh:101), step 2 is a host read of managed memory while a kernel is in flight. The process faults: SIGSEGV on WSL2,0xC0000006on Windows. In gdb, every crashing[stream]test case stops atadaptor.cuh:281, reached from thestart()call on line 275.This change copies the stream into a local before starting the child operation.
schedule_from.cuhalso reads__stream_afterstart(), but its opstate is documented as being stored in host memory, so I left it unchanged.Testing
RTX 5070 Ti (sm_120), driver 617.42,
concurrentManagedAccess == 0:| | before | after |
|---|---|---|
|
cudax.test.execution(WSL2, nvcc 13.4.59, gcc 16.2) | 7 of 9[stream]test cases crash | 197/197 test cases pass ||
cudax/examples/stdexec_stream.cu(WSL2) | SIGSEGV | passes ||
cudax/examples/stdexec_stream.cu(native Windows, nvcc 13.4.92, MSVC 19.51, C++20) |0xC0000006| passes |Before the change, everything passes with
CUDA_LAUNCH_BLOCKING=1, which matches the diagnosis.The
vector_addfailure from #8902 is a different problem. With this change it still fails on native Windows (MSVC), and it passes on WSL2 with gcc.Checklist
[stream]test cases incudax.test.execution. They only fail on devices without concurrent managed access, so Linux CI does not see this.)