Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
async/matrix_exponential.hpp
Go to the documentation of this file.
1#pragma once
2
16
17#include <memory>
18#include <tuple>
19#include <type_traits>
20#include <utility>
21
22namespace uni20::linalg
23{
24namespace detail
25{
26template <class BackendSelector, uni20::AsyncTensorOutput OutputTensor, uni20::RankedTensorView<2> InputTensor,
27 class TimeAwaiter>
28async::AsyncTask co_matrix_exponential(BackendSelector const selector, async::WriteBuffer<OutputTensor> output,
29 async::ReadBuffer<InputTensor> input, TimeAwaiter time)
30{
31 auto output_awaiter = uni20::detail::mutable_async_tensor_awaiter(output);
32 auto awaited = co_await async::all(output_awaiter, input, time);
33 decltype(auto) output_value = uni20::detail::mutable_async_tensor_value<OutputTensor>(std::get<0>(awaited));
34 auto const& input_value = std::get<1>(awaited);
35 using time_type = std::remove_cvref_t<decltype(std::get<2>(awaited))>;
36 time_type const time_value = std::get<2>(awaited);
37
38 auto output_descriptor = uni20::mdspec_of(output_value);
39 auto input_descriptor = uni20::mdspec_of(input_value);
40 co_await co_dispatch_kernel(selector, matrix_exponential_op{}, output_descriptor, input_descriptor, time_value);
41 co_return;
42}
43
44template <class BackendSelector, uni20::AsyncTensorOutput OutputTensor, uni20::RankedTensorView<2> InputTensor,
45 class TimeAwaiter>
46void schedule_async_matrix_exponential(BackendSelector selector, async::Async<OutputTensor>& output,
47 async::Async<InputTensor> const& input, TimeAwaiter time)
48{
49 ERROR_IF(std::addressof(output.queue()) == std::addressof(input.queue()),
50 "async matrix exponential output must not share an epoch queue with its input");
51 auto task = co_matrix_exponential(std::move(selector), output.write(), input.read(), std::move(time));
52 task.debug_name("matrix_exponential");
53 async::schedule(std::move(task));
54}
55} // namespace detail
56
60template <KernelBackendSelector BackendSelector, uni20::AsyncTensorOutput OutputTensor,
61 uni20::RankedTensorView<2> InputTensor, class TimeScalar>
63 requires(TimeScalar&& time) { async::read(std::forward<TimeScalar>(time)); }
64void matrix_exponential(BackendSelector selector, async::Async<OutputTensor>& output,
65 async::Async<InputTensor> const& input, TimeScalar&& time)
66{
67 detail::schedule_async_matrix_exponential(std::move(selector), output, input,
68 async::read(std::forward<TimeScalar>(time)));
69}
70
72template <uni20::AsyncTensorOutput OutputTensor, uni20::RankedTensorView<2> InputTensor, class TimeScalar>
74 requires(TimeScalar&& time) { async::read(std::forward<TimeScalar>(time)); }
75void matrix_exponential(async::Async<OutputTensor>& output, async::Async<InputTensor> const& input, TimeScalar&& time)
76{
77 auto selector = select_backend_for<OutputTensor, InputTensor>(matrix_exponential_op{});
78 matrix_exponential(std::move(selector), output, input, std::forward<TimeScalar>(time));
79}
80
81} // namespace uni20::linalg
The Async<T> container: coroutine‐safe asynchronous read/write.
Coroutine-aware kernel dispatch with an ordinary blocking fallback.
Utilities for awaiting on Async<T>: co_await overload, all(), try_await().
Canonical host-oriented coroutine task type.
Definition async_task.hpp:196
Async<T> is a container for coroutine-safe asynchronous read/write.
Definition async/async.hpp:93
ReadBuffer< T > read() const
Begin an asynchronous read of the value.
Definition async/async.hpp:339
EpochQueue const & queue() const
Inspect the shared epoch queue.
Definition async/async.hpp:423
WriteBuffer< T > write()
Begin exclusive asynchronous access to the payload.
Definition async/async.hpp:346
RAII handle for reading the value from an Async container at a given epoch.
Definition buffers.hpp:53
Exclusive mutable-access buffer for one Async<T> epoch.
Definition buffers.hpp:859
Mutable Tensor output supported by async operation wrappers.
Definition linalg/async/concepts.hpp:25
MutableTensorView with a specified static rank.
Definition tensor/concepts.hpp:166
TensorView whose readable mdspec has a specified static rank.
Definition tensor/concepts.hpp:149
Coroutine scheduler for AsyncTask.
Shared output capabilities for Async Tensor operation wrappers.
void schedule(AsyncTask &&task)
Schedule a task on the currently configured global scheduler.
Definition debug_scheduler.hpp:237
auto all(Aw &&... aw) noexcept
Build an awaitable that waits for all of the provided awaitables.
Definition awaiters.hpp:200
ReadBuffer< T > read(Async< T > const &a)
Convenience helper that forwards to Async<T>::read().
Definition async/async.hpp:540
Definition linalg/async.hpp:28
async::AsyncTask co_dispatch_kernel(BackendSelector selector, Op op, Args &... args)
Dispatch a kernel from a coroutine without requiring coroutine wrappers for blocking backends.
Definition async/dispatch.hpp:106
void matrix_exponential(BackendSelector selector, async::Async< OutputTensor > &output, async::Async< InputTensor > const &input, TimeScalar &&time)
Schedule fixed-output matrix exponentiation through an explicit selector.
Definition async/matrix_exponential.hpp:64
constexpr decltype(auto) mdspec_of(Tensor &tensor) noexcept(noexcept(tensor.mdspec()))
Return a tensor's immediate or descriptor-backed multidimensional metadata.
Definition tensor/concepts.hpp:50
Fixed-output dense matrix exponential operation.
Dense matrix exponential operation tag.
Definition operation_tags.hpp:202
#define ERROR_IF(cond,...)
Definition trace.hpp:389