Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
backends/cpu/gemv.hpp
Go to the documentation of this file.
1#pragma once
2
15
16namespace uni20::linalg
17{
18namespace detail
19{
20template <class OutputMdspan, class MatrixMdspan, class InputMdspan>
23
24template <class OutputMdspan, class Scalar, class MatrixMdspan, class InputMdspan>
25consteval bool cpu_gemv_types_compatible()
26{
31}
32} // namespace detail
33
35template <uni20::MutableRankedMdspecLike<1> OutputMdspan, uni20::Scalar Scalar, uni20::RankedMdspecLike<2> MatrixMdspan,
36 uni20::RankedMdspecLike<1> InputMdspan>
37 requires detail::HostGemvMdspanAccess<OutputMdspan, MatrixMdspan, InputMdspan>
38consteval auto kernel_accepts_types(CpuReferenceBackend const&, gemv_op const&, OutputMdspan&, Scalar const&,
39 MatrixMdspan&, InputMdspan&, Scalar const&)
40{
41 if constexpr (detail::cpu_gemv_types_compatible<OutputMdspan, Scalar, MatrixMdspan, InputMdspan>())
42 return kernel_types_yes;
43 else
44 return kernel_types_no;
45}
46
48template <uni20::MutableRankedMdspecLike<1> OutputMdspan, uni20::Scalar Scalar, uni20::RankedMdspecLike<2> MatrixMdspan,
49 uni20::RankedMdspecLike<1> InputMdspan>
50 requires detail::HostGemvMdspanAccess<OutputMdspan, MatrixMdspan, InputMdspan>
51KernelAttempt try_kernel(CpuReferenceBackend, gemv_op const&, OutputMdspan& output, Scalar alpha, MatrixMdspan& matrix,
52 InputMdspan& input, Scalar beta)
53{
54 auto output_access = acquire_host_write_access_sync(output);
55 auto matrix_access = acquire_host_read_access_sync(matrix);
56 auto input_access = acquire_host_read_access_sync(input);
57 auto output_span = output_access.mdspan();
58 auto matrix_span = matrix_access.mdspan();
59 auto input_span = input_access.mdspan();
60 uni20::linalg::cpu::gemv(output_span, alpha, matrix_span, input_span, beta);
62}
63
64} // namespace uni20::linalg
RAII leases that resolve device descriptors and tensor views to mdspans.
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
Report whether resolved mdspans support reference CPU GEMV expressions.
Definition cpu/gemv.hpp:21
Accessor-respecting reference CPU GEMV for resolved mdspans.
Operation-tag backend dispatch over tensor-view operands.
void gemv(OutputMdspan &&output, Scalar alpha, MatrixMdspan &&matrix, InputMdspan &&input, Scalar beta)
Execute reference CPU GEMV on resolved mdspans.
Definition cpu/gemv.hpp:40
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::yes > kernel_types_yes
Report that a backend accepts every instance of the argument types.
Definition dispatch_error.hpp:40
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 value for the reference host CPU dense linalg oracle.
Definition backend_selector.hpp:55
Dense matrix-vector multiplication operation tag.
Definition operation_tags.hpp:90
Concepts for tensor-level objects that resolve mdspan kernel operands.