10#include <kernel/backend.hpp>
11#include <kernel/util/memory_arbiter.hpp>
15namespace FEAT::LAFEM::Arch
20 template <
typename DT_,
typename IT_>
21 static void exec_generic_impl(DT_ * r,
const DT_ alpha,
const DT_ *
const x,
const DT_ *
const y,
const DT_ *
const val,
22 const IT_ *
const col_idx,
const IT_ *
const row_ptr,
const Index rows,
const Index,
const Index,
const bool);
24 static void exec_mkl_impl(
float * r,
const float alpha,
const float *
const x,
const float *
const y,
const float *
const val,
const Index *
const col_idx,
const Index *
const row_ptr,
const Index rows,
const Index cols,
const Index,
const bool);
25 static void exec_mkl_impl(
double * r,
const double alpha,
const double *
const x,
const double *
const y,
const double *
const val,
const Index *
const col_idx,
const Index *
const row_ptr,
const Index rows,
const Index cols,
const Index,
const bool);
27 template <
typename DT_,
typename IT_>
28 static void exec_mkl_impl(DT_ *,
const DT_,
const DT_ *
const,
const DT_ *
const,
const DT_ *
const,
const IT_ *
const,
const IT_ *
const,
const Index,
const Index,
const Index,
const bool)
30 XABORTM(
"LAFEM::Arch::MatVecMultCSRDense::exec_mkl_impl: MKL backend not available!");
33 template <
typename DT_,
typename IT_>
34 static void exec_cuda_impl(
void* workspace, DT_ * r,
const DT_ alpha,
const DT_ *
const x,
const DT_ *
const y,
const DT_ *
const val,
const IT_ *
const col_idx,
const IT_ *
const row_ptr,
const Index rows,
const Index cols,
const Index nonzeros,
const bool transposed);
36 template <
typename DT_,
typename IT_>
37 static void exec_generic(
Memory::Arbiter& r,
const DT_ alpha,
const Memory::Arbiter& x,
const Memory::Arbiter& y,
const Memory::Arbiter& a,
const Memory::Arbiter& col_idx,
const Memory::Arbiter& row_ptr,
const Index rows,
const Index cols,
const Index nonzeros,
const bool transposed)
48 ci_view.
get_r(), rp_view.
get_r(), rows, cols, nonzeros, transposed);
52 exec_generic_impl(r_view.
get_w(), alpha, x_view.
get_r(), (DT_*)
nullptr, a_view.
get_r(),
53 ci_view.
get_r(), rp_view.
get_r(), rows, cols, nonzeros, transposed);
57 template <
typename DT_>
58 static void exec_mkl(
Memory::Arbiter& r,
const DT_ alpha,
const Memory::Arbiter& x,
const Memory::Arbiter& y,
const Memory::Arbiter& a,
const Memory::Arbiter& col_idx,
const Memory::Arbiter& row_ptr,
const Index rows,
const Index cols,
const Index nonzeros,
const bool transposed)
70 ci_view.
get_r(), rp_view.
get_r(), rows, cols, nonzeros, transposed);
74 exec_mkl_impl(r_view.
get_w(), alpha, x_view.
get_r(), (DT_*)
nullptr, a_view.
get_r(),
75 ci_view.
get_r(), rp_view.
get_r(), rows, cols, nonzeros, transposed);
79 template <
typename DT_,
typename IT_>
80 static void exec_cuda(
void* workspace,
Memory::Arbiter& r,
const DT_ alpha,
const Memory::Arbiter& x,
const Memory::Arbiter& y,
const Memory::Arbiter& a,
const Memory::Arbiter& col_idx,
const Memory::Arbiter& row_ptr,
const Index rows,
const Index cols,
const Index nonzeros,
const bool transposed)
91 ci_view.
get_r(), rp_view.
get_r(), rows, cols, nonzeros, transposed);
95 exec_cuda_impl(workspace, r_view.
get_w(), alpha, x_view.
get_r(), (DT_*)
nullptr, a_view.
get_r(),
96 ci_view.
get_r(), rp_view.
get_r(), rows, cols, nonzeros, transposed);
100 template <
typename DT_,
typename IT_>
101 static void exec([[maybe_unused]] std::array<std::shared_ptr<void>,
to_underlying(BackendIdx::num_backends)>& workspaces,
Memory::Arbiter& r,
const DT_ alpha,
const Memory::Arbiter& x,
const Memory::Arbiter& y,
const Memory::Arbiter& a,
const Memory::Arbiter& col_idx,
const Memory::Arbiter& row_ptr,
const Index rows,
const Index cols,
const Index nonzeros,
const bool transposed)
108 exec_generic<DT_, IT_>(r, alpha, x, y, a, col_idx, row_ptr, rows, cols, nonzeros, transposed);
113 if constexpr(
sizeof(IT_) ==
sizeof(
Index))
114 exec_mkl<DT_>(r, alpha, x, y, a, col_idx, row_ptr, rows, cols, nonzeros, transposed);
117 Backend::warn_missing(
"LAFEM::Arch::MatVecMultCSRDense::exec: MKL backend not available for IT_ != Index");
118 exec_generic<DT_, IT_>(r, alpha, x, y, a, col_idx, row_ptr, rows, cols, nonzeros, transposed);
121 XABORTM(
"LAFEM::Arch::MatVecMultCSRDense::exec: MKL backend not available!");
127 exec_cuda<DT_, IT_>(workspaces[
to_underlying(BackendIdx::cuda)].get(), r, alpha, x, y, a, col_idx, row_ptr, rows, cols, nonzeros, transposed);
129 XABORTM(
"LAFEM::Arch::MatVecMultCSRDense::exec: CUDA backend not available!");
134 XABORTM(
"LAFEM::Arch::MatVecMultCSRDense::exec: unknown backend!");
149 template <
typename DT_,
typename IT_>
155 extern template void MatVecMultCSRDense::exec_generic_impl(
float *,
const float,
const float *
const,
const float *
const,
const float *
const,
const std::uint64_t *
const,
const std::uint64_t *
const,
const Index,
const Index,
const Index,
const bool);
156 extern template void MatVecMultCSRDense::exec_generic_impl(
float *,
const float,
const float *
const,
const float *
const,
const float *
const,
const std::uint32_t *
const,
const std::uint32_t *
const,
const Index,
const Index,
const Index,
const bool);
157 extern template void MatVecMultCSRDense::exec_generic_impl(
double *,
const double,
const double *
const,
const double *
const,
const double *
const,
const std::uint64_t *
const,
const std::uint64_t *
const,
const Index,
const Index,
const Index,
const bool);
158 extern template void MatVecMultCSRDense::exec_generic_impl(
double *,
const double,
const double *
const,
const double *
const,
const double *
const,
const std::uint32_t *
const,
const std::uint32_t *
const,
const Index,
const Index,
const Index,
const bool);
164#define KERNEL_LAFEM_ARCH_MATVECMULT_CSR_DENSE_HPP 1
165#include <kernel/lafem/arch/matvecmult_csr_dense_generic.hpp>
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
static PreferredBackend get_preferred_backend()
get current preferred backend
static void warn_missing(const char *operation, PreferredBackend preferred_backend, PreferredBackend fallback_backend=PreferredBackend::generic)
issues a warning about unsupported backend usage
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
@ overlap
explicitly allow overlapping writes (see Overlapping Memory Views)
@ write
write-only access (see attention note above)
constexpr auto to_underlying(E e) noexcept
Cast enum to underlying type.
std::uint64_t Index
Index data type.
r[i] <- y[i] + alpha * sum_{j=0..n-1} A[i][j] * x[j]
static void init_workspace_cuda(std::shared_ptr< void > &workspace, const Memory::Arbiter &val, const Memory::Arbiter &col_idx, const Memory::Arbiter &row_ptr, const Index rows, const Index cols, const Index nonzeros, const bool transposed)
Sets up a persistent cuSPARSE SpMV workspace for this matrix.