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