Skip to content

when_all: implementation missing mechanism for explicit resource transition? #1937

@maartenarnst

Description

@maartenarnst

In a when_all with child senders that complete on different execution contexts, it appears the resource transitions are not explicit. This appears to be at odds with the p2300 proposal:

We propose that, for senders advertising their completion scheduler, all execution resource transitions must be explicit; running user code anywhere but where they defined it to run must be considered a bug.

For example, if we build a sender like,

TEST(WhenAll, different_domain_children) {
    experimental::execution::single_thread_context cpu{};
    nvexec::stream_context gpu{};

    auto when_all = stdexec::when_all(
        stdexec::schedule(cpu.get_scheduler()) | stdexec::then([] { }),
        stdexec::schedule(gpu.get_scheduler()) | stdexec::then([] __device__ { }));

    auto sndr = std::move(when_all) | stdexec::continues_on(cpu.get_scheduler()) | stdexec::then([] { });

    stdexec::sync_wait(sndr);
}

there is a resource transition from the gpu to the cpu, but it appears the current implementation of when_all does not make it explicit. In particular, the implementation of when_all does not insert a schedule_from to transition away from the gpu.

Note that it appears that the continues_on may not be considered to be responsible for the transition because the completion domain of the when_all is the default_domain. Also note that this snippet does not compile because of a host device error, but this compilation problem might be separate from the conceptual problem of how to think of resource transitions in when_all.

We therefore wanted to ask whether it is a deliberate design decision that the current implementation of when_all does not end branches with an explicit resource transition? If so, how should we think of such resource transitions?

Joint work with @romintomasetti.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions