GEOS
GeosxMacros.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
22 #include "common/GeosxConfig.hpp"
23 #include "LvArray/src/Macros.hpp"
24 
25 #ifndef GEOS_COMMON_GEOSXMACROS_HPP_
26 #define GEOS_COMMON_GEOSXMACROS_HPP_
27 
36 
37 #if defined(GEOS_USE_DEVICE)
38 #define GEOS_HOST __host__
39 #define GEOS_DEVICE __device__
40 #define GEOS_HOST_DEVICE __host__ __device__
41 #define GEOS_FORCE_INLINE __forceinline__
42 #define PRAGMA_UNROLL _Pragma("unroll")
43 #else
45 #define GEOS_HOST
47 #define GEOS_DEVICE
49 #define GEOS_HOST_DEVICE
51 #define GEOS_FORCE_INLINE inline
53 #define PRAGMA_UNROLL
54 #endif
55 
56 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
58 #define GEOS_DEVICE_COMPILE
59 #endif
60 
62 
73 
74 #if defined(__NVCC__)
76 #define GEOS_NV_HOST_DEVICE_DIAG_SUPPRESS _Pragma("nv_diag_suppress 20011") _Pragma("nv_diag_suppress 20014")
78 #define GEOS_NV_HOST_DEVICE_DIAG_DEFAULT _Pragma("nv_diag_default 20011") _Pragma("nv_diag_default 20014")
79 #else
81 #define GEOS_NV_HOST_DEVICE_DIAG_SUPPRESS
82 #define GEOS_NV_HOST_DEVICE_DIAG_DEFAULT
84 #endif
85 
87 
95 
97 #define GEOS_UNUSED_PARAM( X )
98 
104 template< typename ... ARGS >
105 GEOS_HOST_DEVICE inline constexpr
106 void i_g_n_o_r_e( ARGS const & ... ) {}
107 
109 #define GEOS_UNUSED_VAR( ... ) i_g_n_o_r_e( __VA_ARGS__ )
110 
112 #define GEOS_DEBUG_VAR( ... ) GEOS_UNUSED_VAR( __VA_ARGS__ )
113 
115 
116 #if defined(GEOS_USE_OPENMP)
118 #define PRAGMA_OMP( clause ) _Pragma( clause )
119 // #define PRAGMA_OMP( clause ) _Pragma( STRINGIZE( omp clause ) )
120 #else
122 #define PRAGMA_OMP( clause )
123 #endif
124 
126 #define GEOS_RESTRICT LVARRAY_RESTRICT
127 
129 #define GEOS_RESTRICT_THIS LVARRAY_RESTRICT_THIS
130 
132 #define GEOS_DECLTYPE_AUTO_RETURN decltype( auto )
133 
135 #define GEOS_CONCAT_IMPL( A, B ) A ## B
136 
138 #define GEOS_CONCAT( A, B ) GEOS_CONCAT_IMPL( A, B )
139 
144 #if __cplusplus >= 201703L
145 #define GEOS_MAYBE_UNUSED [[maybe_unused]]
146 #else
147 // If not C++17 or later, check the compiler.
148  #ifdef _MSC_VER
149 // Microsoft Visual Studio
150 #define GEOS_MAYBE_UNUSED __pragma(warning(suppress: 4100))
151  #elif defined(__GNUC__) || defined(__clang__)
152 // GCC or Clang
153 #define GEOS_MAYBE_UNUSED __attribute__((unused))
154  #else
155 // If the compiler is unknown, we can't suppress the warning,
156 // so we define GEOS_MAYBE_UNUSED as an empty macro.
157 #define GEOS_MAYBE_UNUSED
158  #endif
159 #endif
160 
167 
169 #define GEOS_DETAIL_MORE_THAN_ONE_ARG_VALUE( _00, _01, _02, _03, _04, _05, _06, _07, \
170  _08, _09, _10, _11, _12, _13, _14, _15, \
171  _INDEX, ... ) _INDEX
172 
177 #define GEOS_DETAIL_MORE_THAN_ONE_ARG( ... ) \
178  GEOS_DETAIL_MORE_THAN_ONE_ARG_VALUE( __VA_ARGS__, \
179  true, true, true, true, true, true, true, true, \
180  true, true, true, true, true, true, true, false, false )
181 
183 
185 #define GEOS_DETAIL_FIRST_ARG_false( FIRST ) FIRST
186 #define GEOS_DETAIL_FIRST_ARG_true( FIRST, ... ) FIRST
187 #define GEOS_DETAIL_FIRST_ARG_FUNC( COND ) GEOS_DETAIL_FIRST_ARG_ ## COND
188 #define GEOS_DETAIL_FIRST_ARG_DISPATCH( COND, ... ) GEOS_DETAIL_FIRST_ARG_FUNC( COND )(__VA_ARGS__)
189 
191 #define GEOS_DETAIL_REST_ARGS_false( FIRST )
192 #define GEOS_DETAIL_REST_ARGS_true( FIRST, ... ) __VA_ARGS__
193 #define GEOS_DETAIL_REST_ARGS_FUNC( COND ) GEOS_DETAIL_REST_ARGS_ ## COND
194 #define GEOS_DETAIL_REST_ARGS_DISPATCH( COND, ... ) GEOS_DETAIL_REST_ARGS_FUNC( COND )(__VA_ARGS__)
195 
197 #define GEOS_DETAIL_REST_PREP_ARGS_false( FIRST )
198 #define GEOS_DETAIL_REST_PREP_ARGS_true( FIRST, ... ) , __VA_ARGS__
199 #define GEOS_DETAIL_REST_PREP_ARGS_FUNC( COND ) GEOS_DETAIL_REST_PREP_ARGS_ ## COND
200 #define GEOS_DETAIL_REST_PREP_ARGS_DISPATCH( COND, ... ) GEOS_DETAIL_REST_PREP_ARGS_FUNC( COND )(__VA_ARGS__)
201 
203 
208 #define GEOS_DETAIL_FIRST_ARG( ... ) GEOS_DETAIL_FIRST_ARG_DISPATCH( GEOS_DETAIL_MORE_THAN_ONE_ARG( __VA_ARGS__ ), \
209  __VA_ARGS__ )
210 
215 #define GEOS_DETAIL_REST_ARGS( ... ) GEOS_DETAIL_REST_ARGS_DISPATCH( GEOS_DETAIL_MORE_THAN_ONE_ARG( __VA_ARGS__ ), \
216  __VA_ARGS__ )
217 
223 #define GEOS_DETAIL_REST_PREP_ARGS( ... ) GEOS_DETAIL_REST_PREP_ARGS_DISPATCH( GEOS_DETAIL_MORE_THAN_ONE_ARG( __VA_ARGS__ ), \
224  __VA_ARGS__ )
225 
226 namespace geos::internal
227 {
228 
233 struct DeviceNullStream
234 {
235  template< class T >
236  GEOS_HOST_DEVICE constexpr DeviceNullStream & operator<<( T const & ) noexcept
237  {
238  return *this;
239  }
240 };
241 
242 }
243 
245 
246 #endif // GEOS_COMMON_GEOSXMACROS_HPP_
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
constexpr void i_g_n_o_r_e(ARGS const &...)
Used to silence unused variable warnings, cuda doesn't respect casting to void.
std::ostream & operator<<(std::ostream &stream, mapType< K, V, SORTED > const &map)
Stream output operator for map types.
Definition: DataTypes.hpp:326