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