FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matvecmult_dense_dense.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
13namespace FEAT::LAFEM::Arch
14{
17 {
18 template <typename DT_>
19 static void exec_generic_impl(DT_ * r, const DT_ alpha, const DT_ * const y, const DT_ * const val, const DT_ * const x, const Index rows, const Index cols, bool transpose);
20
21 static void exec_mkl_impl(float * r, const float alpha, const float * const y, const float * const val, const float * const x, const Index rows, const Index cols, bool transpose);
22 static void exec_mkl_impl(double * r, const double alpha, const double * const y, const double * const val, const double * const x, const Index rows, const Index cols, bool transpose);
23
24 template <typename DT_>
25 static void exec_mkl_impl(DT_ *, const DT_, const DT_ * const, const DT_ * const, const DT_ * const, const Index, const Index, bool)
26 {
27 XABORTM("LAFEM::Arch::MatVecMultDenseDense::exec_mkl_impl: MKL backend not available!");
28 }
29
30 template <typename DT_>
31 static void exec_cuda_impl(DT_ * r, const DT_ alpha, const DT_ * const y, const DT_ * const val, const DT_ * const x, const Index rows, const Index cols, bool transpose);
32
33 template <typename DT_>
34 static void exec_generic(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& y, const Memory::Arbiter& val, const Memory::Arbiter& x, const Index rows, const Index cols, bool transposed)
35 {
39 if(y)
40 {
42 exec_generic_impl(r_view.get_w(), alpha, y_view.get_r(), a_view.get_r(), x_view.get_r(), rows, cols, transposed);
43 }
44 else
45 {
46 exec_generic_impl(r_view.get_w(), alpha, (DT_*)nullptr, a_view.get_r(), x_view.get_r(), rows, cols, transposed);
47 }
48 }
49
50 template <typename DT_>
51 static void exec_mkl(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& y, const Memory::Arbiter& val, const Memory::Arbiter& x, const Index rows, const Index cols, bool transposed)
52 {
56 if(y)
57 {
59 exec_mkl_impl(r_view.get_w(), alpha, y_view.get_r(), a_view.get_r(), x_view.get_r(), rows, cols, transposed);
60 }
61 else
62 {
63 exec_mkl_impl(r_view.get_w(), alpha, (DT_*)nullptr, a_view.get_r(), x_view.get_r(), rows, cols, transposed);
64 }
65 }
66
67 template <typename DT_>
68 static void exec_cuda(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& y, const Memory::Arbiter& val, const Memory::Arbiter& x, const Index rows, const Index cols, bool transposed)
69 {
73 if(y)
74 {
76 exec_cuda_impl(r_view.get_w(), alpha, y_view.get_r(), a_view.get_r(), x_view.get_r(), rows, cols, transposed);
77 }
78 else
79 {
80 exec_cuda_impl(r_view.get_w(), alpha, (DT_*)nullptr, a_view.get_r(), x_view.get_r(), rows, cols, transposed);
81 }
82 }
83
84 template <typename DT_>
85 static void exec(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& y, const Memory::Arbiter& val, const Memory::Arbiter& x, const Index rows, const Index cols, bool transposed)
86 {
87 XASSERT(r != x);
88
90 {
92 exec_generic(r, alpha, y, val, x, rows, cols, transposed);
93 break;
94
96#ifdef FEAT_HAVE_MKL
97 exec_mkl(r, alpha, y, val, x, rows, cols, transposed);
98#else
99 XABORTM("LAFEM::Arch::MatVecMultDenseDense::exec: MKL backend not available!");
100#endif
101 break;
102
104#ifdef FEAT_HAVE_CUDA
105 exec_cuda(r, alpha, y, val, x, rows, cols, transposed);
106#else
107 XABORTM("LAFEM::Arch::MatVecMultDenseDense::exec: CUDA backend not available!");
108#endif
109 break;
110
111 default:
112 XABORTM("LAFEM::Arch::MatVecMultDenseDense::exec: unknown backend!");
113 break;
114 }
115 }
116 }; // struct MatVecMultDenseDense
117
118#ifdef FEAT_EICKT
119 extern template void MatVecMultDenseDense::exec_generic_impl(float *, const float, const float * const, const float * const, const float * const, const Index, const Index, bool);
120 extern template void MatVecMultDenseDense::exec_generic_impl(double *, const double, const double * const, const double * const, const double * const, const Index, const Index, bool);
121#endif
122
123} // namespace FEAT::LAFEM::Arch
124
125#ifndef __CUDACC__
126#define KERNEL_LAFEM_ARCH_MATVECMULT_DENSE_DENSE_HPP 1
127#include <kernel/lafem/arch/matvecmult_dense_dense_generic.hpp>
128#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
Memory arbiter class.
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.
@ 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] <- y[i] + alpha * sum_{j=0..n-1} A[i][j] * x[j]