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