Kokkos Core Kernels Package  Version of the Day
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 #endif
59 
60 //----------------------------------------------------------------------------
90 //----------------------------------------------------------------------------
91 
92 #if !defined(KOKKOS_ENABLE_THREADS) && !defined(KOKKOS_ENABLE_CUDA) && \
93  !defined(KOKKOS_ENABLE_OPENMP) && !defined(KOKKOS_ENABLE_HPX) && \
94  !defined(KOKKOS_ENABLE_OPENMPTARGET) && !defined(KOKKOS_ENABLE_HIP) && \
95  !defined(KOKKOS_ENABLE_SYCL)
96 #define KOKKOS_INTERNAL_NOT_PARALLEL
97 #endif
98 
99 #define KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA
100 
101 #include <KokkosCore_Config_SetupBackend.hpp>
102 
103 //----------------------------------------------------------------------------
104 // Mapping compiler built-ins to KOKKOS_COMPILER_*** macros
105 
106 #if defined(__NVCC__)
107 // NVIDIA compiler is being used.
108 // Code is parsed and separated into host and device code.
109 // Host code is compiled again with another compiler.
110 // Device code is compile to 'ptx'.
111 // NOTE: There is no __CUDACC_VER_PATCH__ officially, its __CUDACC_VER_BUILD__
112 // which does have more than one digit (potentially undefined number of them).
113 // This macro definition is in line with our other compiler defs
114 #define KOKKOS_COMPILER_NVCC \
115  __CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__ * 10
116 #endif // #if defined( __NVCC__ )
117 
118 #if !defined(KOKKOS_LAMBDA)
119 #define KOKKOS_LAMBDA [=]
120 #endif
121 
122 #if !defined(KOKKOS_CLASS_LAMBDA)
123 #define KOKKOS_CLASS_LAMBDA [ =, *this ]
124 #endif
125 
126 //#if !defined( __CUDA_ARCH__ ) // Not compiling Cuda code to 'ptx'.
127 
128 // Intel compiler for host code.
129 
130 #if defined(__INTEL_COMPILER)
131 #define KOKKOS_COMPILER_INTEL __INTEL_COMPILER
132 #elif defined(__INTEL_LLVM_COMPILER)
133 #define KOKKOS_COMPILER_INTEL __INTEL_LLVM_COMPILER
134 #elif defined(__ICC)
135 // Old define
136 #define KOKKOS_COMPILER_INTEL __ICC
137 #elif defined(__ECC)
138 // Very old define
139 #define KOKKOS_COMPILER_INTEL __ECC
140 #endif
141 
142 // CRAY compiler for host code
143 #if defined(_CRAYC)
144 #define KOKKOS_COMPILER_CRAYC _CRAYC
145 #endif
146 
147 #if defined(__APPLE_CC__)
148 #define KOKKOS_COMPILER_APPLECC __APPLE_CC__
149 #endif
150 
151 #if defined(__clang__) && !defined(KOKKOS_COMPILER_INTEL)
152 #define KOKKOS_COMPILER_CLANG \
153  __clang_major__ * 100 + __clang_minor__ * 10 + __clang_patchlevel__
154 #endif
155 
156 #if !defined(__clang__) && !defined(KOKKOS_COMPILER_INTEL) && defined(__GNUC__)
157 #define KOKKOS_COMPILER_GNU \
158  __GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__
159 
160 #if (530 > KOKKOS_COMPILER_GNU)
161 #error "Compiling with GCC version earlier than 5.3.0 is not supported."
162 #endif
163 #endif
164 
165 #if defined(__NVCOMPILER)
166 #define KOKKOS_COMPILER_NVHPC \
167  __NVCOMPILER_MAJOR__ * 100 + __NVCOMPILER_MINOR__ * 10 + \
168  __NVCOMPILER_PATCHLEVEL__
169 #endif
170 
171 #if defined(_MSC_VER) && !defined(KOKKOS_COMPILER_INTEL)
172 #define KOKKOS_COMPILER_MSVC _MSC_VER
173 #endif
174 
175 #if defined(_OPENMP)
176 // Compiling with OpenMP.
177 // The value of _OPENMP is an integer value YYYYMM
178 // where YYYY and MM are the year and month designation
179 // of the supported OpenMP API version.
180 #endif // #if defined( _OPENMP )
181 
182 //----------------------------------------------------------------------------
183 // Intel compiler macros
184 
185 #if defined(KOKKOS_COMPILER_INTEL)
186 // FIXME_SYCL
187 #if !defined(KOKKOS_ENABLE_SYCL)
188 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
189 #define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
190 #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
191 #endif
192 
193 // FIXME_SYCL
194 #if !defined(KOKKOS_ENABLE_SYCL)
195 #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
196 #endif
197 
198 #if !defined(KOKKOS_MEMORY_ALIGNMENT)
199 #define KOKKOS_MEMORY_ALIGNMENT 64
200 #endif
201 
202 #if defined(_WIN32)
203 #define KOKKOS_RESTRICT __restrict
204 #else
205 #define KOKKOS_RESTRICT __restrict__
206 #endif
207 
208 #ifndef KOKKOS_IMPL_ALIGN_PTR
209 #if defined(_WIN32)
210 #define KOKKOS_IMPL_ALIGN_PTR(size) __declspec(align_value(size))
211 #else
212 #define KOKKOS_IMPL_ALIGN_PTR(size) __attribute__((align_value(size)))
213 #endif
214 #endif
215 
216 #if (1900 > KOKKOS_COMPILER_INTEL)
217 #error "Compiling with Intel version earlier than 19.0.5 is not supported."
218 #endif
219 
220 #if !defined(KOKKOS_ENABLE_ASM) && !defined(_WIN32)
221 #define KOKKOS_ENABLE_ASM 1
222 #endif
223 
224 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
225 #if !defined(_WIN32)
226 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
227  inline __attribute__((always_inline))
228 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
229 #else
230 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION inline
231 #endif
232 #endif
233 
234 #if defined(KOKKOS_ARCH_AVX512MIC)
235 #define KOKKOS_ENABLE_RFO_PREFETCH 1
236 #endif
237 
238 #if defined(__MIC__)
239 // Compiling for Xeon Phi
240 #endif
241 #endif
242 
243 //----------------------------------------------------------------------------
244 // Cray compiler macros
245 
246 #if defined(KOKKOS_COMPILER_CRAYC)
247 #endif
248 
249 //----------------------------------------------------------------------------
250 // CLANG compiler macros
251 
252 #if defined(KOKKOS_COMPILER_CLANG)
253 //#define KOKKOS_ENABLE_PRAGMA_UNROLL 1
254 //#define KOKKOS_ENABLE_PRAGMA_IVDEP 1
255 //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
256 //#define KOKKOS_ENABLE_PRAGMA_VECTOR 1
257 
258 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
259 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
260  inline __attribute__((always_inline))
261 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
262 #endif
263 
264 #if !defined(KOKKOS_IMPL_ALIGN_PTR)
265 #define KOKKOS_IMPL_ALIGN_PTR(size) __attribute__((aligned(size)))
266 #endif
267 
268 #endif
269 
270 //----------------------------------------------------------------------------
271 // GNU Compiler macros
272 
273 #if defined(KOKKOS_COMPILER_GNU)
274 //#define KOKKOS_ENABLE_PRAGMA_UNROLL 1
275 //#define KOKKOS_ENABLE_PRAGMA_IVDEP 1
276 //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
277 //#define KOKKOS_ENABLE_PRAGMA_VECTOR 1
278 
279 #if defined(KOKKOS_ARCH_AVX512MIC)
280 #define KOKKOS_ENABLE_RFO_PREFETCH 1
281 #endif
282 
283 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
284 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
285  inline __attribute__((always_inline))
286 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
287 #endif
288 
289 #define KOKKOS_RESTRICT __restrict__
290 
291 #if !defined(KOKKOS_ENABLE_ASM) && !defined(__PGIC__) && \
292  (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || \
293  defined(__x86_64__) || defined(__PPC64__))
294 #define KOKKOS_ENABLE_ASM 1
295 #endif
296 #endif
297 
298 //----------------------------------------------------------------------------
299 
300 #if defined(KOKKOS_COMPILER_PGI)
301 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
302 #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
303 //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
304 #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
305 #endif
306 
307 //----------------------------------------------------------------------------
308 
309 #if defined(KOKKOS_COMPILER_NVCC)
310 #if defined(__CUDA_ARCH__)
311 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
312 #endif
313 #endif
314 
315 //----------------------------------------------------------------------------
316 // Define function marking macros if compiler specific macros are undefined:
317 
318 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
319 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION inline
320 #endif
321 
322 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE)
323 #define KOKKOS_IMPL_HOST_FORCEINLINE inline
324 #endif
325 
326 #if !defined(KOKKOS_IMPL_FORCEINLINE_FUNCTION)
327 #define KOKKOS_IMPL_FORCEINLINE_FUNCTION KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION
328 #endif
329 
330 #if !defined(KOKKOS_IMPL_FORCEINLINE)
331 #define KOKKOS_IMPL_FORCEINLINE KOKKOS_IMPL_HOST_FORCEINLINE
332 #endif
333 
334 #if !defined(KOKKOS_IMPL_INLINE_FUNCTION)
335 #define KOKKOS_IMPL_INLINE_FUNCTION inline
336 #endif
337 
338 #if !defined(KOKKOS_IMPL_FUNCTION)
339 #define KOKKOS_IMPL_FUNCTION
340 #endif
341 
342 #if !defined(KOKKOS_INLINE_FUNCTION_DELETED)
343 #define KOKKOS_INLINE_FUNCTION_DELETED
344 #endif
345 
346 #if !defined(KOKKOS_DEFAULTED_FUNCTION)
347 #define KOKKOS_DEFAULTED_FUNCTION
348 #endif
349 
350 #if !defined(KOKKOS_IMPL_HOST_FUNCTION)
351 #define KOKKOS_IMPL_HOST_FUNCTION
352 #endif
353 
354 #if !defined(KOKKOS_IMPL_DEVICE_FUNCTION)
355 #define KOKKOS_IMPL_DEVICE_FUNCTION
356 #endif
357 
358 // Temporary solution for SYCL not supporting printf in kernels.
359 // Might disappear at any point once we have found another solution.
360 #if !defined(KOKKOS_IMPL_DO_NOT_USE_PRINTF)
361 #define KOKKOS_IMPL_DO_NOT_USE_PRINTF(...) printf(__VA_ARGS__)
362 #endif
363 
364 //----------------------------------------------------------------------------
365 // Define final version of functions. This is so that clang tidy can find these
366 // macros more easily
367 #if defined(__clang_analyzer__)
368 #define KOKKOS_FUNCTION \
369  KOKKOS_IMPL_FUNCTION __attribute__((annotate("KOKKOS_FUNCTION")))
370 #define KOKKOS_INLINE_FUNCTION \
371  KOKKOS_IMPL_INLINE_FUNCTION \
372  __attribute__((annotate("KOKKOS_INLINE_FUNCTION")))
373 #define KOKKOS_FORCEINLINE_FUNCTION \
374  KOKKOS_IMPL_FORCEINLINE_FUNCTION \
375  __attribute__((annotate("KOKKOS_FORCEINLINE_FUNCTION")))
376 #else
377 #define KOKKOS_FUNCTION KOKKOS_IMPL_FUNCTION
378 #define KOKKOS_INLINE_FUNCTION KOKKOS_IMPL_INLINE_FUNCTION
379 #define KOKKOS_FORCEINLINE_FUNCTION KOKKOS_IMPL_FORCEINLINE_FUNCTION
380 #endif
381 
382 //----------------------------------------------------------------------------
383 // Define empty macro for restrict if necessary:
384 
385 #if !defined(KOKKOS_RESTRICT)
386 #define KOKKOS_RESTRICT
387 #endif
388 
389 //----------------------------------------------------------------------------
390 // Define Macro for alignment:
391 
392 #if !defined(KOKKOS_MEMORY_ALIGNMENT)
393 #define KOKKOS_MEMORY_ALIGNMENT 64
394 #endif
395 
396 #if !defined(KOKKOS_MEMORY_ALIGNMENT_THRESHOLD)
397 #define KOKKOS_MEMORY_ALIGNMENT_THRESHOLD 1
398 #endif
399 
400 #if !defined(KOKKOS_IMPL_ALIGN_PTR)
401 #define KOKKOS_IMPL_ALIGN_PTR(size) /* */
402 #endif
403 
404 //----------------------------------------------------------------------------
405 // Determine the default execution space for parallel dispatch.
406 // There is zero or one default execution space specified.
407 
408 #if 1 < ((defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA) ? 1 : 0) + \
409  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP) ? 1 : 0) + \
410  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL) ? 1 : 0) + \
411  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC) ? 1 : 0) + \
412  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET) ? 1 : 0) + \
413  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP) ? 1 : 0) + \
414  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS) ? 1 : 0) + \
415  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX) ? 1 : 0) + \
416  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL) ? 1 : 0))
417 #error "More than one KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_* specified."
418 #endif
419 
420 // If default is not specified then chose from enabled execution spaces.
421 // Priority: CUDA, HIP, SYCL, OPENACC, OPENMPTARGET, OPENMP, THREADS, HPX,
422 // SERIAL
423 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
424 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
425 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
426 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
427 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
428 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
429 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
430 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
431 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
432 #elif defined(KOKKOS_ENABLE_CUDA)
433 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA
434 #elif defined(KOKKOS_ENABLE_HIP)
435 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP
436 #elif defined(KOKKOS_ENABLE_SYCL)
437 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL
438 #elif defined(KOKKOS_ENABLE_OPENACC)
439 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC
440 #elif defined(KOKKOS_ENABLE_OPENMPTARGET)
441 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET
442 #elif defined(KOKKOS_ENABLE_OPENMP)
443 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP
444 #elif defined(KOKKOS_ENABLE_THREADS)
445 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS
446 #elif defined(KOKKOS_ENABLE_HPX)
447 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX
448 #else
449 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL
450 #endif
451 
452 //----------------------------------------------------------------------------
453 // Determine for what space the code is being compiled:
454 #if defined(KOKKOS_ENABLE_DEPRECATED_CODE_3)
455 
456 #if defined(__CUDACC__) && defined(__CUDA_ARCH__) && defined(KOKKOS_ENABLE_CUDA)
457 #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA
458 #elif defined(__SYCL_DEVICE_ONLY__) && defined(KOKKOS_ENABLE_SYCL)
459 #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_SYCL
460 #elif defined(__HIPCC__) && defined(__HIP_DEVICE_COMPILE__) && \
461  defined(KOKKOS_ENABLE_HIP)
462 #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HIP_GPU
463 #else
464 #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
465 #endif
466 
467 #endif
468 //----------------------------------------------------------------------------
469 
470 // Remove surrounding parentheses if present
471 #define KOKKOS_IMPL_STRIP_PARENS(X) KOKKOS_IMPL_ESC(KOKKOS_IMPL_ISH X)
472 #define KOKKOS_IMPL_ISH(...) KOKKOS_IMPL_ISH __VA_ARGS__
473 #define KOKKOS_IMPL_ESC(...) KOKKOS_IMPL_ESC_(__VA_ARGS__)
474 #define KOKKOS_IMPL_ESC_(...) KOKKOS_IMPL_VAN_##__VA_ARGS__
475 #define KOKKOS_IMPL_VAN_KOKKOS_IMPL_ISH
476 
477 #if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_NVHPC)
478 #include <nv/target>
479 #define KOKKOS_IF_ON_DEVICE(CODE) NV_IF_TARGET(NV_IS_DEVICE, CODE)
480 #define KOKKOS_IF_ON_HOST(CODE) NV_IF_TARGET(NV_IS_HOST, CODE)
481 #endif
482 
483 #ifdef KOKKOS_ENABLE_OPENMPTARGET
484 #ifdef KOKKOS_COMPILER_NVHPC
485 #define KOKKOS_IF_ON_DEVICE(CODE) \
486  if (__builtin_is_device_code()) { \
487  KOKKOS_IMPL_STRIP_PARENS(CODE) \
488  }
489 #define KOKKOS_IF_ON_HOST(CODE) \
490  if (!__builtin_is_device_code()) { \
491  KOKKOS_IMPL_STRIP_PARENS(CODE) \
492  }
493 #else
494 // Base function.
495 static constexpr bool kokkos_omp_on_host() { return true; }
496 
497 #pragma omp begin declare variant match(device = {kind(host)})
498 static constexpr bool kokkos_omp_on_host() { return true; }
499 #pragma omp end declare variant
500 
501 #pragma omp begin declare variant match(device = {kind(nohost)})
502 static constexpr bool kokkos_omp_on_host() { return false; }
503 #pragma omp end declare variant
504 
505 #define KOKKOS_IF_ON_DEVICE(CODE) \
506  if constexpr (!kokkos_omp_on_host()) { \
507  KOKKOS_IMPL_STRIP_PARENS(CODE) \
508  }
509 #define KOKKOS_IF_ON_HOST(CODE) \
510  if constexpr (kokkos_omp_on_host()) { \
511  KOKKOS_IMPL_STRIP_PARENS(CODE) \
512  }
513 #endif
514 #endif
515 
516 #ifdef KOKKOS_ENABLE_OPENACC
517 #ifdef KOKKOS_COMPILER_NVHPC
518 #define KOKKOS_IF_ON_DEVICE(CODE) \
519  if (__builtin_is_device_code()) { \
520  KOKKOS_IMPL_STRIP_PARENS(CODE) \
521  }
522 #define KOKKOS_IF_ON_HOST(CODE) \
523  if (!__builtin_is_device_code()) { \
524  KOKKOS_IMPL_STRIP_PARENS(CODE) \
525  }
526 #else
527 // FIXME_OPENACC acc_on_device is a non-constexpr function
528 #define KOKKOS_IF_ON_DEVICE(CODE) \
529  if constexpr (acc_on_device(acc_device_not_host)) { \
530  KOKKOS_IMPL_STRIP_PARENS(CODE) \
531  }
532 #define KOKKOS_IF_ON_HOST(CODE) \
533  if constexpr (acc_on_device(acc_device_host)) { \
534  KOKKOS_IMPL_STRIP_PARENS(CODE) \
535  }
536 #endif
537 #endif
538 
539 #if !defined(KOKKOS_IF_ON_HOST) && !defined(KOKKOS_IF_ON_DEVICE)
540 #if (defined(KOKKOS_ENABLE_CUDA) && defined(__CUDA_ARCH__)) || \
541  (defined(KOKKOS_ENABLE_HIP) && defined(__HIP_DEVICE_COMPILE__)) || \
542  (defined(KOKKOS_ENABLE_SYCL) && defined(__SYCL_DEVICE_ONLY__))
543 #define KOKKOS_IF_ON_DEVICE(CODE) \
544  { KOKKOS_IMPL_STRIP_PARENS(CODE) }
545 #define KOKKOS_IF_ON_HOST(CODE) \
546  {}
547 #else
548 #define KOKKOS_IF_ON_DEVICE(CODE) \
549  {}
550 #define KOKKOS_IF_ON_HOST(CODE) \
551  { KOKKOS_IMPL_STRIP_PARENS(CODE) }
552 #endif
553 #endif
554 
555 //----------------------------------------------------------------------------
556 // If compiling with CUDA, we must use relocatable device code to enable the
557 // task policy.
558 
559 #if defined(KOKKOS_ENABLE_CUDA)
560 #if defined(KOKKOS_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE)
561 #define KOKKOS_ENABLE_TASKDAG
562 #endif
563 // FIXME_SYCL Tasks not implemented
564 #elif !defined(KOKKOS_ENABLE_HIP) && !defined(KOKKOS_ENABLE_SYCL)
565 #define KOKKOS_ENABLE_TASKDAG
566 #endif
567 
568 #if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_ENABLE_DEPRECATED_CODE_4)
569 #define KOKKOS_ENABLE_CUDA_LDG_INTRINSIC
570 #endif
571 
572 #define KOKKOS_INVALID_INDEX (~std::size_t(0))
573 
574 #define KOKKOS_IMPL_CTOR_DEFAULT_ARG KOKKOS_INVALID_INDEX
575 
576 // Guard intel compiler version 19 and older
577 // intel error #2651: attribute does not apply to any entity
578 // using <deprecated_type> KOKKOS_DEPRECATED = ...
579 #if defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS) && !defined(__NVCC__) && \
580  (!defined(KOKKOS_COMPILER_INTEL) || KOKKOS_COMPILER_INTEL >= 2021)
581 #define KOKKOS_DEPRECATED [[deprecated]]
582 #define KOKKOS_DEPRECATED_WITH_COMMENT(comment) [[deprecated(comment)]]
583 #else
584 #define KOKKOS_DEPRECATED
585 #define KOKKOS_DEPRECATED_WITH_COMMENT(comment)
586 #endif
587 
588 #define KOKKOS_IMPL_STRINGIFY(x) #x
589 #define KOKKOS_IMPL_TOSTRING(x) KOKKOS_IMPL_STRINGIFY(x)
590 
591 #ifdef _MSC_VER
592 #define KOKKOS_IMPL_DO_PRAGMA(x) __pragma(x)
593 #define KOKKOS_IMPL_WARNING(desc) \
594  KOKKOS_IMPL_DO_PRAGMA(message( \
595  __FILE__ "(" KOKKOS_IMPL_TOSTRING(__LINE__) ") : warning: " #desc))
596 #else
597 #define KOKKOS_IMPL_DO_PRAGMA(x) _Pragma(#x)
598 #define KOKKOS_IMPL_WARNING(desc) KOKKOS_IMPL_DO_PRAGMA(message(#desc))
599 #endif
600 
601 #define KOKKOS_ATTRIBUTE_NODISCARD [[nodiscard]]
602 
603 #if (defined(KOKKOS_COMPILER_GNU) || defined(KOKKOS_COMPILER_CLANG) || \
604  defined(KOKKOS_COMPILER_INTEL) || defined(KOKKOS_COMPILER_PGI)) && \
605  !defined(_WIN32) && !defined(__ANDROID__)
606 #if __has_include(<execinfo.h>)
607 #define KOKKOS_IMPL_ENABLE_STACKTRACE
608 #endif
609 #define KOKKOS_IMPL_ENABLE_CXXABI
610 #endif
611 
612 // WORKAROUND for AMD aomp which apparently defines CUDA_ARCH when building for
613 // AMD GPUs with OpenMP Target ???
614 #if defined(__CUDA_ARCH__) && !defined(__CUDACC__) && \
615  !defined(KOKKOS_ENABLE_HIP) && !defined(KOKKOS_ENABLE_CUDA)
616 #undef __CUDA_ARCH__
617 #endif
618 
619 #if (defined(KOKKOS_IMPL_WINDOWS_CUDA) || defined(KOKKOS_COMPILER_MSVC)) && \
620  !defined(KOKKOS_COMPILER_CLANG)
621 // MSVC (as of 16.5.5 at least) does not do empty base class optimization by
622 // default when there are multiple bases, even though the standard requires it
623 // for standard layout types.
624 #define KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION __declspec(empty_bases)
625 #else
626 #define KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION
627 #endif
628 
629 #endif // #ifndef KOKKOS_MACROS_HPP