Skip to content

always use std::atomic; stop preferring cuda::std::atomic (#2042) - #2601

Merged
ericniebler merged 1 commit into
NVIDIA:mainfrom
ericniebler:std-atomic-unconditionally
Dec 5, 2026
Merged

ericniebler merged 1 commit into
NVIDIA:mainfrom
ericniebler:std-atomic-unconditionally

Conversation

@ericniebler

Copy link
Copy Markdown
Collaborator

Fixes #2042.

__atomic.hpp switched all of STDEXEC::__std's atomics to cuda::std::atomic whenever <cuda/std/atomic> was merely installed. On Windows cuda::std::atomic<T>::wait polls instead of using WaitOnAddress, which made sync_wait wake-up latency ~15 ms rather than ~6 µs (benchmark in the issue).

Nothing in stdexec/exec needs it:

  • nvexec already spells ::cuda::std::atomic_flag and ::cuda::atomic_ref<..., thread_scope_*> itself (detail/queue.cuh, stream/common.cuh, stream/split.cuh), via detail/cuda_atomic.cuh.
  • nvexec's host-side shared state (when_all, ensure_started) already uses std::atomic.
  • No stdexec atomic is instantiated in device code.

This removes STDEXEC_HAS_CUDA_STD_ATOMIC() and the STDEXEC_DISABLE_CUDA_STD_ATOMIC opt-out (the Relacy tests no longer need it), and drops the !STDEXEC_HAS_CUDA_STD_ATOMIC() condition on __atomic_shared_ptr.

Behavior change: user code that called stdexec's own atomic-backed facilities (e.g. inplace_stop_token::stop_requested(), intrusive_ptr) from __device__ code relied on cuda::std::atomic and would now get a host-from-device error. Nothing in the repo does this.

Testing: with std::atomic used unconditionally, test.nvexec builds and passes (136 cases, 789 assertions) with nvcc 13.5 (g++-15 host, sm_86) and nvc++ 26.11. A host build of sync_wait on static_thread_pool passes with g++-15 at C++20/26. Clang-CUDA is untested; CI will cover it.

🤖 Generated with Claude Code

__atomic.hpp switched the whole of STDEXEC::__std's atomics to
cuda::std::atomic whenever <cuda/std/atomic> was merely installed. On Windows
cuda::std::atomic<T>::wait polls instead of using WaitOnAddress, so sync_wait
latency was ~15 ms instead of ~6 us.

Nothing needs it: nvexec spells ::cuda::std::atomic_flag and
::cuda::atomic_ref<..., thread_scope_*> itself, and its host-side shared state
already uses std::atomic. test.nvexec builds and passes (136 cases) with nvcc
13.5 and nvc++ 26.11 with std::atomic used unconditionally.

Remove STDEXEC_HAS_CUDA_STD_ATOMIC and STDEXEC_DISABLE_CUDA_STD_ATOMIC; Relacy
no longer needs the opt-out.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ericniebler
ericniebler merged commit def9704 into NVIDIA:main Dec 5, 2026
46 checks passed
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.

Use of cuda::std::atomic is surprising

1 participant