8#ifndef KERNEL_LAFEM_ARCH_MATVECMULT_BANDED_DENSE_HPP
9#error "Do not include this implementation-only header file directly!"
12#include <kernel/util/math.hpp>
14namespace FEAT::LAFEM::Arch
18 template <Index Start, Index End, Index Step = 1>
21 template <
typename ... Params>
22 static FORCE_INLINE
void step(
void f(
Index, Params ...), Params... parameters)
24 f(Start, parameters ...);
29 template <Index Start, Index Step>
32 template <
typename ... Params>
33 static FORCE_INLINE
void step(
void (
Index, Params ...), Params ...)
40 template <
typename IT_>
41 inline Index start_offset(
const Index i,
const IT_ *
const offsets,
58 template <
typename IT_>
59 inline Index end_offset(
const Index i,
const IT_ *
const offsets,
76 template <
typename DT_,
typename IT_>
77 FORCE_INLINE
void single_matrix_entry(
Index k, DT_ *
const res,
const DT_ *
const val,
78 const IT_ *
const offsets,
const DT_ *
const x,
Index rows)
80 *res += val[k * rows] * x[offsets[k]];
83 template <
typename DT_,
typename IT_, Index noo, Index i, Index j>
86 void f(DT_ *
const r,
const DT_ alpha,
87 const DT_ *
const val,
const IT_ *
const offsets,
88 const DT_ *
const x,
const Index rows,
const Index cols)
90 Index start(
Math::max(Intern::ApplyBanded::start_offset(j-1, offsets, rows, cols, noo),
91 Intern::ApplyBanded::end_offset(i-1, offsets, rows, cols, noo) + 1));
92 Index end (
Math::min(Intern::ApplyBanded::start_offset(j-2, offsets, rows, cols, noo),
93 Intern::ApplyBanded::end_offset(i-2, offsets, rows, cols, noo) + 1));
96 for (
Index l = start; l < end; ++l)
100 offsets + (j-1), x + l + 1 - rows, rows);
104 Iteration_Left<DT_, IT_, noo, i, j-1>::f(r, alpha, val, offsets, x, rows, cols);
108 template <
typename DT_,
typename IT_, Index noo, Index i>
111 void f(DT_ *
const ,
const DT_ ,
112 const DT_ *
const ,
const IT_ *
const ,
113 const DT_ *
const ,
const Index ,
const Index )
120 template <
typename DT_,
typename IT_, Index noo, Index i>
123 void f(DT_ *
const r,
const DT_ alpha,
124 const DT_ *
const val,
const IT_ *
const offsets,
125 const DT_ *
const x,
const Index rows,
const Index cols)
127 Iteration_Left<DT_, IT_, noo, i, i-1>::f(r, alpha, val, offsets, x, rows, cols);
132 template <
typename DT_,
typename IT_, Index noo>
135 void f(DT_ *
const ,
const DT_ ,
136 const DT_ *
const ,
const IT_ *
const ,
137 const DT_ *
const ,
const Index ,
const Index )
144 template <
typename DT_,
typename IT_>
145 void apply_banded_generic(DT_ * r,
const DT_ alpha,
const DT_ *
const x,
146 const DT_ *
const val,
const IT_ *
const offsets,
151 while (k < bands && offsets[k] + 1 < rows)
157 for (
Index i(k + 1); i > 0;)
162 for (
Index j(bands + 1); j > 0;)
167 const Index start(
Math::max(Intern::ApplyBanded::start_offset( i, offsets, rows, cols, bands),
168 Intern::ApplyBanded::end_offset ( j, offsets, rows, cols, bands) + 1));
169 const Index stop (
Math::min(Intern::ApplyBanded::start_offset(i-1, offsets, rows, cols, bands),
170 Intern::ApplyBanded::end_offset (j-1, offsets, rows, cols, bands) + 1));
171 for (
Index l(start); l < stop; ++l)
174 for (
Index a(i); a < j; ++a)
176 s += val[a * rows + l] * x[l + offsets[a] + 1 - rows];
186 template <
typename DT_,
typename IT_>
187 void MatVecMultBandedDense::exec_generic_impl(DT_ * r,
const DT_ alpha,
const DT_ *
const x,
const DT_ *
const y,
188 const DT_ *
const val,
const IT_ *
const offsets,
const Index bands,
const Index rows,
const Index cols)
195#ifdef FEAT_UNROLL_BANDED
199 Intern::ApplyBanded::Iteration_Right<DT_, IT_, 3, 4>::f(r, alpha, val, offsets, x, rows, cols);
202 Intern::ApplyBanded::Iteration_Right<DT_, IT_, 5, 6>::f(r, alpha, val, offsets, x, rows, cols);
205 Intern::ApplyBanded::Iteration_Right<DT_, IT_, 9, 10>::f(r, alpha, val, offsets, x, rows, cols);
208 Intern::ApplyBanded::Iteration_Right<DT_, IT_, 25, 26>::f(r, alpha, val, offsets, x, rows, cols);
213 std::cout <<
"Warning: Apply not optimized for " << bands <<
" offsets!\n";
215 Intern::ApplyBanded::apply_banded_generic(r, alpha, x, val, offsets, bands, rows, cols);
218 Intern::ApplyBanded::apply_banded_generic(r, alpha, x, val, offsets, bands, rows, cols);
T_ min(T_ a, T_ b)
Returns the minimum of two values.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
void memcopy_main(void *dst, const void *src, std::size_t bytes)
Copies a region of a main memory block into another main memory block.
void memset_main(void *ptr, int value, std::size_t bytes)
Formats all bytes of a memory block in main memory to a given value.
std::uint64_t Index
Index data type.