FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
backend.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
11// includes, system
12#include <iostream>
13
14
15#ifdef FEAT_HAVE_CUDA
16#define CUDA_SKELETON_VOID(function_cuda, ...)\
17 function_cuda(__VA_ARGS__);\
18 return;
19#define CUDA_SKELETON_VOID_T1(t1, function_cuda, ...)\
20 function_cuda<t1>(__VA_ARGS__);\
21 return;
22#define CUDA_SKELETON_VOID_T2(t1, t2, function_cuda, ...)\
23 function_cuda<t1, t2>(__VA_ARGS__);\
24 return;
25#else
26#define CUDA_SKELETON_VOID(function_cuda, ...)\
27 [[fallthrough]];
28#define CUDA_SKELETON_VOID_T1(t1, function_cuda, ...)\
29 [[fallthrough]];
30#define CUDA_SKELETON_VOID_T2(t1, t2, function_cuda, ...)\
31 [[fallthrough]];
32#endif
33
34#ifdef FEAT_HAVE_MKL
35#define MKL_SKELETON_VOID(function_mkl, ...)\
36 function_mkl(__VA_ARGS__);\
37 return;
38#define MKL_SKELETON_VOID_T1(t1, function_mkl, ...)\
39 function_mkl<t1>(__VA_ARGS__);\
40 return;
41#define MKL_SKELETON_VOID_T2(t1, t2, function_mkl, ...)\
42 function_mkl<t1, t2 >(__VA_ARGS__);\
43 return;
44#else
45#define MKL_SKELETON_VOID(function_mkl, ...)\
46 [[fallthrough]];
47#define MKL_SKELETON_VOID_T1(t1, function_mkl, ...)\
48 [[fallthrough]];
49#define MKL_SKELETON_VOID_T2(t1, t2, function_mkl, ...)\
50 [[fallthrough]];
51#endif
52
53#define BACKEND_SKELETON_VOID(function_cuda, function_mkl, function_generic, ...)\
54 switch(Backend::get_preferred_backend())\
55 {\
56 case FEAT::PreferredBackend::cuda:\
57 CUDA_SKELETON_VOID(function_cuda, __VA_ARGS__)\
58 case FEAT::PreferredBackend::mkl:\
59 MKL_SKELETON_VOID(function_mkl, __VA_ARGS__)\
60 case FEAT::PreferredBackend::generic:\
61 default:\
62 function_generic(__VA_ARGS__);\
63 return;\
64 }
65
66#define BACKEND_SKELETON_VOID_T1(t1, function_cuda, function_mkl, function_generic, ...)\
67 switch(Backend::get_preferred_backend())\
68 {\
69 case FEAT::PreferredBackend::cuda:\
70 CUDA_SKELETON_VOID_T1(t1, function_cuda, __VA_ARGS__)\
71 case FEAT::PreferredBackend::mkl:\
72 MKL_SKELETON_VOID_T1(t1, function_mkl, __VA_ARGS__)\
73 case FEAT::PreferredBackend::generic:\
74 default:\
75 function_generic<t1>(__VA_ARGS__);\
76 return;\
77 }
78
79#define BACKEND_SKELETON_VOID_T2(t1, t2, function_cuda, function_mkl, function_generic, ...)\
80 switch(Backend::get_preferred_backend())\
81 {\
82 case FEAT::PreferredBackend::cuda:\
83 CUDA_SKELETON_VOID_T2(t1, t2, function_cuda, __VA_ARGS__)\
84 case FEAT::PreferredBackend::mkl:\
85 MKL_SKELETON_VOID_T2(t1, t2, function_mkl, __VA_ARGS__)\
86 case FEAT::PreferredBackend::generic:\
87 default:\
88 function_generic<t1, t2>(__VA_ARGS__);\
89 return;\
90 }
91
92#ifdef FEAT_HAVE_CUDA
93#define CUDA_SKELETON_RETURN(function_cuda, ...)\
94 return function_cuda(__VA_ARGS__);
95#else
96#define CUDA_SKELETON_RETURN(function_cuda, ...)\
97 [[fallthrough]];
98#endif
99
100#ifdef FEAT_HAVE_MKL_
101#define MKL_SKELETON_RETURN(function_mkl, ...)\
102 return function_mkl(__VA_ARGS__);
103#else
104#define MKL_SKELETON_RETURN(function_mkl, ...)\
105 [[fallthrough]];
106#endif
107
108#define BACKEND_SKELETON_RETURN(function_cuda, function_mkl, function_generic, ...)\
109 switch(Backend::get_preferred_backend())\
110 {\
111 case FEAT::PreferredBackend::cuda:\
112 CUDA_SKELETON_RETURN(function_cuda, __VA_ARGS__)\
113 case FEAT::PreferredBackend::mkl:\
114 MKL_SKELETON_RETURN(function_mkl, __VA_ARGS__)\
115 case FEAT::PreferredBackend::generic:\
116 default:\
117 return function_generic(__VA_ARGS__);\
118 }
119
120namespace FEAT
121{
124 {
125 generic = 0,
126 mkl,
127 cuda
128 };
129
136 {
137 private:
140
141 public:
143 static void set_preferred_backend(PreferredBackend preferred_backend);
144
146 static PreferredBackend get_preferred_backend();
147 }; // class Backend
148
149 std::ostream & operator<< (std::ostream & left, FEAT::PreferredBackend backend);
150} // namespace FEAT
FEAT Kernel base header.
Backend support class.
Definition: backend.hpp:136
static PreferredBackend _preferred_backend
the currently preferred backend
Definition: backend.hpp:139
FEAT namespace.
Definition: adjactor.hpp:12
PreferredBackend
The backend that shall be used in all compute heavy calculations.
Definition: backend.hpp:124