Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
async/matrix_set.hpp
Go to the documentation of this file.
1#pragma once
2
16
17#include <tuple>
18#include <utility>
19
20namespace uni20::linalg
21{
22namespace detail
23{
24template <class BackendSelector, uni20::AsyncTensorOutput MatrixTensor, class DiagonalAwaiter, class OffDiagonalAwaiter>
25async::AsyncTask co_set_matrix(BackendSelector const selector, async::WriteBuffer<MatrixTensor> matrix,
26 DiagonalAwaiter diagonal, OffDiagonalAwaiter off_diagonal, MatrixRegion const region)
27{
28 auto matrix_awaiter = uni20::detail::mutable_async_tensor_awaiter(matrix);
29 auto awaited = co_await async::all(matrix_awaiter, diagonal, off_diagonal);
30 decltype(auto) matrix_value = uni20::detail::mutable_async_tensor_value<MatrixTensor>(std::get<0>(awaited));
31 using scalar_type = uni20::tensor_element_t<MatrixTensor>;
32 scalar_type const diagonal_value = static_cast<scalar_type>(std::get<1>(awaited));
33 scalar_type const off_diagonal_value = static_cast<scalar_type>(std::get<2>(awaited));
34
35 auto descriptor = uni20::mdspec_of(matrix_value);
36 co_await co_dispatch_kernel(selector, matrix_set_op{.region = region}, descriptor, diagonal_value,
37 off_diagonal_value);
38 co_return;
39}
40
41template <class BackendSelector, uni20::AsyncTensorOutput MatrixTensor, class DiagonalAwaiter, class OffDiagonalAwaiter>
42void schedule_async_set_matrix(BackendSelector selector, async::Async<MatrixTensor>& matrix, DiagonalAwaiter diagonal,
43 OffDiagonalAwaiter off_diagonal, MatrixRegion region)
44{
45 auto task = co_set_matrix(std::move(selector), matrix.write(), std::move(diagonal), std::move(off_diagonal), region);
46 task.debug_name("set_matrix");
47 async::schedule(std::move(task));
48}
49} // namespace detail
50
53template <KernelBackendSelector BackendSelector, uni20::AsyncTensorOutput MatrixTensor, class Diagonal,
54 class OffDiagonal>
56 AsyncOperationScalar<Diagonal, uni20::tensor_element_t<MatrixTensor>> &&
57 AsyncOperationScalar<OffDiagonal, uni20::tensor_element_t<MatrixTensor>>
58void set_matrix(BackendSelector selector, async::Async<MatrixTensor>& matrix, Diagonal&& diagonal,
59 OffDiagonal&& off_diagonal, MatrixRegion region = MatrixRegion::All)
60{
61 detail::schedule_async_set_matrix(std::move(selector), matrix, async::read(std::forward<Diagonal>(diagonal)),
62 async::read(std::forward<OffDiagonal>(off_diagonal)), region);
63}
64
66template <uni20::AsyncTensorOutput MatrixTensor, class Diagonal, class OffDiagonal>
68 AsyncOperationScalar<Diagonal, uni20::tensor_element_t<MatrixTensor>> &&
69 AsyncOperationScalar<OffDiagonal, uni20::tensor_element_t<MatrixTensor>>
70void set_matrix(async::Async<MatrixTensor>& matrix, Diagonal&& diagonal, OffDiagonal&& off_diagonal,
72{
73 auto selector = select_backend_for<MatrixTensor>(matrix_set_op{.region = region});
74 set_matrix(std::move(selector), matrix, std::forward<Diagonal>(diagonal), std::forward<OffDiagonal>(off_diagonal),
75 region);
76}
77
78} // 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
WriteBuffer< T > write()
Begin exclusive asynchronous access to the payload.
Definition async/async.hpp:346
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
Coroutine scheduler for AsyncTask.
Capabilities shared by asynchronous Tensor operation wrappers.
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 set_matrix(BackendSelector selector, async::Async< MatrixTensor > &matrix, Diagonal &&diagonal, OffDiagonal &&off_diagonal, MatrixRegion region=MatrixRegion::All)
Schedule structured matrix initialization through an explicit selector.
Definition async/matrix_set.hpp:58
MatrixRegion
Matrix region selected by structured initialization operations.
Definition operation_tags.hpp:208
@ All
All entries, including rectangular portions of the matrix.
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
std::remove_cv_t< typename tensor_mdspec_t< T >::element_type > tensor_element_t
Scalar value type exposed by a tensor-level object.
Definition tensor/concepts.hpp:126
Structured dense matrix initialization operation.
Structured dense matrix initialization operation tag.
Definition operation_tags.hpp:219
MatrixRegion region
Definition operation_tags.hpp:221