Skip to content

nvexec(continues_on): basic transition#2031

Open
romintomasetti wants to merge 1 commit intoNVIDIA:mainfrom
romintomasetti:continues-on-nvexec
Open

nvexec(continues_on): basic transition#2031
romintomasetti wants to merge 1 commit intoNVIDIA:mainfrom
romintomasetti:continues-on-nvexec

Conversation

@romintomasetti
Copy link
Copy Markdown
Contributor

@romintomasetti romintomasetti commented Apr 17, 2026

On the machines I could test, very basic transitions with nvexec::strean_context never work (it segfaults).

I already flagged this in:

@ericniebler I haven't looked for a fix, but this bug seems quite important to fix. Feel free to work with this branch, I won't touch anymore 😉

For the record, here is the stack trace reported by cuda-gdb: output.log.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Apr 17, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ericniebler
Copy link
Copy Markdown
Collaborator

thanks for the test cases. the stream scheduler has a curious history. it was written several years ago by a coworker who is a CUDA ninja, but was new to std::execution. i am not a CUDA guru (although i'm getting better). the stream scheduler code is ... challenging for me. when i try to fix bugs there i lose whole days. and sometimes my "fixes" cause other issues, or performance regressions.

all this is to say, if anybody has an interest in digging into this, they would have my undying gratitude. i agree the current situation is unsatisfactory.

@maartenarnst
Copy link
Copy Markdown

The issue appears to be caused by a double call to schedule_from.

Once in the continues_on sender expression:

schedule_from(static_cast<_Sender&&>(__sndr)));

And then once more in nvexec's implementation:

: sndr_(schedule_from(static_cast<Sender&&>(sndr)))

This patch avoids the seg fault in my build:

From eb0868543dc7a742418661675270dcb4eb7af76b Mon Sep 17 00:00:00 2001
From: Maarten Arnst <maarten.arnst@uliege.be>
Date: Sun, 19 Apr 2026 09:42:25 +0200
Subject: [PATCH] Avoid double call to schedule_from

Signed-off-by: Maarten Arnst <maarten.arnst@uliege.be>
---
 include/nvexec/stream/continues_on.cuh | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/nvexec/stream/continues_on.cuh b/include/nvexec/stream/continues_on.cuh
index a7ee8f26..eb254959 100644
--- a/include/nvexec/stream/continues_on.cuh
+++ b/include/nvexec/stream/continues_on.cuh
@@ -172,15 +172,13 @@ namespace nv::execution::_strm
     template <class Sender>
     struct source_sender : stream_sender_base
     {
-      using schedule_from_sender_t = __result_of<schedule_from, Sender>;
-
       explicit source_sender(Sender sndr)
-        : sndr_(schedule_from(static_cast<Sender&&>(sndr)))
+        : sndr_(static_cast<Sender&&>(sndr))
       {}

       template <__decay_copyable Self, STDEXEC::receiver Receiver>
       STDEXEC_EXPLICIT_THIS_BEGIN(auto connect)(this Self&& self, Receiver rcvr)
-        -> connect_result_t<__copy_cvref_t<Self, schedule_from_sender_t>, Receiver>
+        -> connect_result_t<__copy_cvref_t<Self, Sender>, Receiver>
       {
         return STDEXEC::connect(static_cast<Self&&>(self).sndr_, static_cast<Receiver&&>(rcvr));
       }
@@ -201,7 +199,7 @@ namespace nv::execution::_strm
       }

      private:
-      __result_of<schedule_from, Sender> sndr_;
+      Sender sndr_;
     };

     template <class... Ty>
--
2.39.2 (Apple Git-143)

(It seems I can't push directly with a commit to the branch).

@romintomasetti
Copy link
Copy Markdown
Contributor Author

I confirm that @maartenarnst 's fix works. I'll push it.

Signed-off-by: romintomasetti <romin.tomasetti@gmail.com>
Signed-off-by: Maarten Arnst <maarten.arnst@uliege.be>
Signed-off-by: romintomasetti <romin.tomasetti@gmail.com>
@romintomasetti
Copy link
Copy Markdown
Contributor Author

The following still segfaults (switching from one context to another):

  TEST_CASE("continues on a different context instance", "[cuda][stream][adaptors][continues_on]")
  {
    nvexec::stream_context ctx_A, ctx_B;

    auto sndr = STDEXEC::just()
              | STDEXEC::continues_on(ctx_A.get_scheduler())
              | STDEXEC::continues_on(ctx_B.get_scheduler());

    STDEXEC::sync_wait(std::move(sndr));
  }

@ericniebler It's probably fine to merge this PR as a first step, i.e. it fixes the transition "to itself".

@ericniebler
Copy link
Copy Markdown
Collaborator

/ok to test ace3bba

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.

3 participants