Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
kernel/contract.hpp
Go to the documentation of this file.
1#pragma once
2
6
13
15{
16
17template <typename T, StridedMdspanLike AType, StridedMdspanLike BType, std::size_t N, typename U,
19 requires(AType::rank() + BType::rank() == CType::rank() + 2 * N) && DefaultAccessorMdspanLike<AType> &&
35void contract(T const& alpha, AType A, BType B, std::array<std::pair<std::size_t, std::size_t>, N> const& contractDims,
36 U const& beta, CType C)
37{
38 auto [Mgroup, Ngroup, Kgroup] = extract_strides(A, B, contractDims, C);
39 contract_strided(Mgroup, Ngroup, Kgroup, alpha, A.data_handle(), B.data_handle(), beta, C.data_handle());
40}
41
42template <typename T, StridedMdspanLike AType, StridedMdspanLike BType, typename U, MutableStridedMdspanLike CType,
43 std::size_t N>
59void contract(T const& alpha, AType A, BType B,
60 std::pair<std::size_t, std::size_t> const (&dims)[N], // array reference, size known at compile time
61 U const& beta, CType C)
62{
63 contract(alpha, A, B, std::to_array(dims), beta, C);
64}
65
66} // namespace uni20::kernel
An mdspan-like type whose accessor is stdex::default_accessor.
Definition mdspan/concepts.hpp:501
Mutable mdspan-like types whose layout reports they are always strided.
Definition mdspan/concepts.hpp:421
An mdspan-like type whose mapping is always strided and exposes stride observers.
Definition mdspan/concepts.hpp:406
void contract_strided(static_vector< extent_strides< 2 >, MR > const &Mgrp, static_vector< extent_strides< 2 >, NR > const &Ngrp, static_vector< extent_strides< 2 >, KR > const &Kgrp, T alpha, T const *A, T const *B, T beta, T *C)
Execute the CPU tensor contraction using precomputed stride groupings.
Definition kernel/cpu/contract.hpp:147
auto extract_strides(AType const &A, BType const &B, std::array< std::pair< std::size_t, std::size_t >, N > const &contractDims, CType const &C)
Extract merged stride groups for a tensor contraction.
Definition strides.hpp:287
Configured gateway to Uni20's mdspan implementation.
Definition kernel/contract.hpp:15
void contract(T const &alpha, AType A, BType B, std::array< std::pair< std::size_t, std::size_t >, N > const &contractDims, U const &beta, CType C)
Definition kernel/contract.hpp:35
mpreal beta(mpreal const &a, mpreal const &x)
Real Beta function; positive rational/integer pairs retain exact values.
Definition mpreal_special.hpp:164
Stride utilities for mdspan-like tensors.