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