Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
backends/blas/gemv.hpp
Go to the documentation of this file.
1#pragma once
2
14
15#include <concepts>
16
17namespace uni20::linalg
18{
19namespace detail::blas_backend
20{
21
22template <class OutputMdspan, class Scalar, class MatrixMdspan, class InputMdspan>
23consteval bool gemv_types_compatible()
24{
28 return requires(output_span& output, Scalar alpha, matrix_span& matrix, input_span& input) {
29 { uni20::linalg::blas::try_gemv(output, alpha, matrix, input, alpha) } -> std::same_as<KernelAttempt>;
30 };
31}
32} // namespace detail::blas_backend
33
35template <uni20::MutableRankedMdspecLike<1> OutputMdspan, class Scalar, uni20::RankedMdspecLike<2> MatrixMdspan,
36 uni20::RankedMdspecLike<1> InputMdspan>
39consteval auto kernel_accepts_types(BlasBackend const&, gemv_op const&, OutputMdspan&, Scalar const&, MatrixMdspan&,
40 InputMdspan&, Scalar const&)
41{
42 if constexpr (detail::blas_backend::gemv_types_compatible<OutputMdspan, Scalar, MatrixMdspan, InputMdspan>())
43 return kernel_types_maybe;
44 else
45 return kernel_types_no;
46}
47
49template <uni20::MutableRankedMdspecLike<1> OutputMdspan, class Scalar, uni20::RankedMdspecLike<2> MatrixMdspan,
50 uni20::RankedMdspecLike<1> InputMdspan>
53KernelAttempt try_kernel(BlasBackend, gemv_op const&, OutputMdspan& output, Scalar alpha, MatrixMdspan& matrix,
54 InputMdspan& input, Scalar beta)
55{
56 auto output_access = acquire_host_write_access_sync(output);
57 auto matrix_access = acquire_host_read_access_sync(matrix);
58 auto input_access = acquire_host_read_access_sync(input);
59 auto output_span = output_access.mdspan();
60 auto matrix_span = matrix_access.mdspan();
61 auto input_span = input_access.mdspan();
62 return uni20::linalg::blas::try_gemv(output_span, alpha, matrix_span, input_span, beta);
63}
64
65} // namespace uni20::linalg
RAII leases that resolve device descriptors and tensor views to mdspans.
Direct mdspan GEMV wrappers over the configured BLAS provider.
Mdspec metadata supporting host read acquisition.
Definition access.hpp:688
Mutable mdspec metadata supporting host write acquisition.
Definition access.hpp:694
Concept for numeric scalar types (integer, real, or complex).
Definition scalar_concepts.hpp:81
Operation-tag backend dispatch over tensor-view operands.
KernelAttempt try_gemv(OutputMdspan &&output, Scalar alpha, MatrixMdspan &&matrix, InputMdspan &&input, Scalar beta)
Try a direct no-copy BLAS GEMV from mdspan-like operands.
Definition blas/gemv.hpp:96
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
constexpr KernelAcceptance< KernelTypeAcceptance::no > kernel_types_no
Report that a backend rejects the argument types.
Definition dispatch_error.hpp:34
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::maybe > kernel_types_maybe
Report that runtime operand values determine backend acceptance.
Definition dispatch_error.hpp:37
std::remove_cvref_t< decltype(std::declval< detail::host_read_mdspan_lease_t< Mdspec > & >().mdspan())> host_read_mdspan_t
Read-only mdspan type resolved by host descriptor acquisition.
Definition access.hpp:679
auto acquire_host_read_access_sync(Mdspan const &mdspan)
Acquire a directly host-accessible read-only mdspan.
Definition access.hpp:616
std::remove_cvref_t< decltype(std::declval< detail::host_write_mdspan_lease_t< Mdspec > & >().mdspan())> host_write_mdspan_t
Writable mdspan type resolved by host descriptor acquisition.
Definition access.hpp:684
mpreal beta(mpreal const &a, mpreal const &x)
Real Beta function; positive rational/integer pairs retain exact values.
Definition mpreal_special.hpp:164
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 BLAS dense linalg kernels, including MPLAPACK scalar adapters.
Definition backend_selector.hpp:27
Dense matrix-vector multiplication operation tag.
Definition operation_tags.hpp:90
Concepts for tensor-level objects that resolve mdspan kernel operands.