Documentation 6b54b78464
Loading...
Searching...
No Matches
code_config.hpp
Go to the documentation of this file.
1/*!
2 * \file code_config.hpp
3 * \brief Header file for collecting common macros, definitions and type configurations.
4 * \author T. Albring, P. Gomes, J. Blühdorn
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27#pragma once
28
29#include <cstdint>
30#include <type_traits>
31#include <cmath>
32
33#if defined(_MSC_VER)
34#define PRAGMIZE(X) __pragma(X)
35#else
36#define PRAGMIZE(X) _Pragma(#X)
37#endif
38
39#if defined(_MSC_VER)
40#define FORCEINLINE __forceinline
41#elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
42#define FORCEINLINE inline __attribute__((always_inline))
43#else
44#define FORCEINLINE inline
45#endif
46
47#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
48#define NEVERINLINE inline __attribute__((noinline))
49#else
50#define NEVERINLINE inline
51#endif
52
53/*--- Marks a function callable from both host and device code, a no-op outside nvcc. ---*/
54#ifdef __CUDACC__
55#define SU2_CUDA_HOST_DEVICE __host__ __device__
56#else
57#define SU2_CUDA_HOST_DEVICE
58#endif
59
60#if defined(__INTEL_COMPILER)
61/*--- Disable warnings related to inline attributes. ---*/
62#pragma warning disable 2196
63#pragma warning disable 3415
64/*--- Disable warnings related to overloaded virtual. ---*/
65#pragma warning disable 654
66#pragma warning disable 1125
67#if defined(CODI_FORWARD_TYPE) || defined(CODI_REVERSE_TYPE)
68#pragma warning disable 1875
69#endif
70#endif
71
72/*--- Convenience SFINAE typedef to conditionally
73 * enable/disable function template overloads. ---*/
74template <bool condition>
75using su2enable_if = typename std::enable_if<condition, bool>::type;
76
77/*--- Compile-time type selection. ---*/
78template <bool B, class T, class F>
80 using type = T;
81};
82template <class T, class F>
83struct su2conditional<false, T, F> {
84 using type = F;
85};
86
87template <bool B, class T, class F>
89
90/*! \brief Static cast "In" to "Out", in debug builds a dynamic cast is used. */
91template <class Out, class In>
93 static_assert(std::is_pointer<In>::value, "This expects a pointer");
94#ifndef NDEBUG
95 return static_cast<Out>(ptr);
96#else
97 return dynamic_cast<Out>(ptr);
98#endif
99}
100
101/*--- Detect compilation with OpenMP. ---*/
102#if defined(_OPENMP)
103#define HAVE_OMP
104#endif
105
106/*--- Detect whether the CUDA kernels are part of this build. They work on su2mixedfloat
107 * and passivedouble, so reverse AD is fine: su2_gpu_capable_v is false for the active type
108 * and CSysMatrix<su2double> stays on the host. Forward AD is not, there su2mixedfloat is
109 * su2double (see below) and the active type would reach the kernels. The .cu sources are
110 * compiled with the CoDiPack defines like everything else, see codi_host_only.hpp. ---*/
111#if defined(HAVE_CUDA) && !defined(CODI_FORWARD_TYPE)
112#define SU2_ENABLE_CUDA_KERNELS
113#endif
114
115/*--- No full single precision for AD builds. ---*/
116#if (defined(CODI_REVERSE_TYPE) || defined(CODI_FORWARD_TYPE)) && defined(USE_SINGLE_PRECISION)
117#undef USE_SINGLE_PRECISION
118#endif
119
120/*--- Default integer types. Currently used for rank-local sparse patterns. ---*/
121using su2uint = uint32_t;
122using su2int = int32_t;
123
124/*--- This type can be used for (rare) compatibility cases or for
125 * computations that are intended to be (always) passive. ---*/
126#ifdef USE_SINGLE_PRECISION
127using passivedouble = float;
128#else
129using passivedouble = double;
130#endif
131
132/*--- std::min/max do not compile if the arguments have inconsistent types, which
133 * happens in single precision due to floating point literals (double by default).
134 * These overloads delegate to fmin/fmax which do not have that problem. ---*/
135#ifdef USE_SINGLE_PRECISION
136namespace std {
137FORCEINLINE float min(const float& a, const double& b) { return fmin(a, static_cast<float>(b)); }
138FORCEINLINE float min(const double& b, const float& a) { return fmin(a, static_cast<float>(b)); }
139FORCEINLINE float max(const float& a, const double& b) { return fmax(a, static_cast<float>(b)); }
140FORCEINLINE float max(const double& b, const float& a) { return fmax(a, static_cast<float>(b)); }
141} // namespace std
142#endif
143
144/*--- Depending on the datatype defined during the configuration,
145 * include the correct definition, and create the main typedef. ---*/
146
147#if defined(CODI_REVERSE_TYPE) // reverse mode AD
148#include "codi.hpp"
149#include "codi/tools/data/externalFunctionUserData.hpp"
150
151#if defined(HAVE_OMP)
152using su2double = codi::RealReverseIndexOpenMPGen<double, double>;
153#else
154#if defined(CODI_JACOBIAN_LINEAR_TAPE)
155using su2double = codi::RealReverse;
156#elif defined(CODI_JACOBIAN_REUSE_TAPE)
157using su2double = codi::RealReverseIndexGen<double, double, codi::ReuseIndexManager<int> >;
158#elif defined(CODI_JACOBIAN_MULTIUSE_TAPE)
159using su2double = codi::RealReverseIndex;
160#elif defined(CODI_PRIMAL_LINEAR_TAPE)
161using su2double = codi::RealReversePrimal;
162#elif defined(CODI_PRIMAL_REUSE_TAPE)
163using su2double = codi::RealReversePrimalIndexGen<double, double, codi::ReuseIndexManager<int> >;
164#elif defined(CODI_PRIMAL_MULTIUSE_TAPE)
165using su2double = codi::RealReversePrimalIndex;
166#elif defined(CODI_TAG_TAPE)
167using su2double = codi::RealReverseTag;
168#else
169#error "Please define a CoDiPack tape."
170#endif
171#endif
172
173#if defined(HAVE_OMP) || defined(CODI_JACOBIAN_REUSE_TAPE) || defined(CODI_JACOBIAN_MULTIUSE_TAPE) || \
174 defined(CODI_PRIMAL_REUSE_TAPE) || defined(CODI_PRIMAL_MULTIUSE_TAPE)
175#define CODI_INDEX_REUSE
176#endif
177#elif defined(CODI_FORWARD_TYPE) // forward mode AD
178#include "codi.hpp"
179using su2double = codi::RealForward;
180#else // primal / direct / no AD
182#endif
183
184/*--- Define a type for potentially lower precision operations. ---*/
185#ifndef CODI_FORWARD_TYPE
186#ifdef USE_MIXED_PRECISION
187using su2mixedfloat = float;
188#else
190#endif
191#else
192/*--- There is no lower precision for forward AD so undefine the macro to simplify
193 * the logic needed to deal with the multiple type configurations. ---*/
194#ifdef USE_MIXED_PRECISION
195#undef USE_MIXED_PRECISION
196#endif
198#endif
199
200/*--- Detect if OpDiLib has to be used. ---*/
201#if defined(HAVE_OMP) && defined(CODI_REVERSE_TYPE)
202#ifndef __INTEL_COMPILER
203#define HAVE_OPDI
204#else
205#warning Hybrid parallel reverse mode AD cannot be used with Intel compilers.
206#endif
207
208#if (_OPENMP >= 201811 && !defined(FORCE_OPDI_MACRO_BACKEND)) || defined(FORCE_OPDI_OMPT_BACKEND)
209#define HAVE_OMPT
210#endif
211#endif
212
213#ifdef __GNUC__
214#define SU2_IGNORE_WARNING(WARNING) \
215 PRAGMIZE(GCC diagnostic push) \
216 PRAGMIZE(GCC diagnostic ignored WARNING)
217#define SU2_RESTORE_WARNING PRAGMIZE(GCC diagnostic pop)
218#else
219#define SU2_IGNORE_WARNING(WARNING)
220#define SU2_RESTORE_WARNING
221#endif
uint32_t su2uint
Definition code_config.hpp:121
double passivedouble
Definition code_config.hpp:129
typename su2conditional< B, T, F >::type su2conditional_t
Definition code_config.hpp:88
#define FORCEINLINE
Definition code_config.hpp:44
Out su2staticcast_p(In ptr)
Static cast "In" to "Out", in debug builds a dynamic cast is used.
Definition code_config.hpp:92
passivedouble su2mixedfloat
Definition code_config.hpp:189
int32_t su2int
Definition code_config.hpp:122
passivedouble su2double
Definition code_config.hpp:181
typename std::enable_if< condition, bool >::type su2enable_if
Definition code_config.hpp:75
F type
Definition code_config.hpp:84
Definition code_config.hpp:79
T type
Definition code_config.hpp:80