FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter_dense_csr.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
14namespace FEAT::LAFEM::Arch
15{
16 struct UnitFilterDenseCSR
17 {
18 template<typename DT_, typename IT_>
19 static void exec_generic_impl(DT_* mat, const IT_* const row_ptr, const IT_* const col_idx, const IT_ * const f_idx, const Index f_nzes, const bool unit, const int block_width);
20
21 template<typename DT_, typename IT_>
22 static void exec_generic(Memory::Arbiter& mat, const Memory::Arbiter& row_ptr, const Memory::Arbiter& col_idx, const Memory::Arbiter& f_idx, const Index f_nzes, const bool unit, const int block_width)
23 {
24 Memory::TypedView<DT_> a_view(mat.view(Memory::Location::main, Memory::Access::read_write));
25 Memory::TypedView<IT_> ci_view(col_idx.view(Memory::Location::main, Memory::Access::read));
26 Memory::TypedView<IT_> rp_view(row_ptr.view(Memory::Location::main, Memory::Access::read));
27 Memory::TypedView<IT_> fi_view(f_idx.view(Memory::Location::main, Memory::Access::read));
28 exec_generic_impl(a_view.get_w(), rp_view.get_r(), ci_view.get_r(), fi_view.get_r(), f_nzes, unit, block_width);
29 }
30
31 template<typename DT_, typename IT_>
32 static void exec_cuda_impl(DT_* mat, const IT_* const row_ptr, const IT_* const col_idx, const IT_ * const f_idx, const Index f_nzes, const bool unit, const int block_width);
33
34 template<typename DT_, typename IT_>
35 static void exec_cuda(Memory::Arbiter& mat, const Memory::Arbiter& row_ptr, const Memory::Arbiter& col_idx, const Memory::Arbiter& f_idx, const Index f_nzes, const bool unit, const int block_width)
36 {
37 Memory::TypedView<DT_> a_view(mat.view(Memory::Location::cuda, Memory::Access::read_write));
38 Memory::TypedView<IT_> ci_view(col_idx.view(Memory::Location::cuda, Memory::Access::read));
39 Memory::TypedView<IT_> rp_view(row_ptr.view(Memory::Location::cuda, Memory::Access::read));
40 Memory::TypedView<IT_> fi_view(f_idx.view(Memory::Location::cuda, Memory::Access::read));
41 exec_cuda_impl(a_view.get_w(), rp_view.get_r(), ci_view.get_r(), fi_view.get_r(), f_nzes, unit, block_width);
42 }
43
44 template<typename DT_, typename IT_>
45 static void exec(Memory::Arbiter& mat, const Memory::Arbiter& row_ptr, const Memory::Arbiter& col_idx, const Memory::Arbiter& f_idx, const Index f_nzes, const bool unit, const int block_width)
46 {
47 XASSERT(!unit || (block_width == 1));
48
49 switch(Backend::get_preferred_backend())
50 {
51 case PreferredBackend::generic:
52 exec_generic<DT_, IT_>(mat, row_ptr, col_idx, f_idx, f_nzes, unit, block_width);
53 break;
54
55 case PreferredBackend::mkl:
56#ifdef FEAT_HAVE_MKL
57 Backend::warn_missing("LAFEM::Arch::UnitFilterDenseCSR::exec");
58 exec_generic<DT_, IT_>(mat, row_ptr, col_idx, f_idx, f_nzes, unit, block_width);
59#else
60 XABORTM("LAFEM::Arch::UnitFilterDenseCSR::exec: MKL backend not available!");
61#endif
62 break;
63
64 case PreferredBackend::cuda:
65#ifdef FEAT_HAVE_CUDA
66 exec_cuda<DT_, IT_>(mat, row_ptr, col_idx, f_idx, f_nzes, unit, block_width);
67#else
68 XABORTM("LAFEM::Arch::UnitFilterDenseCSR::exec: CUDA backend not available!");
69#endif
70 break;
71
72 default:
73 XABORTM("LAFEM::Arch::UnitFilterDenseCSR::exec: unknown backend!");
74 break;
75 }
76 }
77 }; // struct UnitFilterDenseCSR
78
79#ifdef FEAT_EICKT
80 extern template void UnitFilterDenseCSR::exec_generic_impl(float* mat, const std::uint32_t* const row_ptr, const std::uint32_t* const col_idx, const std::uint32_t * const f_idx, const Index f_nzes, const bool unit, const int);
81 extern template void UnitFilterDenseCSR::exec_generic_impl(float* mat, const std::uint64_t* const row_ptr, const std::uint64_t* const col_idx, const std::uint64_t * const f_idx, const Index f_nzes, const bool unit, const int);
82 extern template void UnitFilterDenseCSR::exec_generic_impl(double* mat, const std::uint32_t* const row_ptr, const std::uint32_t* const col_idx, const std::uint32_t * const f_idx, const Index f_nzes, const bool unit, const int);
83 extern template void UnitFilterDenseCSR::exec_generic_impl(double* mat, const std::uint64_t* const row_ptr, const std::uint64_t* const col_idx, const std::uint64_t * const f_idx, const Index f_nzes, const bool unit, const int);
84#endif
85} // namespace FEAT::LAFEM::Arch
87
88#ifndef __CUDACC__
89#define KERNEL_LAFEM_ARCH_UNIT_FILTER_DENSE_CSR_HPP 1
90#include <kernel/lafem/arch/unit_filter_dense_csr_generic.hpp>
91#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.
std::uint64_t Index
Index data type.