FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matvecmult_csr_block.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
10#include <kernel/backend.hpp>
11#include <kernel/util/memory_arbiter.hpp>
12#include <kernel/util/tiny_algebra.hpp>
13
14namespace FEAT::LAFEM::Arch
15{
18 {
19 template <typename DT_, typename IT_, int block_size_>
20 static void exec_generic_impl(Tiny::Vector<DT_,block_size_> * r, const DT_ alpha, const Tiny::Vector<DT_,block_size_> * const x, const Tiny::Vector<DT_,block_size_> * const y, const DT_ * const val,
21 const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const Index cols, const Index nonzeros, const bool transposed);
22
23 template <typename DT_, typename IT_, int block_size_>
24 static void exec_cuda_impl(DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val,
25 const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const Index cols, const Index nonzeros, const bool transposed);
26
27 template <typename DT_, typename IT_, int block_size_>
28 static void exec_generic(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& x, const Memory::Arbiter& y, const Memory::Arbiter& a,
29 const Memory::Arbiter& col_idx, const Memory::Arbiter& row_ptr, const Index rows, const Index cols, const Index nonzeros, const bool transposed)
30 {
36 if(y)
37 {
39 exec_generic_impl<DT_, IT_, block_size_>(r_view.get_w(), alpha, x_view.get_r(), y_view.get_r(), a_view.get_r(),
40 ci_view.get_r(), rp_view.get_r(), rows, cols, nonzeros, transposed);
41 }
42 else
43 {
44 exec_generic_impl<DT_, IT_, block_size_>(r_view.get_w(), alpha, x_view.get_r(), (Tiny::Vector<DT_, block_size_>*)nullptr, a_view.get_r(),
45 ci_view.get_r(), rp_view.get_r(), rows, cols, nonzeros, transposed);
46 }
47 }
48
49 template <typename DT_, typename IT_, int block_size_>
50 static void exec_cuda(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& x, const Memory::Arbiter& y, const Memory::Arbiter& a,
51 const Memory::Arbiter& col_idx, const Memory::Arbiter& row_ptr, const Index rows, const Index cols, const Index nonzeros, const bool transposed)
52 {
58 if(y)
59 {
61 exec_cuda_impl<DT_, IT_, block_size_>(r_view.get_w(), alpha, x_view.get_r(), y_view.get_r(), a_view.get_r(),
62 ci_view.get_r(), rp_view.get_r(), rows, cols, nonzeros, transposed);
63 }
64 else
65 {
66 exec_cuda_impl<DT_, IT_, block_size_>(r_view.get_w(), alpha, x_view.get_r(), (DT_*)nullptr, a_view.get_r(),
67 ci_view.get_r(), rp_view.get_r(), rows, cols, nonzeros, transposed);
68 }
69 }
70
71 template <typename DT_, typename IT_, int block_size_>
72 static void exec(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& x, const Memory::Arbiter& y, const Memory::Arbiter& a,
73 const Memory::Arbiter& col_idx, const Memory::Arbiter& row_ptr, const Index rows, const Index cols, const Index nonzeros, const bool transposed)
74 {
75 XASSERT(r != x);
76
78 {
80 exec_generic<DT_, IT_, block_size_>(r, alpha, x, y, a, col_idx, row_ptr, rows, cols, nonzeros, transposed);
81 break;
82
84#ifdef FEAT_HAVE_MKL
85 Backend::warn_missing("LAFEM::Arch::MatVecMultCSRBlock::exec: MKL backend not available!");
86 exec_generic<DT_, IT_, block_size_>(r, alpha, x, y, a, col_idx, row_ptr, rows, cols, nonzeros, transposed);
87#else
88 XABORTM("LAFEM::Arch::MatVecMultCSRBlock::exec: MKL backend not available!");
89#endif
90 break;
91
93#ifdef FEAT_HAVE_CUDA
94 if constexpr(block_size_ < 4)
95 exec_cuda<DT_, IT_, block_size_>(r, alpha, x, y, a, col_idx, row_ptr, rows, cols, nonzeros, transposed);
96 else
97 XABORTM("LAFEM::Arch::MatVecMultCSRBlock::exec: CUDA backend not available for block_size_ > 3!");
98#else
99 XABORTM("LAFEM::Arch::MatVecMultCSRBlock::exec: CUDA backend not available!");
100#endif
101 break;
102
103 default:
104 XABORTM("LAFEM::Arch::MatVecMultCSRBlock::exec: unknown backend!");
105 break;
106 }
107 }
108 }; // struct MatVecMultCSRBlock
109
110#ifdef FEAT_EICKT
111 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint32_t, 1>(Tiny::Vector<float,1> *, const float, const Tiny::Vector<float,1> * const, const Tiny::Vector<float,1> * const, const float * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
112 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint64_t, 1>(Tiny::Vector<float,1> *, const float, const Tiny::Vector<float,1> * const, const Tiny::Vector<float,1> * const, const float * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
113 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint32_t, 2>(Tiny::Vector<float,2> *, const float, const Tiny::Vector<float,2> * const, const Tiny::Vector<float,2> * const, const float * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
114 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint64_t, 2>(Tiny::Vector<float,2> *, const float, const Tiny::Vector<float,2> * const, const Tiny::Vector<float,2> * const, const float * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
115 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint32_t, 3>(Tiny::Vector<float,3> *, const float, const Tiny::Vector<float,3> * const, const Tiny::Vector<float,3> * const, const float * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
116 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint64_t, 3>(Tiny::Vector<float,3> *, const float, const Tiny::Vector<float,3> * const, const Tiny::Vector<float,3> * const, const float * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
117 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint32_t, 4>(Tiny::Vector<float,4> *, const float, const Tiny::Vector<float,4> * const, const Tiny::Vector<float,4> * const, const float * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
118 extern template void MatVecMultCSRBlock::exec_generic_impl<float, std::uint64_t, 4>(Tiny::Vector<float,4> *, const float, const Tiny::Vector<float,4> * const, const Tiny::Vector<float,4> * const, const float * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
119 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint32_t, 1>(Tiny::Vector<double,1> *, const double, const Tiny::Vector<double,1> * const, const Tiny::Vector<double,1> * const, const double * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
120 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint64_t, 1>(Tiny::Vector<double,1> *, const double, const Tiny::Vector<double,1> * const, const Tiny::Vector<double,1> * const, const double * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
121 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint32_t, 2>(Tiny::Vector<double,2> *, const double, const Tiny::Vector<double,2> * const, const Tiny::Vector<double,2> * const, const double * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
122 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint64_t, 2>(Tiny::Vector<double,2> *, const double, const Tiny::Vector<double,2> * const, const Tiny::Vector<double,2> * const, const double * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
123 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint32_t, 3>(Tiny::Vector<double,3> *, const double, const Tiny::Vector<double,3> * const, const Tiny::Vector<double,3> * const, const double * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
124 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint64_t, 3>(Tiny::Vector<double,3> *, const double, const Tiny::Vector<double,3> * const, const Tiny::Vector<double,3> * const, const double * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
125 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint32_t, 4>(Tiny::Vector<double,4> *, const double, const Tiny::Vector<double,4> * const, const Tiny::Vector<double,4> * const, const double * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const bool);
126 extern template void MatVecMultCSRBlock::exec_generic_impl<double, std::uint64_t, 4>(Tiny::Vector<double,4> *, const double, const Tiny::Vector<double,4> * const, const Tiny::Vector<double,4> * const, const double * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const bool);
127#endif
128
129} // namespace FEAT::LAFEM::Arch
130
131#ifndef __CUDACC__
132#define KERNEL_LAFEM_ARCH_MATVECMULT_CSR_BLOCK_HPP 1
133#include <kernel/lafem/arch/matvecmult_csr_block_generic.hpp>
134#endif
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
FEAT Kernel base header.
static PreferredBackend get_preferred_backend()
get current preferred backend
Definition: backend.cpp:32
static void warn_missing(const char *operation, PreferredBackend preferred_backend, PreferredBackend fallback_backend=PreferredBackend::generic)
issues a warning about unsupported backend usage
Definition: backend.cpp:77
Memory arbiter class.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
Typed memory view class.
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.
Tiny Vector class template.
@ overlap
explicitly allow overlapping writes (see Overlapping Memory Views)
@ read
read-only access
@ write
write-only access (see attention note above)
std::uint64_t Index
Index data type.
r[i][k] <- y[i][k] + alpha * sum_{j=0..n-1} A[i][j] * x[j][k]