Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AMReX_GpuQualifiers.H
Go to the documentation of this file.
1#ifndef AMREX_GPU_QUALIFIERS_H_
2#define AMREX_GPU_QUALIFIERS_H_
3#include <AMReX_Config.H>
4
5#if defined(AMREX_USE_GPU) && !defined(AMREX_USE_SYCL)
6
7#if defined(AMREX_USE_HIP)
8#include <hip/hip_runtime.h>
9#endif
10
11#if defined(AMREX_USE_CUDA) && (defined(AMREX_CXX_PGI) || defined(AMREX_CXX_NVHPC))
12#include <nv/target>
13#define AMREX_IF_ON_DEVICE(CODE) NV_IF_TARGET(NV_IS_DEVICE, CODE)
14#define AMREX_IF_ON_HOST(CODE) NV_IF_TARGET(NV_IS_HOST, CODE)
15#endif
16
17#define AMREX_GPU_HOST __host__
18#define AMREX_GPU_DEVICE __device__
19#define AMREX_GPU_GLOBAL __global__
20#define AMREX_GPU_HOST_DEVICE __host__ __device__
21#define AMREX_GPU_CONSTANT __constant__
22
23#define AMREX_GPU_MANAGED __managed__
24#define AMREX_GPU_DEVICE_MANAGED __device__ __managed__
25
26#else
27
28#define AMREX_GPU_HOST
29#define AMREX_GPU_DEVICE
30#define AMREX_GPU_GLOBAL
31#define AMREX_GPU_HOST_DEVICE
32#define AMREX_GPU_CONSTANT
33#define AMREX_GPU_MANAGED
34#define AMREX_GPU_DEVICE_MANAGED
35
36#endif
37
38#define AMREX_DEVICE_COMPILE (__CUDA_ARCH__ || __HIP_DEVICE_COMPILE__ || __SYCL_DEVICE_ONLY__)
39
40// Remove surrounding parentheses if present
41#define AMREX_IMPL_STRIP_PARENS(X) AMREX_IMPL_ESC(AMREX_IMPL_ISH X)
42#define AMREX_IMPL_ISH(...) AMREX_IMPL_ISH __VA_ARGS__
43#define AMREX_IMPL_ESC(...) AMREX_IMPL_ESC_(__VA_ARGS__)
44#define AMREX_IMPL_ESC_(...) AMREX_IMPL_VAN_##__VA_ARGS__
45#define AMREX_IMPL_VAN_AMREX_IMPL_ISH
46
47#if !defined(AMREX_IF_ON_DEVICE) && !defined(AMREX_IF_ON_HOST)
48#if (defined(AMREX_USE_CUDA) && defined(__CUDA_ARCH__)) || \
49 (defined(AMREX_USE_HIP) && defined(__HIP_DEVICE_COMPILE__)) || \
50 (defined(AMREX_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__))
51#define AMREX_IF_ON_DEVICE(CODE) \
52 { AMREX_IMPL_STRIP_PARENS(CODE) }
53#define AMREX_IF_ON_HOST(CODE) \
54 {}
55#else
56#define AMREX_IF_ON_DEVICE(CODE) \
57 {}
58#define AMREX_IF_ON_HOST(CODE) \
59 { AMREX_IMPL_STRIP_PARENS(CODE) }
60#endif
61#endif
62
63#ifdef AMREX_USE_SYCL
64# include <sycl/sycl.hpp>
65#endif
66
67#define AMREX_WRONG_NUM_ARGS(...) static_assert(false,"Wrong number of arguments to macro")
68
69#define AMREX_GET_DGV_MACRO(_1,_2,_3,NAME,...) NAME
70#define AMREX_DEVICE_GLOBAL_VARIABLE(...) AMREX_GET_DGV_MACRO(__VA_ARGS__,\
71 AMREX_DGVARR, AMREX_DGV,\
72 AMREX_WRONG_NUM_ARGS)(__VA_ARGS__)
73
74#ifdef AMREX_USE_SYCL
75# define AMREX_DGV(type,name) SYCL_EXTERNAL sycl::ext::oneapi::experimental::device_global<type> name
76# define AMREX_DGVARR(type,num,name) SYCL_EXTERNAL sycl::ext::oneapi::experimental::device_global<type[num]> name
77#elif defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
78# define AMREX_DGV(type,name) __device__ type name
79# define AMREX_DGVARR(type,num,name) __device__ type name[num]
80#else
81# define AMREX_DGV(type,name) type name
82# define AMREX_DGVARR(type,num,name) type name[num]
83#endif
84
85#endif