Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
lu_mpfr.hpp
Go to the documentation of this file.
1#pragma once
2
9
10namespace uni20::linalg
11{
13template <MutableRankedMdspecLike<2> A>
14 requires HostWritableMdspec<A> && mpfr_detail::RuntimeScalar<typename A::value_type>
15consteval auto kernel_accepts_types(LapackBackend, lu_factor_op const&, A&, std::span<std::size_t>, LuNorms<mpreal>*,
17{
18 return kernel_types_yes;
19}
20
22template <MutableRankedMdspecLike<2> A>
23 requires HostWritableMdspec<A> && mpfr_detail::RuntimeScalar<typename A::value_type>
24KernelAttempt try_kernel(LapackBackend, lu_factor_op const&, A& a, std::span<std::size_t> pivots,
25 LuNorms<mpreal>* norms, SolveInfo& info, SolveOptions<mpreal> const& options, Precision p)
26{
27 (void)p.bit_count();
28 detail::require_lu_shape(a, pivots.size());
29 detail::require_solve_options(options);
30 auto access = acquire_host_write_access_sync(a);
31 auto s = access.mdspan();
32 info = {};
33 if (!detail::solve_matrix_is_finite(s))
34 {
35 info.status = SolveStatus::nonfinite_input;
37 }
38 auto work = mpfr_detail::pack(s, p);
39 if (!detail::solve_matrix_is_finite(work.mdspan()))
40 {
43 }
44 detail::capture_lu_norms(work.mdspan(), norms, mpreal(0, p));
45 auto scale = detail::lu_input_scale(work.mdspan(), mpreal(0, p));
46 auto tolerance = options.relative_pivot_tolerance.at(p);
47 std::vector<std::size_t> provider_pivots;
48 auto singular = mplapack::getrf(pivots.size(), mpfr_detail::values(work), provider_pivots, p);
49 mpfr_detail::unpack(work, s);
50 std::copy(provider_pivots.begin(), provider_pivots.end(), pivots.begin());
51 if (!detail::solve_matrix_is_finite(work.mdspan()))
53 else if (singular)
54 info = {.status = SolveStatus::singular, .pivot = singular - 1};
55 else
56 detail::check_lu_diagonal(work.mdspan(), scale, tolerance, info);
58}
59
61template <RankedMdspecLike<2> A, MutableRankedMdspecLike<2> B>
62 requires HostReadableMdspec<A> && HostWritableMdspec<B> && mpfr_detail::RuntimeScalar<typename A::value_type> &&
63 std::same_as<typename A::value_type, typename B::value_type>
64consteval auto kernel_accepts_types(LapackBackend, lu_solve_op const&, A&, std::span<std::size_t const>, B&, SolveInfo&,
66{
67 return kernel_types_yes;
68}
69
72template <RankedMdspecLike<2> A, MutableRankedMdspecLike<2> B>
73 requires HostReadableMdspec<A> && HostWritableMdspec<B> && mpfr_detail::RuntimeScalar<typename A::value_type> &&
74 std::same_as<typename A::value_type, typename B::value_type>
75KernelAttempt try_kernel(LapackBackend, lu_solve_op const&, A& a, std::span<std::size_t const> pivots, B& b,
76 SolveInfo& info, Precision p)
77{
78 (void)p.bit_count();
79 detail::require_lu_solve_shape(a, pivots, b);
80 info = {};
81 if (a.extent(0) == 0 || b.extent(1) == 0) return KernelAttempt::success;
84 auto as = aa.mdspan();
85 auto bs = ba.mdspan();
86 if (!detail::solve_matrix_is_finite(bs))
87 {
88 info.status = SolveStatus::nonfinite_input;
90 }
91 auto av = mpfr_detail::pack(as, p);
92 auto bv = mpfr_detail::pack(bs, p);
93 if (!detail::solve_matrix_is_finite(bv.mdspan()))
94 {
97 }
98 mplapack::getrs(pivots.size(), b.extent(1), mpfr_detail::values(std::as_const(av)), pivots, mpfr_detail::values(bv),
99 p);
100 mpfr_detail::unpack(bv, bs);
101 if (!detail::solve_matrix_is_finite(bv.mdspan())) info.status = SolveStatus::nonfinite_result;
103}
104} // namespace uni20::linalg
RAII leases that resolve device descriptors and tensor views to mdspans.
Synchronous packed-array boundary to the serial MPFR/MPC provider.
Exact arithmetic or an explicit binary working precision.
Definition core/precision.hpp:13
Owning exact rational or finite-precision MPFR real, with eager arithmetic.
Definition mpreal.hpp:74
Mdspec metadata supporting host read acquisition.
Definition access.hpp:688
Mutable mdspec metadata supporting host write acquisition.
Definition access.hpp:694
Operation-tag backend dispatch over tensor-view operands.
Definition linalg/async.hpp:28
KernelAttempt try_kernel(BlasBackend, gemm_op const &, C &c, S const &alpha, A &a, B &b, S const &beta)
Pack logical host values and execute GEMM through value-preserving provider conversion.
Definition linalg/backends/blas/binary80.hpp:30
KernelAttempt
Result of one runtime kernel backend attempt.
Definition kernel_attempt.hpp:27
@ nonfinite_input
An input coefficient or RHS component was nonfinite; both workspaces are preserved.
@ singular
An exactly zero elimination pivot was found.
@ nonfinite_result
A factor, solution, reduction, or required magnitude became nonfinite.
consteval auto kernel_accepts_types(BlasBackend, gemm_op const &, C &, S const &, A &, B &, S const &)
Accept host-readable native binary80 operands, including transforming accessors.
Definition linalg/backends/blas/binary80.hpp:19
constexpr KernelAcceptance< KernelTypeAcceptance::yes > kernel_types_yes
Report that a backend accepts every instance of the argument types.
Definition dispatch_error.hpp:40
std::size_t getrf(std::size_t n, std::span< float80 > a, std::vector< std::size_t > &pivots)
Factor a square binary80 matrix, returning zero or a one-based singular pivot.
Definition binary80.cpp:203
void getrs(std::size_t n, std::size_t nrhs, std::span< float80 const > a, std::span< std::size_t const > pivots, std::span< float80 > b)
Solve from read-only binary80 LU factors and zero-based pivots.
Definition binary80.cpp:213
Definition data_table.cpp:8
auto acquire_host_read_access_sync(Mdspan const &mdspan)
Acquire a directly host-accessible read-only mdspan.
Definition access.hpp:616
auto acquire_host_write_access_sync(Mdspan &mdspan)
Acquire a directly host-accessible writable mdspan.
Definition access.hpp:626
Backend-independent operation values used with normalized kernel operands.
Backend family for configured dense LAPACK kernels, including MPLAPACK scalar adapters.
Definition backend_selector.hpp:20
Original matrix norms after conversion to factor precision.
Definition lu_info.hpp:20
Diagnostics written by a completed numerical attempt, independent of dispatch.
Definition solve_info.hpp:41
Real-scalar pivot policy for a square linear solve.
Definition solve_info.hpp:62
Real relative_pivot_tolerance
Reject nonzero pivots at or below this fraction of the original maximum entry magnitude.
Definition solve_info.hpp:64
Fixed-output packed LU factorization with zero-based row-swap pivots.
Definition operation_tags.hpp:165
Solve using read-only packed LU factors, overwriting an existing RHS.
Definition operation_tags.hpp:171
Multiply one element value by a retained scalar factor.
Definition elementwise_functions.hpp:68