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(_WIN32)
202 #define KOKKOS_RESTRICT __restrict
203 #else
204 #define KOKKOS_RESTRICT __restrict__
205 #endif
206 
207 #ifndef KOKKOS_IMPL_ALIGN_PTR
208 #if defined(_WIN32)
209 #define KOKKOS_IMPL_ALIGN_PTR(size) __declspec(align_value(size))
210 #else
211 #define KOKKOS_IMPL_ALIGN_PTR(size) __attribute__((align_value(size)))
212 #endif
213 #endif
214 
215 #if !defined(KOKKOS_ENABLE_ASM) && !defined(_WIN32)
216 #define KOKKOS_ENABLE_ASM 1
217 #endif
218 
219 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
220 #if !defined(_WIN32)
221 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
222  inline __attribute__((always_inline))
223 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
224 #else
225 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION inline
226 #endif
227 #endif
228 
229 #if defined(__MIC__)
230 // Compiling for Xeon Phi
231 #endif
232 #endif
233 
234 //----------------------------------------------------------------------------
235 // Cray compiler macros
236 
237 #if defined(KOKKOS_COMPILER_CRAYC)
238 #endif
239 
240 //----------------------------------------------------------------------------
241 // CLANG compiler macros
242 
243 #if defined(KOKKOS_COMPILER_CLANG)
244 // #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
245 // #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
246 // #define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
247 // #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
248 
249 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
250 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
251  inline __attribute__((always_inline))
252 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
253 #endif
254 
255 #if !defined(KOKKOS_IMPL_ALIGN_PTR)
256 #define KOKKOS_IMPL_ALIGN_PTR(size) __attribute__((aligned(size)))
257 #endif
258 
259 #endif
260 
261 //----------------------------------------------------------------------------
262 // GNU Compiler macros
263 
264 #if defined(KOKKOS_COMPILER_GNU)
265 // #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
266 // #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
267 // #define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
268 // #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
269 
270 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
271 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
272  inline __attribute__((always_inline))
273 #define KOKKOS_IMPL_HOST_FORCEINLINE __attribute__((always_inline))
274 #endif
275 
276 #define KOKKOS_RESTRICT __restrict__
277 
278 #if !defined(KOKKOS_ENABLE_ASM) && !defined(__PGIC__) && \
279  (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || \
280  defined(__x86_64__) || defined(__PPC64__))
281 #define KOKKOS_ENABLE_ASM 1
282 #endif
283 #endif
284 
285 //----------------------------------------------------------------------------
286 
287 #if defined(KOKKOS_COMPILER_NVHPC)
288 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
289 #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
290 // #define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
291 #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
292 #endif
293 
294 //----------------------------------------------------------------------------
295 
296 #if defined(KOKKOS_COMPILER_NVCC)
297 #if defined(__CUDA_ARCH__)
298 #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
299 #endif
300 #endif
301 
302 //----------------------------------------------------------------------------
303 // Define function marking macros if compiler specific macros are undefined:
304 
305 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION)
306 #define KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION inline
307 #endif
308 
309 #if !defined(KOKKOS_IMPL_HOST_FORCEINLINE)
310 #define KOKKOS_IMPL_HOST_FORCEINLINE inline
311 #endif
312 
313 #if !defined(KOKKOS_IMPL_FORCEINLINE_FUNCTION)
314 #define KOKKOS_IMPL_FORCEINLINE_FUNCTION KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION
315 #endif
316 
317 #if !defined(KOKKOS_IMPL_FORCEINLINE)
318 #define KOKKOS_IMPL_FORCEINLINE KOKKOS_IMPL_HOST_FORCEINLINE
319 #endif
320 
321 #if !defined(KOKKOS_IMPL_INLINE_FUNCTION)
322 #define KOKKOS_IMPL_INLINE_FUNCTION inline
323 #endif
324 
325 #if !defined(KOKKOS_IMPL_FUNCTION)
326 #define KOKKOS_IMPL_FUNCTION
327 #endif
328 
329 #if !defined(KOKKOS_INLINE_FUNCTION_DELETED)
330 #define KOKKOS_INLINE_FUNCTION_DELETED
331 #endif
332 
333 #if !defined(KOKKOS_DEFAULTED_FUNCTION)
334 #define KOKKOS_DEFAULTED_FUNCTION
335 #endif
336 
337 #if !defined(KOKKOS_DEDUCTION_GUIDE)
338 #define KOKKOS_DEDUCTION_GUIDE
339 #endif
340 
341 #if !defined(KOKKOS_IMPL_HOST_FUNCTION)
342 #define KOKKOS_IMPL_HOST_FUNCTION
343 #endif
344 
345 #if !defined(KOKKOS_IMPL_DEVICE_FUNCTION)
346 #define KOKKOS_IMPL_DEVICE_FUNCTION
347 #endif
348 
349 // FIXME_OPENACC FIXME_OPENMPTARGET
350 // Move to setup files once there is more content
351 // clang-format off
352 #if defined(KOKKOS_ENABLE_OPENACC)
353 #define KOKKOS_IMPL_RELOCATABLE_FUNCTION @"KOKKOS_RELOCATABLE_FUNCTION is not supported for the OpenACC backend"
354 #endif
355 #if defined(KOKKOS_ENABLE_OPENMPTARGET)
356 #define KOKKOS_IMPL_RELOCATABLE_FUNCTION @"KOKKOS_RELOCATABLE_FUNCTION is not supported for the OpenMPTarget backend"
357 #endif
358 // clang-format on
359 
360 #if !defined(KOKKOS_IMPL_RELOCATABLE_FUNCTION)
361 #define KOKKOS_IMPL_RELOCATABLE_FUNCTION
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 #define KOKKOS_RELOCATABLE_FUNCTION \
377  KOKKOS_IMPL_RELOCATABLE_FUNCTION \
378  __attribute__((annotate("KOKKOS_RELOCATABLE_FUNCTION")))
379 #else
380 #define KOKKOS_FUNCTION KOKKOS_IMPL_FUNCTION
381 #define KOKKOS_INLINE_FUNCTION KOKKOS_IMPL_INLINE_FUNCTION
382 #define KOKKOS_FORCEINLINE_FUNCTION KOKKOS_IMPL_FORCEINLINE_FUNCTION
383 #define KOKKOS_RELOCATABLE_FUNCTION KOKKOS_IMPL_RELOCATABLE_FUNCTION
384 #endif
385 
386 //----------------------------------------------------------------------------
387 // Define empty macro for restrict if necessary:
388 
389 #if !defined(KOKKOS_RESTRICT)
390 #define KOKKOS_RESTRICT
391 #endif
392 
393 //----------------------------------------------------------------------------
394 // Define Macro for alignment:
395 
396 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
397 #ifndef KOKKOS_MEMORY_ALIGNMENT
398 #define KOKKOS_IMPL_MEMORY_ALIGNMENT 64
399 #ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
400 #define KOKKOS_MEMORY_ALIGNMENT \
401  [] { \
402  int memory_alignment \
403  [[deprecated("KOKKOS_MEMORY_ALIGNMENT macro is deprecated")]] = \
404  KOKKOS_IMPL_MEMORY_ALIGNMENT; \
405  return memory_alignment; \
406  }();
407 #else
408 #define KOKKOS_MEMORY_ALIGNMENT KOKKOS_IMPL_MEMORY_ALIGNMENT
409 #endif
410 #else
411 #define KOKKOS_IMPL_MEMORY_ALIGNMENT KOKKOS_MEMORY_ALIGNMENT
412 #endif
413 #else // KOKKOS_ENABLE_DEPRECATED_CODE_4
414 #ifdef KOKKOS_MEMORY_ALIGNMENT
415 static_assert(false,
416  "External definition of KOKKOS_MEMORY_ALIGNMENT is not allowed");
417 #endif
418 #endif
419 
420 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
421 #ifndef KOKKOS_MEMORY_ALIGNMENT_THRESHOLD
422 #define KOKKOS_IMPL_MEMORY_ALIGNMENT_THRESHOLD 1
423 #ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
424 #define KOKKOS_MEMORY_ALIGNMENT_THRESHOLD \
425  [] { \
426  int memory_alignment [[deprecated( \
427  "KOKKOS_MEMORY_ALIGNMENT_THRESHOLD macro is deprecated")]] = \
428  KOKKOS_IMPL_MEMORY_ALIGNMENT_THRESHOLD; \
429  return memory_alignment; \
430  }();
431 #else
432 #define KOKKOS_MEMORY_ALIGNMENT_THRESHOLD KOKKOS_IMPL_MEMORY_ALIGNMENT_THRESHOLD
433 #endif
434 #else
435 #define KOKKOS_IMPL_MEMORY_ALIGNMENT_THRESHOLD KOKKOS_MEMORY_ALIGNMENT_THRESHOLD
436 #endif
437 #else // KOKKOS_ENABLE_DEPRECATED_CODE_4
438 #ifdef KOKKOS_MEMORY_ALIGNMENT_THRESHOLD
439 static_assert(
440  false,
441  "External definition of KOKKOS_MEMORY_ALIGNMENT_THRESHOLD is not allowed");
442 #endif
443 #endif
444 
445 #if !defined(KOKKOS_IMPL_ALIGN_PTR)
446 #define KOKKOS_IMPL_ALIGN_PTR(size) /* */
447 #endif
448 
449 //----------------------------------------------------------------------------
450 // Determine the default execution space for parallel dispatch.
451 // There is zero or one default execution space specified.
452 
453 #if 1 < ((defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA) ? 1 : 0) + \
454  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP) ? 1 : 0) + \
455  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL) ? 1 : 0) + \
456  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC) ? 1 : 0) + \
457  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET) ? 1 : 0) + \
458  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP) ? 1 : 0) + \
459  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS) ? 1 : 0) + \
460  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX) ? 1 : 0) + \
461  (defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL) ? 1 : 0))
462 #error "More than one KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_* specified."
463 #endif
464 
465 // If default is not specified then chose from enabled execution spaces.
466 // Priority: CUDA, HIP, SYCL, OPENACC, OPENMPTARGET, OPENMP, THREADS, HPX,
467 // SERIAL
468 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
469 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
470 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
471 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
472 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
473 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
474 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
475 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
476 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
477 #elif defined(KOKKOS_ENABLE_CUDA)
478 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA
479 #elif defined(KOKKOS_ENABLE_HIP)
480 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP
481 #elif defined(KOKKOS_ENABLE_SYCL)
482 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL
483 #elif defined(KOKKOS_ENABLE_OPENACC)
484 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC
485 #elif defined(KOKKOS_ENABLE_OPENMPTARGET)
486 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET
487 #elif defined(KOKKOS_ENABLE_OPENMP)
488 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP
489 #elif defined(KOKKOS_ENABLE_THREADS)
490 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS
491 #elif defined(KOKKOS_ENABLE_HPX)
492 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX
493 #else
494 #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL
495 #endif
496 
497 //----------------------------------------------------------------------------
498 
499 // Remove surrounding parentheses if present
500 #define KOKKOS_IMPL_STRIP_PARENS(X) KOKKOS_IMPL_ESC(KOKKOS_IMPL_ISH X)
501 #define KOKKOS_IMPL_ISH(...) KOKKOS_IMPL_ISH __VA_ARGS__
502 #define KOKKOS_IMPL_ESC(...) KOKKOS_IMPL_ESC_(__VA_ARGS__)
503 #define KOKKOS_IMPL_ESC_(...) KOKKOS_IMPL_VAN_##__VA_ARGS__
504 #define KOKKOS_IMPL_VAN_KOKKOS_IMPL_ISH
505 
506 #if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_NVHPC)
507 #include <nv/target>
508 #define KOKKOS_IF_ON_DEVICE(CODE) NV_IF_TARGET(NV_IS_DEVICE, CODE)
509 #define KOKKOS_IF_ON_HOST(CODE) NV_IF_TARGET(NV_IS_HOST, CODE)
510 #endif
511 
512 #ifdef KOKKOS_ENABLE_OPENMPTARGET
513 #ifdef KOKKOS_COMPILER_NVHPC
514 #define KOKKOS_IF_ON_DEVICE(CODE) \
515  if (__builtin_is_device_code()) { \
516  KOKKOS_IMPL_STRIP_PARENS(CODE) \
517  }
518 #define KOKKOS_IF_ON_HOST(CODE) \
519  if (!__builtin_is_device_code()) { \
520  KOKKOS_IMPL_STRIP_PARENS(CODE) \
521  }
522 #else
523 // Base function.
524 static constexpr bool kokkos_omp_on_host() { return true; }
525 
526 #pragma omp begin declare variant match(device = {kind(host)})
527 static constexpr bool kokkos_omp_on_host() { return true; }
528 #pragma omp end declare variant
529 
530 #pragma omp begin declare variant match(device = {kind(nohost)})
531 static constexpr bool kokkos_omp_on_host() { return false; }
532 #pragma omp end declare variant
533 
534 #define KOKKOS_IF_ON_DEVICE(CODE) \
535  if constexpr (!kokkos_omp_on_host()) { \
536  KOKKOS_IMPL_STRIP_PARENS(CODE) \
537  }
538 #define KOKKOS_IF_ON_HOST(CODE) \
539  if constexpr (kokkos_omp_on_host()) { \
540  KOKKOS_IMPL_STRIP_PARENS(CODE) \
541  }
542 #endif
543 #endif
544 
545 #ifdef KOKKOS_ENABLE_OPENACC
546 #ifdef KOKKOS_COMPILER_NVHPC
547 #define KOKKOS_IF_ON_DEVICE(CODE) \
548  if (__builtin_is_device_code()) { \
549  KOKKOS_IMPL_STRIP_PARENS(CODE) \
550  }
551 #define KOKKOS_IF_ON_HOST(CODE) \
552  if (!__builtin_is_device_code()) { \
553  KOKKOS_IMPL_STRIP_PARENS(CODE) \
554  }
555 #else
556 #include <openacc.h>
557 // FIXME_OPENACC acc_on_device is a non-constexpr function
558 #define KOKKOS_IF_ON_DEVICE(CODE) \
559  if constexpr (acc_on_device(acc_device_not_host)) { \
560  KOKKOS_IMPL_STRIP_PARENS(CODE) \
561  }
562 #define KOKKOS_IF_ON_HOST(CODE) \
563  if constexpr (acc_on_device(acc_device_host)) { \
564  KOKKOS_IMPL_STRIP_PARENS(CODE) \
565  }
566 #endif
567 #endif
568 
569 #if !defined(KOKKOS_IF_ON_HOST) && !defined(KOKKOS_IF_ON_DEVICE)
570 #if (defined(KOKKOS_ENABLE_CUDA) && defined(__CUDA_ARCH__)) || \
571  (defined(KOKKOS_ENABLE_HIP) && defined(__HIP_DEVICE_COMPILE__)) || \
572  (defined(KOKKOS_ENABLE_SYCL) && defined(__SYCL_DEVICE_ONLY__))
573 #define KOKKOS_IF_ON_DEVICE(CODE) \
574  { KOKKOS_IMPL_STRIP_PARENS(CODE) }
575 #define KOKKOS_IF_ON_HOST(CODE) \
576  {}
577 #else
578 #define KOKKOS_IF_ON_DEVICE(CODE) \
579  {}
580 #define KOKKOS_IF_ON_HOST(CODE) \
581  { KOKKOS_IMPL_STRIP_PARENS(CODE) }
582 #endif
583 #endif
584 
585 //----------------------------------------------------------------------------
586 // If compiling with CUDA, we must use relocatable device code to enable the
587 // task policy.
588 
589 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
590 #if defined(KOKKOS_ENABLE_CUDA)
591 #if defined(KOKKOS_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE)
592 #define KOKKOS_ENABLE_TASKDAG
593 #endif
594 // FIXME_SYCL Tasks not implemented
595 #elif !defined(KOKKOS_ENABLE_HIP) && !defined(KOKKOS_ENABLE_SYCL) && \
596  !defined(KOKKOS_ENABLE_OPENMPTARGET)
597 #define KOKKOS_ENABLE_TASKDAG
598 #endif
599 #endif
600 
601 #if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_ENABLE_DEPRECATED_CODE_4)
602 #define KOKKOS_ENABLE_CUDA_LDG_INTRINSIC
603 #endif
604 
605 #define KOKKOS_INVALID_INDEX (~std::size_t(0))
606 
607 #define KOKKOS_IMPL_CTOR_DEFAULT_ARG KOKKOS_INVALID_INDEX
608 
609 // Guard intel compiler version 19 and older
610 // intel error #2651: attribute does not apply to any entity
611 // using <deprecated_type> KOKKOS_DEPRECATED = ...
612 #if defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS) && !defined(__NVCC__)
613 #define KOKKOS_DEPRECATED [[deprecated]]
614 #define KOKKOS_DEPRECATED_WITH_COMMENT(comment) [[deprecated(comment)]]
615 #else
616 #define KOKKOS_DEPRECATED
617 #define KOKKOS_DEPRECATED_WITH_COMMENT(comment)
618 #endif
619 
620 #define KOKKOS_IMPL_STRINGIFY(x) #x
621 #define KOKKOS_IMPL_TOSTRING(x) KOKKOS_IMPL_STRINGIFY(x)
622 
623 #ifdef _MSC_VER
624 #define KOKKOS_IMPL_DO_PRAGMA(x) __pragma(x)
625 #define KOKKOS_IMPL_WARNING(desc) \
626  KOKKOS_IMPL_DO_PRAGMA(message( \
627  __FILE__ "(" KOKKOS_IMPL_TOSTRING(__LINE__) ") : warning: " #desc))
628 #else
629 #define KOKKOS_IMPL_DO_PRAGMA(x) _Pragma(#x)
630 #define KOKKOS_IMPL_WARNING(desc) KOKKOS_IMPL_DO_PRAGMA(message(#desc))
631 #endif
632 
633 // clang-format off
634 #if defined(__NVCOMPILER)
635  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
636  _Pragma("diag_suppress 1216") \
637  _Pragma("diag_suppress deprecated_entity_with_custom_message")
638  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
639  _Pragma("diag_default 1216") \
640  _Pragma("diag_suppress deprecated_entity_with_custom_message")
641 #elif defined(__EDG__)
642  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
643  _Pragma("warning push") \
644  _Pragma("warning disable 1478")
645  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
646  _Pragma("warning pop")
647 #elif defined(__GNUC__) || defined(__clang__)
648  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
649  _Pragma("GCC diagnostic push") \
650  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
651  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
652  _Pragma("GCC diagnostic pop")
653 #elif defined(_MSC_VER)
654  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH() \
655  _Pragma("warning(push)") \
656  _Pragma("warning(disable: 4996)")
657  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP() \
658  _Pragma("warning(pop)")
659 #else
660  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH()
661  #define KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP()
662 #endif
663 
664 #if defined(__NVCOMPILER)
665 #define KOKKOS_IMPL_DISABLE_UNREACHABLE_WARNINGS_PUSH() \
666  _Pragma("diag_suppress code_is_unreachable") \
667  _Pragma("diag_suppress initialization_not_reachable")
668 #define KOKKOS_IMPL_DISABLE_UNREACHABLE_WARNINGS_POP() \
669  _Pragma("diag_default code_is_unreachable") \
670  _Pragma("diag_default initialization_not_reachable")
671 #else
672 #define KOKKOS_IMPL_DISABLE_UNREACHABLE_WARNINGS_PUSH()
673 #define KOKKOS_IMPL_DISABLE_UNREACHABLE_WARNINGS_POP()
674 #endif
675 // clang-format on
676 
677 #define KOKKOS_ATTRIBUTE_NODISCARD [[nodiscard]]
678 
679 #ifndef KOKKOS_ENABLE_CXX17
680 #define KOKKOS_IMPL_ATTRIBUTE_UNLIKELY [[unlikely]]
681 #else
682 #define KOKKOS_IMPL_ATTRIBUTE_UNLIKELY
683 #endif
684 
685 #if (defined(KOKKOS_COMPILER_GNU) || defined(KOKKOS_COMPILER_CLANG) || \
686  defined(KOKKOS_COMPILER_INTEL_LLVM) || defined(KOKKOS_COMPILER_NVHPC)) && \
687  !defined(_WIN32) && !defined(__ANDROID__)
688 #if __has_include(<execinfo.h>)
689 #define KOKKOS_IMPL_ENABLE_STACKTRACE
690 #endif
691 #define KOKKOS_IMPL_ENABLE_CXXABI
692 #endif
693 
694 // WORKAROUND for AMD aomp which apparently defines CUDA_ARCH when building for
695 // AMD GPUs with OpenMP Target ???
696 #if defined(__CUDA_ARCH__) && !defined(__CUDACC__) && \
697  !defined(KOKKOS_ENABLE_HIP) && !defined(KOKKOS_ENABLE_CUDA)
698 #undef __CUDA_ARCH__
699 #endif
700 
701 #if (defined(KOKKOS_IMPL_WINDOWS_CUDA) || defined(KOKKOS_COMPILER_MSVC)) && \
702  !defined(KOKKOS_COMPILER_CLANG)
703 // MSVC (as of 16.5.5 at least) does not do empty base class optimization by
704 // default when there are multiple bases, even though the standard requires it
705 // for standard layout types.
706 #define KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION __declspec(empty_bases)
707 #else
708 #define KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION
709 #endif
710 
711 #endif // #ifndef KOKKOS_MACROS_HPP