NVIDIA / stdexec

`std::execution`, the proposed C++ framework for asynchronous and parallel programming.
Apache License 2.0
1.56k stars 159 forks source link

Add a sender adaptor for setting the current allocator associated with the receiver #314

Closed anthonywilliams closed 10 months ago

anthonywilliams commented 2 years ago

As described in issue #313 some algorithms may require memory allocation, however there is no mechanism in P2300R3 for specifying which allocator to use for this memory allocation.

In many scenarios it is essential to be able to control memory allocations. I therefore propose adding allocator support to let_value as follows:

let_error and any other algorithms that can allocate should be adjusted in a similar fashion.

ericniebler commented 2 years ago

In sender/receiver, state like allocators isn't passed into the algorithm; it is associated with the receiver with queries like get_allocator(Receiver). If you know the allocator when you are calling the algorithm and want it to be used, you would write a sender adaptor with_allocator(Sender, Allocator) that, when connect-ed, would wrap the incoming receiver with one that implemented the get_allocator query and returned the allocator.

EDIT: Rather than forcing the world to write with_allocator, P2300 would do well to ship with sender adaptors that correspond to the existing receiver queries. My $0.02.

anthonywilliams commented 2 years ago

OK: if get_allocator is the way to go, then we need with_allocator in the paper.

ericniebler commented 2 years ago

We'll probably want several of these sender adaptors; e.g., for setting the current scheduler, or the current stop token. In libunifex, we have just one sender adaptor that can be parameterized on a receiver query CPO, which might be the right way to go here.

ericniebler commented 10 months ago

moved to cplusplus/sender-receiver#56