Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
async_impl.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "async_ops.hpp"
10#include "buffers.hpp"
11
12namespace uni20::async
13{
14
15template <typename T>
16template <typename U>
17 requires detail::async_assignment_source<T, U>
19{
20 if constexpr (!is_async_alias_v<T>)
21 {
22 if constexpr (detail::async_source<U>)
23 {
24 Async<T> replacement;
25 async_initialize(replacement, std::forward<U>(rhs));
26 *this = std::move(replacement);
27 }
28 else
29 {
30 *this = Async<T>(std::forward<U>(rhs));
31 }
32 }
33 else
34 {
35 async_assign(*this, std::forward<U>(rhs));
36 }
37 return *this;
38}
39
42template <typename T> void Async<T>::wait() const { this->read().wait(); }
43
47template <typename T> void Async<T>::wait(IAsyncScheduler& sched) const { this->read().wait(sched); }
48
52template <typename T> T const& Async<T>::get_wait() const { return this->read().get_wait(); }
53
58template <typename T> T const& Async<T>::get_wait(IAsyncScheduler& sched) const { return this->read().get_wait(sched); }
59
63template <typename T>
65 requires(!is_async_alias_v<T> && std::constructible_from<T, T &&>)
66{
67 return this->write().move_from_wait();
68}
69
74template <TaskAwaitable A> inline auto TaskPromiseBase::await_transform(A& a) { return TaskAwaiter<A&>(a, *this); }
75
80template <TaskAwaitable A> inline auto TaskPromiseBase::await_transform(A&& a)
81{
82 return TaskAwaiter<std::remove_reference_t<A>>(std::move(a), *this);
83}
84
89template <TaskFactoryAwaitable A> inline auto TaskPromiseBase::await_transform(A& a)
90{
91 return TaskFactoryAwaiter<A&>(a, *this);
92}
93
98template <TaskFactoryAwaitable A> inline auto TaskPromiseBase::await_transform(A&& a)
99{
100 return TaskFactoryAwaiter<std::remove_reference_t<A>>(std::move(a), *this);
101}
102
103} // namespace uni20::async
Concepts and helpers for composing Async expressions.
Defines shared and concrete task coroutine promises.
Awaitable capabilities for shared reads and exclusive mutable access to Async<T>.
Async<T> is a container for coroutine-safe asynchronous read/write.
Definition async/async.hpp:93
T move_from_wait()
Block until the value is available, then move it out of the Async.
Definition async_impl.hpp:64
T const & get_wait() const
Block the current thread until the value becomes available.
Definition async_impl.hpp:52
Async & operator=(U &&rhs)
Assign an immediate or heterogeneous async value.
void wait() const
Block the current thread until the value becomes available.
Definition async_impl.hpp:42
Scheduler interface for initial AsyncTask submission and host-side progress.
Definition scheduler.hpp:89
auto await_transform(A &a)
Transform an awaiter to transfer one task ownership claim.
Definition async_impl.hpp:74
void async_initialize(Async< T > &destination, U &&source)
Initialize a fresh independent async value from another async source.
Definition async_ops.hpp:300
void async_assign(WriteBuffer< T > destination, U &&source)
Assign an awaitable value into an existing independent-value timeline.
Definition async_ops.hpp:310
This represents the reverse-mode adjoint for functions of complex variables, assuming a real-valued s...
Definition async/async.hpp:26
ReadBuffer< T > read(Async< T > const &a)
Convenience helper that forwards to Async<T>::read().
Definition async/async.hpp:540
WriteBuffer< T > write(Async< T > &a)
Convenience helper that forwards to Async<T>::write().
Definition async/async.hpp:545
Forwarding awaiter that transfers one task ownership claim to an awaitable.
Definition async_task_promise.hpp:885
Forwarding awaiter that transfers shared task ownership through a TaskFactory.
Definition async_task_promise.hpp:953