FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter_block_vec.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 UnitFilterBlockVec
17 {
18 template <typename DT_, typename IT_>
19 static void exec_generic_impl(DT_ * v, const DT_ * const f_val, const IT_ * const f_idx, const Index f_nzes, const bool zero, const bool ign_nans, const int block_size);
20
21 template <typename DT_, typename IT_, int block_size_>
22 static void exec_generic(Memory::Arbiter& v, const Memory::Arbiter& f_val, const Memory::Arbiter& f_idx, const Index f_nzes, const bool zero, const bool ign_nans)
23 {
24 Memory::TypedView<DT_> v_view(v.view(Memory::Location::main, Memory::Access::read_write));
25 Memory::TypedView<IT_> i_view(f_idx.view(Memory::Location::main, Memory::Access::read));
26 if(!zero || ign_nans)
27 {
28 Memory::TypedView<DT_> f_view(f_val.view(Memory::Location::main, Memory::Access::read));
29 exec_generic_impl(v_view.get_w(), f_view.get_r(), i_view.get_r(), f_nzes, zero, ign_nans, block_size_);
30 }
31 else
32 {
33 // f_val view is not required in this case
34 exec_generic_impl(v_view.get_w(), (DT_*)nullptr, i_view.get_r(), f_nzes, zero, ign_nans, block_size_);
35 }
36 }
37
38 template <typename DT_, typename IT_>
39 static void exec_cuda_impl(DT_ * v, const DT_ * const f_val, const IT_ * const f_idx, const Index f_nzes, const bool zero, const bool ign_nans, const int block_size);
40
41 template <typename DT_, typename IT_, int block_size_>
42 static void exec_cuda(Memory::Arbiter& v, const Memory::Arbiter& f_val, const Memory::Arbiter& f_idx, const Index f_nzes, const bool zero, const bool ign_nans)
43 {
44 Memory::TypedView<DT_> v_view(v.view(Memory::Location::cuda, Memory::Access::read_write));
45 Memory::TypedView<IT_> i_view(f_idx.view(Memory::Location::cuda, Memory::Access::read));
46 if(!zero || ign_nans)
47 {
48 Memory::TypedView<DT_> f_view(f_val.view(Memory::Location::cuda, Memory::Access::read));
49 exec_cuda_impl(v_view.get_w(), f_view.get_r(), i_view.get_r(), f_nzes, zero, ign_nans, block_size_);
50 }
51 else
52 {
53 // f_val view is not required in this case
54 exec_cuda_impl(v_view.get_w(), (DT_*)nullptr, i_view.get_r(), f_nzes, zero, ign_nans, block_size_);
55 }
56 }
57
58 template <typename DT_, typename IT_, int block_size_>
59 static void exec(Memory::Arbiter& v, const Memory::Arbiter& f_val, const Memory::Arbiter& f_idx, const Index f_nzes, const bool zero, const bool ign_nans)
60 {
61 switch(Backend::get_preferred_backend())
62 {
63 case PreferredBackend::generic:
64 exec_generic<DT_, IT_, block_size_>(v, f_val, f_idx, f_nzes, zero, ign_nans);
65 break;
66
67 case PreferredBackend::mkl:
68#ifdef FEAT_HAVE_MKL
69 Backend::warn_missing("LAFEM::Arch::UnitFilterBlockVec::exec");
70 exec_generic<DT_, IT_, block_size_>(v, f_val, f_idx, f_nzes, zero, ign_nans);
71#else
72 XABORTM("LAFEM::Arch::UnitFilterBlockVec::exec: MKL backend not available!");
73#endif
74 break;
75
76 case PreferredBackend::cuda:
77#ifdef FEAT_HAVE_CUDA
78 exec_cuda<DT_, IT_, block_size_>(v, f_val, f_idx, f_nzes, zero, ign_nans);
79#else
80 XABORTM("LAFEM::Arch::UnitFilterBlockVec::exec: CUDA backend not available!");
81#endif
82 break;
83
84 default:
85 XABORTM("LAFEM::Arch::UnitFilterBlockVec::exec: unknown backend!");
86 break;
87 }
88 }
89 }; // struct UnitFilterBlockVec
90
91#ifdef FEAT_EICKT
92 extern template void UnitFilterBlockVec::exec_generic_impl(float *, const float * const, const std::uint64_t * const, const Index, const bool, const bool, const int);
93 extern template void UnitFilterBlockVec::exec_generic_impl(double *, const double * const, const std::uint64_t * const, const Index, const bool, const bool, const int);
94 extern template void UnitFilterBlockVec::exec_generic_impl(float *, const float * const, const std::uint32_t * const, const Index, const bool, const bool, const int);
95 extern template void UnitFilterBlockVec::exec_generic_impl(double *, const double * const, const std::uint32_t * const, const Index, const bool, const bool, const int);
96#endif
97} // namespace FEAT::LAFEM::Arch
99
100#ifndef __CUDACC__
101#define KERNEL_LAFEM_ARCH_UNIT_FILTER_BLOCK_VEC_HPP 1
102#include <kernel/lafem/arch/unit_filter_block_vec_generic.hpp>
103#endif
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
FEAT Kernel base header.
std::uint64_t Index
Index data type.