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