FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matmatmult_sparse_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{
16 {
17 template <typename DT_, typename IT_>
18 static void exec_generic_impl(DT_ * r, const DT_ alpha, const DT_ * const val, const IT_ * const col_idx, const IT_ * const row_ptr, const Index nonzeros,
19 const DT_ * const y, const DT_* const z, const Index rows, const Index cols, const Index inner);
20
21 template <typename DT_, typename IT_>
22 static void exec_cuda_impl(DT_ * r, const DT_ alpha, const DT_ * const val, const IT_ * const col_idx, const IT_ * const row_ptr, const Index nonzeros,
23 const DT_ * const y, const DT_* const z, const Index rows, const Index cols, const Index inner);
24
25 template <typename DT_, typename IT_>
26 static void exec_generic(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& val, const Memory::Arbiter& col_idx, const Memory::Arbiter& row_ptr, const Index nonzeros,
27 const Memory::Arbiter& y, const Memory::Arbiter& z, const Index rows, const Index cols, const Index inner)
28 {
34 if(z)
35 {
37 exec_generic_impl(r_view.get_w(), alpha, a_view.get_r(), ci_view.get_r(), rp_view.get_r(),
38 nonzeros, y_view.get_r(), z_view.get_r(), rows, cols, inner);
39 }
40 else
41 {
42 exec_generic_impl(r_view.get_w(), alpha, a_view.get_r(), ci_view.get_r(), rp_view.get_r(),
43 nonzeros, y_view.get_r(), (DT_*)nullptr, rows, cols, inner);
44 }
45 }
46
47 template <typename DT_, typename IT_>
48 static void exec_cuda(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& val, const Memory::Arbiter& col_idx, const Memory::Arbiter& row_ptr, const Index nonzeros,
49 const Memory::Arbiter& y, const Memory::Arbiter& z, const Index rows, const Index cols, const Index inner)
50 {
56 if(z)
57 {
59 exec_cuda_impl(r_view.get_w(), alpha, a_view.get_r(), ci_view.get_r(), rp_view.get_r(),
60 nonzeros, y_view.get_r(), z_view.get_r(), rows, cols, inner);
61 }
62 else
63 {
64 exec_cuda_impl(r_view.get_w(), alpha, a_view.get_r(), ci_view.get_r(), rp_view.get_r(),
65 nonzeros, y_view.get_r(), (DT_*)nullptr, rows, cols, inner);
66 }
67 }
68
69 template <typename DT_, typename IT_>
70 static void exec(Memory::Arbiter& r, const DT_ alpha, const Memory::Arbiter& val, const Memory::Arbiter& col_idx, const Memory::Arbiter& row_ptr, const Index nonzeros,
71 const Memory::Arbiter& y, const Memory::Arbiter& z, const Index rows, const Index cols, const Index inner)
72 {
73 XASSERT(r != y);
74
76 {
78 exec_generic<DT_, IT_>(r, alpha, val, col_idx, row_ptr, nonzeros, y, z, rows, cols, inner);
79 break;
80
82#ifdef FEAT_HAVE_MKL
83 Backend::warn_missing("LAFEM::Arch::MatMatMultSparseDense::exec");
84 exec_generic<DT_, IT_>(r, alpha, val, col_idx, row_ptr, nonzeros, y, z, rows, cols, inner);
85#else
86 XABORTM("LAFEM::Arch::MatMatMultSparseDense::exec: MKL backend not available!");
87#endif
88 break;
89
91#ifdef FEAT_HAVE_CUDA
92 exec_cuda<DT_, IT_>(r, alpha, val, col_idx, row_ptr, nonzeros, y, z, rows, cols, inner);
93#else
94 XABORTM("LAFEM::Arch::MatMatMultSparseDense::exec: CUDA backend not available!");
95#endif
96 break;
97 }
98 }
99 }; // struct MatMatMultSparseDense
100
101#ifdef FEAT_EICKT
102 extern template void MatMatMultSparseDense::exec_generic_impl(float *, const float, const float * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const float * const, const float * const, const Index, const Index, const Index);
103 extern template void MatMatMultSparseDense::exec_generic_impl(double *, const double, const double * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const double *const , const double *const , const Index, const Index, const Index);
104
105 extern template void MatMatMultSparseDense::exec_generic_impl(float *, const float, const float * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const float * const, const float * const, const Index, const Index, const Index);
106 extern template void MatMatMultSparseDense::exec_generic_impl(double *, const double, const double * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const double * const, const double *const , const Index, const Index, const Index);
107#endif
108} // namespace FEAT::LAFEM::Arch
109
110#ifndef __CUDACC__
111#define KERNEL_LAFEM_ARCH_MATMATMULT_SPARSE_DENSE_HPP 1
112#include <kernel/lafem/arch/matmatmult_sparse_dense_generic.hpp>
113#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.
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.