VTK-m  2.2
Configure.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_internal_Configure_h
11 #define vtk_m_internal_Configure_h
12 
13 // Defined when NVCC is compiling either __host__ or __device__ code.
14 #ifdef __CUDACC__
15 #define VTKM_CUDA
16 #endif
17 
18 // Defined only when NVCC is compiling __device__ code.
19 #ifdef __CUDA_ARCH__
20 #define VTKM_CUDA_DEVICE_PASS
21 #endif
22 
23 // Defined when compiling for the HIP language.
24 #ifdef __HIP__
25 #define VTKM_HIP
26 #endif
27 
28 #if defined(_MSC_VER)
29 //MSVC 2015+ can use a clang frontend, so we want to label it only as MSVC
30 //and not MSVC and clang
31 #define VTKM_MSVC
32 
33 #elif defined(__INTEL_COMPILER)
34 //Intel 14+ on OSX uses a clang frontend, so again we want to label them as
35 //intel only, and not intel and clang
36 #define VTKM_ICC
37 
38 #elif defined(__PGI)
39 // PGI reports as GNUC as it generates the same ABI, so we need to check for
40 // it before gcc.
41 #define VTKM_PGI
42 
43 #elif defined(__ibmxl__)
44 //Check for xl before GCC and clang, as xl claims it is many things
45 #define VTKM_XL
46 
47 #elif defined(__clang__)
48 //Check for clang before GCC, as clang says it is GNUC since it has ABI
49 //compliance
50 #define VTKM_CLANG
51 
52 #elif defined(__MINGW32__)
53 //Check for MinGW before GCC, since MinGW will be otherwise categorized
54 //as VTKM_GCC
55 #define VTKM_MINGW
56 
57 #elif defined(__GNUC__)
58 // Several compilers pretend to be GCC but have minor differences. Try to
59 // compensate for that, by checking for those compilers first
60 #define VTKM_GCC
61 #endif
62 
63 
64 #if defined(unix) || defined(__unix) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
65 #include <unistd.h>
66 # ifdef _POSIX_VERSION
67 # define VTKM_POSIX _POSIX_VERSION
68 # endif
69 #endif
70 
71 #if defined(_WIN32)
72 # define VTKM_WINDOWS
73 #endif
74 
75 #if !defined(VTKM_NO_ASSERT)
76 /* #undef VTKM_NO_ASSERT */
77 #endif
78 
79 #if !defined(VTKM_NO_ASSERT_CUDA)
80 #define VTKM_NO_ASSERT_CUDA
81 #endif
82 
83 #if !defined(VTKM_NO_ASSERT_HIP)
84 #define VTKM_NO_ASSERT_HIP
85 #endif
86 
87 #if !defined(VTKM_USE_DOUBLE_PRECISION) && !defined(VTKM_NO_DOUBLE_PRECISION)
88 /* #undef VTKM_USE_DOUBLE_PRECISION */
89 #endif
90 
91 #if defined(VTKM_USE_DOUBLE_PRECISION) && defined(VTKM_NO_DOUBLE_PRECISION)
92 # error Both VTKM_USE_DOUBLE_PRECISION and VTKM_NO_DOUBLE_PRECISION defined. Do not know what to do.
93 #endif
94 
95 #if !defined(VTKM_USE_64BIT_IDS) && !defined(VTKM_NO_64BIT_IDS)
96 #define VTKM_USE_64BIT_IDS
97 #endif
98 
99 #if defined(VTKM_USE_64BIT_IDS) && defined(VTKM_NO_64BIT_IDS)
100 # error Both VTKM_USE_64BIT_IDS and VTKM_NO_64BIT_IDS defined. Do not know what to do.
101 #endif
102 
103 #define VTKM_SIZE_LONG 8
104 #define VTKM_SIZE_LONG_LONG 8
105 
106 // Defines the cache line size in bytes to align allocations to
107 #ifndef VTKM_ALLOCATION_ALIGNMENT
108 #define VTKM_ALLOCATION_ALIGNMENT 64
109 #endif
110 
111 // Define a pair of macros, VTKM_THIRDPARTY_PRE_INCLUDE and VTKM_THIRDPARTY_POST_INCLUDE,
112 // that should be wrapped around any #include for a tbb or thrust header file. Mostly
113 // this is used to set pragmas that dissable warnings that VTK-m checks for
114 // but tbb and thrust does not.
115 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
116 
117 #define VTK_M_THIRDPARTY_GENERAL_WARNING_PRAGMAS \
118  _Pragma("GCC diagnostic ignored \"-Wconversion\"") \
119  _Pragma("GCC diagnostic ignored \"-Wshadow\"") \
120  _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"")
121 
122 // GCC has a unused by set variable warnings that needs to be silenced.
123 #if defined(VTKM_GCC)
124 #define VTK_M_THIRDPARTY_GCC_WARNING_PRAGMAS \
125  _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"") \
126  _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
127 #else
128 #define VTK_M_THIRDPARTY_GCC_WARNING_PRAGMAS
129 #endif
130 
131 
132 #if defined(VTKM_CLANG) && (__apple_build_version__ >= 7000072)
133 // 1. Newer versions of clang have an unused-local-typedef warning, but not older
134 // versions. This checks for the apple version of clang, which is different
135 // than other clang compiled versions.
136 // 2+. Suppress common issues found in third-party code such
137 // as DIY
138 #define VTK_M_THIRDPARTY_CLANG_WARNING_PRAGMAS \
139  _Pragma("GCC diagnostic ignored \"-Wunused-local-typedef\"") \
140  _Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"") \
141  _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
142  _Pragma("GCC diagnostic ignored \"-Wunused-template\"")
143 #elif defined(VTKM_CLANG) && defined(__ibmxl__)
144 #define VTK_M_THIRDPARTY_CLANG_WARNING_PRAGMAS \
145  _Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"") \
146  _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
147 #elif defined(VTKM_CLANG)
148 #define VTK_M_THIRDPARTY_CLANG_WARNING_PRAGMAS \
149  _Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"") \
150  _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
151  _Pragma("GCC diagnostic ignored \"-Wunused-template\"")
152 #else
153 #define VTK_M_THIRDPARTY_CLANG_WARNING_PRAGMAS
154 #endif
155 
156 // Older versions of GCC don't support the push/pop pragmas. Right now we are
157 // not checking for GCC 3 or earlier. I'm not sure we have a use case for that.
158 #if defined(VTKM_GCC) && (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
159 #define VTK_M_THIRDPARTY_WARNINGS_PUSH
160 #define VTK_M_THRIDPARTY_WARNINGS_POP
161 #else
162 #define VTK_M_THIRDPARTY_WARNINGS_PUSH _Pragma("GCC diagnostic push")
163 #define VTK_M_THRIDPARTY_WARNINGS_POP _Pragma("GCC diagnostic pop")
164 #endif
165 
166 #define VTKM_THIRDPARTY_PRE_INCLUDE \
167  VTK_M_THIRDPARTY_WARNINGS_PUSH \
168  VTK_M_THIRDPARTY_GENERAL_WARNING_PRAGMAS \
169  VTK_M_THIRDPARTY_GCC_WARNING_PRAGMAS \
170  VTK_M_THIRDPARTY_CLANG_WARNING_PRAGMAS
171 #define VTKM_THIRDPARTY_POST_INCLUDE \
172  VTK_M_THRIDPARTY_WARNINGS_POP
173 
174 #elif (defined(VTKM_MSVC))
175 #define VTKM_THIRDPARTY_PRE_INCLUDE \
176  __pragma(warning(push)) \
177  __pragma(warning(disable:4100)) \
178  __pragma(warning(disable:4127)) \
179  __pragma(warning(disable:4201)) \
180  __pragma(warning(disable:4244)) \
181  __pragma(warning(disable:4267)) \
182  __pragma(warning(disable:4324)) \
183  __pragma(warning(disable:4510)) \
184  __pragma(warning(disable:4512)) \
185  __pragma(warning(disable:4515)) \
186  __pragma(warning(disable:4610)) \
187  __pragma(warning(disable:4800))
188 #define VTKM_THIRDPARTY_POST_INCLUDE \
189  __pragma(warning(pop))
190 #else
191 #define VTKM_THIRDPARTY_PRE_INCLUDE
192 #define VTKM_THIRDPARTY_POST_INCLUDE
193 #endif
194 
195 #include <cctype> //needed to get the __GLIBCXX__ macro
196 #if defined(__GLIBCXX__) && \
197  (__GLIBCXX__ < 20150422 || __GLIBCXX__ == 20160726 || __GLIBCXX__ == 20150626 || \
198  __GLIBCXX__ == 20150623)
199 // GCC release date mapping
200 // 20160726 == 4.9.4
201 // 20150626 == 4.9.3
202 // 20150623 == 4.8.5
203 // 20150422 == 5.1
204 // 20141030 == 4.9.2
205 // See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning.__GLIBCXX__
206 // Some context on why this check is useful
207 // Components of the c++ standard such as `std::aligned_union` are not something
208 // intrinsic to compiler but part of the standard library. Therefore support for these
209 // features are determined by what standard library is used versus the compiler.
210 // For example by default Intel, PGI, and IBM compilers use the standard library
211 // that is provided by a systems default C++ compiler ( generally gcc ). For this
212 // reason we have a define that states we are compiling with GLIBCXX_4 which
213 // is missing some usefull C++ standard library components
214 //
215 #define VTKM_USING_GLIBCXX_4
216 #endif
217 
218 //Determine if current compiler supports vectorization pragma's
219 //if so set the define VTKM_COMPILER_SUPPORTS_VECTOR_PRAGMAS
220 //
221 //While ICC 14 does support simd pragma, in testing we find that the
222 //simd code produces SIGBUS and isn't safe to use.
223 //
224 #if ( defined(VTKM_GCC) && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) ) ) || \
225  ( defined(VTKM_ICC) && (__INTEL_COMPILER >= 1500) ) || \
226  ( defined(VTKM_CLANG) && defined(__apple_build_version__) && (__apple_build_version__ >= 7000000) ) || \
227  ( defined(VTKM_CLANG) && !defined(__apple_build_version__) && (__clang_major__ > 3) ) || \
228  ( defined(VTKM_CLANG) && !defined(__apple_build_version__) && (__clang_major__ == 3 && __clang_minor__ >= 5) )
229 #define VTKM_COMPILER_SUPPORTS_VECTOR_PRAGMAS 1
230 #endif
231 
232 
233 // Define a pair of macros, VTKM_VECTORIZATION_PRE_LOOP and VTKM_VECTORIZATION_IN_LOOP,
234 // that should be wrapped around any "for"/"while" that you want vectorized.
235 // This is used to set per compiler pragmas for vectorization, and to disable
236 // any warnings that about vectorization failures.
237 /* #undef VTKM_VECTORIZATION_ENABLED */
238 
239 #if defined(VTKM_COMPILER_SUPPORTS_VECTOR_PRAGMAS) &&\
240  defined(VTKM_VECTORIZATION_ENABLED)
241 #if defined(VTKM_CLANG)
242 //clang only needs pre loop
243 #define VTKM_VECTORIZATION_PRE_LOOP \
244  _Pragma("clang loop vectorize(enable) interleave(enable)")
245 #define VTKM_VECTORIZATION_IN_LOOP
246 #elif defined(VTKM_ICC) && defined(NDEBUG)
247 //Note: icc can't do vectorization in debug builds
248 //icc needs pre and in loop
249 //For ICC we want ivdep over simd for the following reason:
250 //#pragma simd is a more powerful combo of '#pragma vector always' and '#pragma ivdep'
251 //The compiler does not check for aliasing or dependencies that might cause
252 //incorrect results after vectorization, and it does not protect against illegal
253 //memory references. #pragma ivdep overrides potential dependencies, but the
254 //compiler still performs a dependency analysis, and will not vectorize if it
255 //finds a proven dependency that would affect results. With #pragma simd, the
256 //compiler does no such analysis, and tries to vectorize regardless.
257 //
258 //Final: We are currently disabling all vectorization with ICC
259 // in the short-term. Both ivdep and simd cause a horrible decrease in compile
260 // time, and generates bad vectorization code.
261 #define VTKM_VECTORIZATION_PRE_LOOP
262 #define VTKM_VECTORIZATION_IN_LOOP
263 #elif defined(VTKM_GCC)
264 //gcc only needs in loop
265 #define VTKM_VECTORIZATION_PRE_LOOP \
266  _Pragma("GCC ivdep")
267 #define VTKM_VECTORIZATION_IN_LOOP
268 #else
269 // Compiler is unknown so we don't define any vectortization pragmas
270 #define VTKM_VECTORIZATION_PRE_LOOP
271 #define VTKM_VECTORIZATION_IN_LOOP
272 #endif
273 #else
274 // Compiler doesn't support any vectortization pragmas
275 #define VTKM_VECTORIZATION_PRE_LOOP
276 #define VTKM_VECTORIZATION_IN_LOOP
277 #endif
278 
279 //Mark if we are building with CUDA enabled
280 #ifndef VTKM_ENABLE_CUDA
281 /* #undef VTKM_ENABLE_CUDA */
282 #endif
283 //Mark if we are building with TBB enabled
284 #ifndef VTKM_ENABLE_TBB
285 #define VTKM_ENABLE_TBB
286 #endif
287 //Mark if we are building with OpenMP enabled
288 #ifndef VTKM_ENABLE_OPENMP
289 #define VTKM_ENABLE_OPENMP
290 #endif
291 //Mark if we are building with Kokkos enabled
292 #ifndef VTKM_ENABLE_KOKKOS
293 /* #undef VTKM_ENABLE_KOKKOS */
294 #endif
295 //Mark if Kokkos has Cuda backend enabled
296 #ifndef VTKM_KOKKOS_CUDA
297 /* #undef VTKM_KOKKOS_CUDA */
298 #endif
299 //Mark if Kokkos has HIP backend enabled
300 #ifndef VTKM_KOKKOS_HIP
301 /* #undef VTKM_KOKKOS_HIP */
302 #endif
303 // Mark if Kokkos algorithms should use thrust
304 #if defined(VTKM_KOKKOS_HIP) || defined(VTKM_KOKKOS_CUDA)
305 /* #undef VTKM_ENABLE_KOKKOS_THRUST */
306 #endif
307 
308 //Mark if we are building with MPI enabled.
309 #define VTKM_ENABLE_MPI
310 
311 //Mark if we are building with GPU AWARE MPI enabled.
312 /* #undef VTKM_ENABLE_GPU_MPI */
313 
314 //Mark what version of the CUDA compiler we have. This is needed to correctly
315 //choose consistent implementation ( so we don't violate ODR ) when we compile
316 //with CUDA 7.5
317 #ifdef VTKM_ENABLE_CUDA
318 #define VTKM_CUDA_VERSION_MAJOR
319 #define VTKM_CUDA_VERSION_MINOR
320 #endif
321 
322 #if __cplusplus >= 201402L || \
323  ( defined(VTKM_MSVC) && _MSC_VER >= 1910 ) || \
324  ( defined(VTKM_ICC) && defined(__INTEL_CXX11_MODE__) )
325 #define VTKM_HAVE_CXX_14
326 #else
327 #error "VTK-m requires at least a C++14 compiler"
328 #endif
329 
330 //Mark if we have enabled logging.
331 #define VTKM_ENABLE_LOGGING
332 
333 // Define a pair of macros, VTKM_SWALLOW_SEMICOLON_PRE_BLOCK and
334 // VTKM_SWALLOW_SEMICOLON_POST_BLOCK that can be used around a block in a
335 // macro to "swallow" the semicolon after the macro's use so that it is
336 // used like a function without warnings about extra semicolons. It is
337 // generally implemented by wrapping the block as a do/while with a false
338 // condition so that it executes exactly once. (See, for example,
339 // https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html)
340 // However, some compilers might complain about this, too. For example, you
341 // might get a complaint about a loop with a constant expression. These
342 // macros take care of these conditions.
343 #ifdef VTKM_MSVC
344 #define VTKM_SWALLOW_SEMICOLON_PRE_BLOCK \
345  __pragma(warning(push)) \
346  __pragma(warning(disable:4127)) \
347  do
348 #define VTKM_SWALLOW_SEMICOLON_POST_BLOCK \
349  while (false) \
350  __pragma(warning(pop))
351 #else // not VTKM_MSVC
352 #define VTKM_SWALLOW_SEMICOLON_PRE_BLOCK \
353  do
354 #define VTKM_SWALLOW_SEMICOLON_POST_BLOCK \
355  while (false)
356 #endif
357 
364 #define VTKM_PASS_COMMAS(...) __VA_ARGS__
365 
394 #define VTKM_EXPAND(expr) expr
395 
396 #ifdef VTKM_MSVC
397 //With MSVC the types that we generate cause warning C4503 (long symbol names)
398 //this doesn't affect the resulting binary so we just suppress that warning
399 //
400 #pragma warning(disable:4503)
401 
402 //In VTK-m libraries, we are typically exporting (with declspec) classes rather
403 //than the independent methods within the class. When you are exporting to a
404 //dll in MSVC and the class contains a field that is not similarly exported,
405 //then you get a warning. This is generally not an issue for our use since we
406 //are really only using classes from the standard library and distributed with
407 //VTK-m itself. The only sane way to fix the issue is to just disable the
408 //warning.
409 //
410 #pragma warning(disable:4251)
411 
412 #endif
413 
414 //----------------------------------------------------------------------------
415 // Switch case fall-through policy.
416 
417 // Use "VTKM_FALLTHROUGH;" to annotate deliberate fall-through in switches,
418 // use it analogously to "break;". The trailing semi-colon is required.
419 #if !defined(VTKM_FALLTHROUGH) && defined(__has_cpp_attribute)
420 # if __cplusplus >= 201703L && __has_cpp_attribute(fallthrough)
421 # define VTKM_FALLTHROUGH [[fallthrough]]
422 # elif __cplusplus >= 201103L && __has_cpp_attribute(gnu::fallthrough)
423 # define VTKM_FALLTHROUGH [[gnu::fallthrough]]
424 # elif __cplusplus >= 201103L && __has_cpp_attribute(clang::fallthrough)
425 # define VTKM_FALLTHROUGH [[clang::fallthrough]]
426 # endif
427 #endif
428 
429 #ifndef VTKM_FALLTHROUGH
430 # define VTKM_FALLTHROUGH ((void)0)
431 #endif
432 
433 #endif //vtkm_internal_Configure_h