Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_Macros.hpp
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 
17 #ifndef KOKKOS_MACROS_HPP
18 #define KOKKOS_MACROS_HPP
19 
20 //----------------------------------------------------------------------------
36 #define KOKKOS_VERSION_LESS(MAJOR, MINOR, PATCH) \
37  (KOKKOS_VERSION < ((MAJOR)*10000 + (MINOR)*100 + (PATCH)))
38 
39 #define KOKKOS_VERSION_LESS_EQUAL(MAJOR, MINOR, PATCH) \
40  (KOKKOS_VERSION <= ((MAJOR)*10000 + (MINOR)*100 + (PATCH)))
41 
42 #define KOKKOS_VERSION_GREATER(MAJOR, MINOR, PATCH) \
43  (KOKKOS_VERSION > ((MAJOR)*10000 + (MINOR)*100 + (PATCH)))
44 
45 #define KOKKOS_VERSION_GREATER_EQUAL(MAJOR, MINOR, PATCH) \
46  (KOKKOS_VERSION >= ((MAJOR)*10000 + (MINOR)*100 + (PATCH)))
47 
48 #define KOKKOS_VERSION_EQUAL(MAJOR, MINOR, PATCH) \
49  (KOKKOS_VERSION == ((MAJOR)*10000 + (MINOR)*100 + (PATCH)))
50 
51 #if !KOKKOS_VERSION_EQUAL(KOKKOS_VERSION_MAJOR, KOKKOS_VERSION_MINOR, \
52  KOKKOS_VERSION_PATCH)
53 #error implementation bug
54 #endif
55 
56 #ifndef KOKKOS_DONT_INCLUDE_CORE_CONFIG_H
57 #include <KokkosCore_config.h>
58 #include <impl/Kokkos_DesulAtomicsConfig.hpp>
59 #include <impl/Kokkos_NvidiaGpuArchitectures.hpp>
60 #endif
61 
62 #if !defined(KOKKOS_ENABLE_CXX17)
63 #if __has_include(<version>)
64 #include <version>
65 #else
66 #include <ciso646>
67 #endif
68 #if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 10
69 #error \
70  "Compiling with support for C++20 or later requires a libstdc++ version later than 9"
71 #endif
72 #endif
73 
74 //----------------------------------------------------------------------------
98 //----------------------------------------------------------------------------
99 
100 #if defined(KOKKOS_ENABLE_ATOMICS_BYPASS) && \
101  (defined(KOKKOS_ENABLE_THREADS) || defined(KOKKOS_ENABLE_CUDA) || \
102  defined(KOKKOS_ENABLE_OPENMP) || defined(KOKKOS_ENABLE_HPX) || \
103  defined(KOKKOS_ENABLE_OPENMPTARGET) || defined(KOKKOS_ENABLE_HIP) || \
104  defined(KOKKOS_ENABLE_SYCL) || defined(KOKKOS_ENABLE_OPENACC))
105 #error Atomics may only be disabled if neither a host parallel nor a device backend is enabled
106 #endif
107 
108 #define KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA
109 
110 #include <KokkosCore_Config_SetupBackend.hpp>
111 
112 //----------------------------------------------------------------------------
113 // Mapping compiler built-ins to KOKKOS_COMPILER_*** macros
114 
115 #if defined(__NVCC__)
116 // NVIDIA compiler is being used.
117 // Code is parsed and separated into host and device code.
118 // Host code is compiled again with another compiler.
119 // Device code is compile to 'ptx'.
120 // NOTE: There is no __CUDACC_VER_PATCH__ officially, its __CUDACC_VER_BUILD__
121 // which does have more than one digit (potentially undefined number of them).
122 // This macro definition is in line with our other compiler defs
123 #define KOKKOS_COMPILER_NVCC \
124  __CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__ * 10
125 #endif // #if defined( __NVCC__ )
126 
127 #if !defined(KOKKOS_LAMBDA)
128 #define KOKKOS_LAMBDA [=]
129 #endif
130 
131 #if !defined(KOKKOS_CLASS_LAMBDA)
132 #define KOKKOS_CLASS_LAMBDA [ =, *this ]
133 #endif
134 
135 //#if !defined( __CUDA_ARCH__ ) // Not compiling Cuda code to 'ptx'.
136 
137 // Intel compiler for host code.
138 
139 #if defined(__INTEL_COMPILER)
140 #define KOKKOS_COMPILER_INTEL __INTEL_COMPILER
141 
142 #elif defined(__INTEL_LLVM_COMPILER)
143 #define KOKKOS_COMPILER_INTEL_LLVM __INTEL_LLVM_COMPILER
144 
145 // Cray compiler for device offload code
146 #elif defined(__cray__) && defined(__clang__)
147 #define KOKKOS_COMPILER_CRAY_LLVM \
148  __cray_major__ * 100 + __cray_minor__ * 10 + __cray_patchlevel__
149 
150 #elif defined(_CRAYC)
151 // CRAY compiler for host code
152 #define KOKKOS_COMPILER_CRAYC _CRAYC
153 
154 #elif defined(__APPLE_CC__)
155 #define KOKKOS_COMPILER_APPLECC __APPLE_CC__
156 
157 #elif defined(__NVCOMPILER)
158 #define KOKKOS_COMPILER_NVHPC \
159  __NVCOMPILER_MAJOR__ * 10000 + __NVCOMPILER_MINOR__ * 100 + \
160  __NVCOMPILER_PATCHLEVEL__
161 
162 #elif defined(__clang__)
163 // Check this after the Clang-based proprietary compilers which will also define
164 // __clang__
165 #define KOKKOS_COMPILER_CLANG \
166  __clang_major__ * 100 + __clang_minor__ * 10 + __clang_patchlevel__
167 
168 #elif defined(__GNUC__)
169 // Check this here because many compilers (at least Clang variants and Intel
170 // classic) define `__GNUC__` for compatibility
171 #define KOKKOS_COMPILER_GNU \
172  __GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__
173 
174 #if (820 > KOKKOS_COMPILER_GNU)
175 #error "Compiling with GCC version earlier than 8.2.0 is not supported."
176 #endif
177 
178 #elif defined(_MSC_VER)
179 // Check this after Intel and Clang because those define _MSC_VER for
180 // compatibility
181 #define KOKKOS_COMPILER_MSVC _MSC_VER
182 #endif
183 
184 #if defined(_OPENMP)
185 // Compiling with OpenMP.
186 // The value of _OPENMP is an integer value YYYYMM
187 // where YYYY and MM are the year and month designation
188 // of the supported OpenMP API version.
189 #endif // #if defined( _OPENMP )
190 
191 //----------------------------------------------------------------------------
192 // Intel compiler macros
193 
194 #if defined(KOKKOS_COMPILER_INTEL) || defined(KOKKOS_COMPILER_INTEL_LLVM)
195 #if defined(KOKKOS_COMPILER_INTEL_LLVM) && \
196  KOKKOS_COMPILER_INTEL_LLVM >= 20230100
197 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
198 #define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
199 #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
200 
201 #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
202 #endif
203 
204 #if !defined(KOKKOS_MEMORY_ALIGNMENT)
205 #define KOKKOS_MEMORY_ALIGNMENT 64
206 #endif
207 
208 #if defined(_WIN32)
209 #define KOKKOS_RESTRICT __restrict
210 #else
211 #define KOKKOS_RESTRICT __restrict__
212 #endif
213 
214 #ifndef KOKKOS_IMPL_ALIGN_PTR
215 #if defined(_WIN32)
216 #define KOKKOS_IMPL_ALIGN_PTR(size) __declspec(align_value(size))
217 #else
218 #define KOKKOS_IMPL_ALIGN_PTR(size) __attribute__((align_value(size)))
219 #endif
220 #endif
221 
222 #if defined(KOKKOS_COMPILER_INTEL) && (1900 > KOKKOS_COMPILER_INTEL)
223 #error "Compiling with Intel version earlier than 19.0.5 is not supported."
224 #endif
225 
226 #if !defined(KOKKOS_ENABLE_ASM) && !defined(_WIN32)
227 #define KOKKOS_ENABLE_ASM 1
228 #endif
229 
230 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
231 #if !defined(_WIN32)
232 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
233  inline __attribute__((always_inline))
234 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
235 #else
236 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION inline
237 #endif
238 #endif
239 
240 #if defined(__MIC__)
241 // Compiling for Xeon Phi
242 #endif
243 #endif
244 
245 //----------------------------------------------------------------------------
246 // Cray compiler macros
247 
248 #if defined(KOKKOS_COMPILER_CRAYC)
249 #endif
250 
251 //----------------------------------------------------------------------------
252 // CLANG compiler macros
253 
254 #if defined(KOKKOS_COMPILER_CLANG)
255 //#define KOKKOS_ENABLE_PRAGMA_UNROLL 1
256 //#define KOKKOS_ENABLE_PRAGMA_IVDEP 1
257 //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
258 //#define KOKKOS_ENABLE_PRAGMA_VECTOR 1
259 
260 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
261 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
262  inline __attribute__((always_inline))
263 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
264 #endif
265 
266 #if !defined(KOKKOS_IMPL_ALIGN_PTR)
267 #define KOKKOS_IMPL_ALIGN_PTR(size) __attribute__((aligned(size)))
268 #endif
269 
270 #endif
271 
272 //----------------------------------------------------------------------------
273 // GNU Compiler macros
274 
275 #if defined(KOKKOS_COMPILER_GNU)
276 //#define KOKKOS_ENABLE_PRAGMA_UNROLL 1
277 //#define KOKKOS_ENABLE_PRAGMA_IVDEP 1
278 //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
279 //#define KOKKOS_ENABLE_PRAGMA_VECTOR 1
280 
281 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
282 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
283  inline __attribute__((always_inline))
284 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
285 #endif
286 
287 #define KOKKOS_RESTRICT __restrict__
288 
289 #if !defined(KOKKOS_ENABLE_ASM) && !defined(__PGIC__) && \
290  (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || \
291  defined(__x86_64__) || defined(__PPC64__))
292 #define KOKKOS_ENABLE_ASM 1
293 #endif
294 #endif
295 
296 //----------------------------------------------------------------------------
297 
298 #if defined(KOKKOS_COMPILER_NVHPC)
299 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
300 #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
301 //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
302 #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
303 #endif
304 
305 //----------------------------------------------------------------------------
306 
307 #if defined(KOKKOS_COMPILER_NVCC)
308 #if defined(__CUDA_ARCH__)
309 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
310 #endif
311 #endif
312 
313 //----------------------------------------------------------------------------
314 // Define function marking macros if compiler specific macros are undefined:
315 
316 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
317 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION inline
318 #endif
319 
320 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE)
321 #define KOKKOS_IMPL_HOST_FORCEINLINE inline
322 #endif
323 
324 #if !defined(KOKKOS_IMPL_FORCEINLINE_FUNCTION)
325 #define KOKKOS_IMPL_FORCEINLINE_FUNCTION KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION
326 #endif
327 
328 #if !defined(KOKKOS_IMPL_FORCEINLINE)
329 #define KOKKOS_IMPL_FORCEINLINE KOKKOS_IMPL_HOST_FORCEINLINE
330 #endif
331 
332 #if !defined(KOKKOS_IMPL_INLINE_FUNCTION)
333 #define KOKKOS_IMPL_INLINE_FUNCTION inline
334 #endif
335 
336 #if !defined(KOKKOS_IMPL_FUNCTION)
337 #define KOKKOS_IMPL_FUNCTION
338 #endif
339 
340 #if !defined(KOKKOS_INLINE_FUNCTION_DELETED)
341 #define KOKKOS_INLINE_FUNCTION_DELETED
342 #endif
343 
344 #if !defined(KOKKOS_DEFAULTED_FUNCTION)
345 #define KOKKOS_DEFAULTED_FUNCTION
346 #endif
347 
348 #if !defined(KOKKOS_DEDUCTION_GUIDE)
349 #define KOKKOS_DEDUCTION_GUIDE
350 #endif
351 
352 #if !defined(KOKKOS_IMPL_HOST_FUNCTION)
353 #define KOKKOS_IMPL_HOST_FUNCTION
354 #endif
355 
356 #if !defined(KOKKOS_IMPL_DEVICE_FUNCTION)
357 #define KOKKOS_IMPL_DEVICE_FUNCTION
358 #endif
359 
360 //----------------------------------------------------------------------------
361 // Define final version of functions. This is so that clang tidy can find these
362 // macros more easily
363 #if defined(__clang_analyzer__)
364 #define KOKKOS_FUNCTION \
365  KOKKOS_IMPL_FUNCTION __attribute__((annotate("KOKKOS_FUNCTION")))
366 #define KOKKOS_INLINE_FUNCTION \
367  KOKKOS_IMPL_INLINE_FUNCTION \
368  __attribute__((annotate("KOKKOS_INLINE_FUNCTION")))
369 #define KOKKOS_FORCEINLINE_FUNCTION \
370  KOKKOS_IMPL_FORCEINLINE_FUNCTION \
371  __attribute__((annotate("KOKKOS_FORCEINLINE_FUNCTION")))
372 #else
373 #define KOKKOS_FUNCTION KOKKOS_IMPL_FUNCTION
374 #define KOKKOS_INLINE_FUNCTION KOKKOS_IMPL_INLINE_FUNCTION
375 #define KOKKOS_FORCEINLINE_FUNCTION KOKKOS_IMPL_FORCEINLINE_FUNCTION
376 #endif
377 
378 //----------------------------------------------------------------------------
379 // Define empty macro for restrict if necessary:
380 
381 #if !defined(KOKKOS_RESTRICT)
382 #define KOKKOS_RESTRICT
383 #endif
384 
385 //----------------------------------------------------------------------------
386 // Define Macro for alignment:
387 
388 #if !defined(KOKKOS_MEMORY_ALIGNMENT)
389 #define KOKKOS_MEMORY_ALIGNMENT 64
390 #endif
391 
392 #if !defined(KOKKOS_MEMORY_ALIGNMENT_THRESHOLD)
393 #define KOKKOS_MEMORY_ALIGNMENT_THRESHOLD 1
394 #endif
395 
396 #if !defined(KOKKOS_IMPL_ALIGN_PTR)
397 #define KOKKOS_IMPL_ALIGN_PTR(size) /* */
398 #endif
399 
400 //----------------------------------------------------------------------------
401 // Determine the default execution space for parallel dispatch.
402 // There is zero or one default execution space specified.
403 
404 #if 1 < ((defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA) ? 1 : 0) + \
405  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP) ? 1 : 0) + \
406  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL) ? 1 : 0) + \
407  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC) ? 1 : 0) + \
408  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET) ? 1 : 0) + \
409  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP) ? 1 : 0) + \
410  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS) ? 1 : 0) + \
411  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX) ? 1 : 0) + \
412  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL) ? 1 : 0))
413 #error "More than one KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_* specified."
414 #endif
415 
416 // If default is not specified then chose from enabled execution spaces.
417 // Priority: CUDA, HIP, SYCL, OPENACC, OPENMPTARGET, OPENMP, THREADS, HPX,
418 // SERIAL
419 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
420 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
421 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
422 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
423 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
424 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
425 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
426 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
427 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
428 #elif defined(KOKKOS_ENABLE_CUDA)
429 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA
430 #elif defined(KOKKOS_ENABLE_HIP)
431 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP
432 #elif defined(KOKKOS_ENABLE_SYCL)
433 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL
434 #elif defined(KOKKOS_ENABLE_OPENACC)
435 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC
436 #elif defined(KOKKOS_ENABLE_OPENMPTARGET)
437 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET
438 #elif defined(KOKKOS_ENABLE_OPENMP)
439 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP
440 #elif defined(KOKKOS_ENABLE_THREADS)
441 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS
442 #elif defined(KOKKOS_ENABLE_HPX)
443 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX
444 #else
445 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL
446 #endif
447 
448 //----------------------------------------------------------------------------
449 
450 // Remove surrounding parentheses if present
451 #define KOKKOS_IMPL_STRIP_PARENS(X) KOKKOS_IMPL_ESC(KOKKOS_IMPL_ISH X)
452 #define KOKKOS_IMPL_ISH(...) KOKKOS_IMPL_ISH __VA_ARGS__
453 #define KOKKOS_IMPL_ESC(...) KOKKOS_IMPL_ESC_(__VA_ARGS__)
454 #define KOKKOS_IMPL_ESC_(...) KOKKOS_IMPL_VAN_##__VA_ARGS__
455 #define KOKKOS_IMPL_VAN_KOKKOS_IMPL_ISH
456 
457 #if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_NVHPC)
458 #include <nv/target>
459 #define KOKKOS_IF_ON_DEVICE(CODE) NV_IF_TARGET(NV_IS_DEVICE, CODE)
460 #define KOKKOS_IF_ON_HOST(CODE) NV_IF_TARGET(NV_IS_HOST, CODE)
461 #endif
462 
463 #ifdef KOKKOS_ENABLE_OPENMPTARGET
464 #ifdef KOKKOS_COMPILER_NVHPC
465 #define KOKKOS_IF_ON_DEVICE(CODE) \
466  if (__builtin_is_device_code()) { \
467  KOKKOS_IMPL_STRIP_PARENS(CODE) \
468  }
469 #define KOKKOS_IF_ON_HOST(CODE) \
470  if (!__builtin_is_device_code()) { \
471  KOKKOS_IMPL_STRIP_PARENS(CODE) \
472  }
473 #else
474 // Base function.
475 static constexpr bool kokkos_omp_on_host() { return true; }
476 
477 #pragma omp begin declare variant match(device = {kind(host)})
478 static constexpr bool kokkos_omp_on_host() { return true; }
479 #pragma omp end declare variant
480 
481 #pragma omp begin declare variant match(device = {kind(nohost)})
482 static constexpr bool kokkos_omp_on_host() { return false; }
483 #pragma omp end declare variant
484 
485 #define KOKKOS_IF_ON_DEVICE(CODE) \
486  if constexpr (!kokkos_omp_on_host()) { \
487  KOKKOS_IMPL_STRIP_PARENS(CODE) \
488  }
489 #define KOKKOS_IF_ON_HOST(CODE) \
490  if constexpr (kokkos_omp_on_host()) { \
491  KOKKOS_IMPL_STRIP_PARENS(CODE) \
492  }
493 #endif
494 #endif
495 
496 #ifdef KOKKOS_ENABLE_OPENACC
497 #ifdef KOKKOS_COMPILER_NVHPC
498 #define KOKKOS_IF_ON_DEVICE(CODE) \
499  if (__builtin_is_device_code()) { \
500  KOKKOS_IMPL_STRIP_PARENS(CODE) \
501  }
502 #define KOKKOS_IF_ON_HOST(CODE) \
503  if (!__builtin_is_device_code()) { \
504  KOKKOS_IMPL_STRIP_PARENS(CODE) \
505  }
506 #else
507 #include <openacc.h>
508 // FIXME_OPENACC acc_on_device is a non-constexpr function
509 #define KOKKOS_IF_ON_DEVICE(CODE) \
510  if constexpr (acc_on_device(acc_device_not_host)) { \
511  KOKKOS_IMPL_STRIP_PARENS(CODE) \
512  }
513 #define KOKKOS_IF_ON_HOST(CODE) \
514  if constexpr (acc_on_device(acc_device_host)) { \
515  KOKKOS_IMPL_STRIP_PARENS(CODE) \
516  }
517 #endif
518 #endif
519 
520 #if !defined(KOKKOS_IF_ON_HOST) && !defined(KOKKOS_IF_ON_DEVICE)
521 #if (defined(KOKKOS_ENABLE_CUDA) && defined(__CUDA_ARCH__)) || \
522  (defined(KOKKOS_ENABLE_HIP) && defined(__HIP_DEVICE_COMPILE__)) || \
523  (defined(KOKKOS_ENABLE_SYCL) && defined(__SYCL_DEVICE_ONLY__))
524 #define KOKKOS_IF_ON_DEVICE(CODE) \
525  { KOKKOS_IMPL_STRIP_PARENS(CODE) }
526 #define KOKKOS_IF_ON_HOST(CODE) \
527  {}
528 #else
529 #define KOKKOS_IF_ON_DEVICE(CODE) \
530  {}
531 #define KOKKOS_IF_ON_HOST(CODE) \
532  { KOKKOS_IMPL_STRIP_PARENS(CODE) }
533 #endif
534 #endif
535 
536 //----------------------------------------------------------------------------
537 // If compiling with CUDA, we must use relocatable device code to enable the
538 // task policy.
539 
540 #if defined(KOKKOS_ENABLE_CUDA)
541 #if defined(KOKKOS_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE)
542 #define KOKKOS_ENABLE_TASKDAG
543 #endif
544 // FIXME_SYCL Tasks not implemented
545 #elif !defined(KOKKOS_ENABLE_HIP) && !defined(KOKKOS_ENABLE_SYCL)
546 #define KOKKOS_ENABLE_TASKDAG
547 #endif
548 
549 #if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_ENABLE_DEPRECATED_CODE_4)
550 #define KOKKOS_ENABLE_CUDA_LDG_INTRINSIC
551 #endif
552 
553 #define KOKKOS_INVALID_INDEX (~std::size_t(0))
554 
555 #define KOKKOS_IMPL_CTOR_DEFAULT_ARG KOKKOS_INVALID_INDEX
556 
557 // Guard intel compiler version 19 and older
558 // intel error #2651: attribute does not apply to any entity
559 // using <deprecated_type> KOKKOS_DEPRECATED = ...
560 #if defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS) && !defined(__NVCC__) && \
561  (!defined(KOKKOS_COMPILER_INTEL) || KOKKOS_COMPILER_INTEL >= 2021)
562 #define KOKKOS_DEPRECATED [[deprecated]]
563 #define KOKKOS_DEPRECATED_WITH_COMMENT(comment) [[deprecated(comment)]]
564 #else
565 #define KOKKOS_DEPRECATED
566 #define KOKKOS_DEPRECATED_WITH_COMMENT(comment)
567 #endif
568 
569 #define KOKKOS_IMPL_STRINGIFY(x) #x
570 #define KOKKOS_IMPL_TOSTRING(x) KOKKOS_IMPL_STRINGIFY(x)
571 
572 #ifdef _MSC_VER
573 #define KOKKOS_IMPL_DO_PRAGMA(x) __pragma(x)
574 #define KOKKOS_IMPL_WARNING(desc) \
575  KOKKOS_IMPL_DO_PRAGMA(message( \
576  __FILE__ "(" KOKKOS_IMPL_TOSTRING(__LINE__) ") : warning: " #desc))
577 #else
578 #define KOKKOS_IMPL_DO_PRAGMA(x) _Pragma(#x)
579 #define KOKKOS_IMPL_WARNING(desc) KOKKOS_IMPL_DO_PRAGMA(message(#desc))
580 #endif
581 
582 // clang-format off
583 #if defined(__NVCOMPILER)
584  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
585  _Pragma("diag_suppress 1216")
586  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
587  _Pragma("diag_default 1216")
588 #elif defined(__EDG__)
589  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
590  _Pragma("warning push") \
591  _Pragma("warning disable 1478")
592  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
593  _Pragma("warning pop")
594 #elif defined(__GNUC__) || defined(__clang__)
595  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
596  _Pragma("GCC diagnostic push") \
597  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
598  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
599  _Pragma("GCC diagnostic pop")
600 #elif defined(_MSC_VER)
601  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
602  _Pragma("warning(push)") \
603  _Pragma("warning(disable: 4996)")
604  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
605  _Pragma("warning(pop)")
606 #else
607  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH()
608  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP()
609 #endif
610 // clang-format on
611 
612 #define KOKKOS_ATTRIBUTE_NODISCARD [[nodiscard]]
613 
614 #ifndef KOKKOS_ENABLE_CXX17
615 #define KOKKOS_IMPL_ATTRIBUTE_UNLIKELY [[unlikely]]
616 #else
617 #define KOKKOS_IMPL_ATTRIBUTE_UNLIKELY
618 #endif
619 
620 #if (defined(KOKKOS_COMPILER_GNU) || defined(KOKKOS_COMPILER_CLANG) || \
621  defined(KOKKOS_COMPILER_INTEL) || defined(KOKKOS_COMPILER_INTEL_LLVM) || \
622  defined(KOKKOS_COMPILER_NVHPC)) && \
623  !defined(_WIN32) && !defined(__ANDROID__)
624 #if __has_include(<execinfo.h>)
625 #define KOKKOS_IMPL_ENABLE_STACKTRACE
626 #endif
627 #define KOKKOS_IMPL_ENABLE_CXXABI
628 #endif
629 
630 // WORKAROUND for AMD aomp which apparently defines CUDA_ARCH when building for
631 // AMD GPUs with OpenMP Target ???
632 #if defined(__CUDA_ARCH__) && !defined(__CUDACC__) && \
633  !defined(KOKKOS_ENABLE_HIP) && !defined(KOKKOS_ENABLE_CUDA)
634 #undef __CUDA_ARCH__
635 #endif
636 
637 #if (defined(KOKKOS_IMPL_WINDOWS_CUDA) || defined(KOKKOS_COMPILER_MSVC)) && \
638  !defined(KOKKOS_COMPILER_CLANG)
639 // MSVC (as of 16.5.5 at least) does not do empty base class optimization by
640 // default when there are multiple bases, even though the standard requires it
641 // for standard layout types.
642 #define KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION __declspec(empty_bases)
643 #else
644 #define KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION
645 #endif
646 
647 #endif // #ifndef KOKKOS_MACROS_HPP