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