1#ifndef AMREX_GPU_CONTROL_H_
2#define AMREX_GPU_CONTROL_H_
3#include <AMReX_Config.H>
10#if defined(AMREX_USE_CUDA) && (__CUDACC_VER_MAJOR__ > 11 || ((__CUDACC_VER_MAJOR__ == 11) && (__CUDACC_VER_MINOR__ >= 2)))
11#define AMREX_CUDA_GE_11_2 1
14#if defined(AMREX_USE_HIP) || defined(AMREX_CUDA_GE_11_2)
15#define AMREX_GPU_STREAM_ALLOC_SUPPORT 1
18#if defined(AMREX_USE_HIP)
19#define AMREX_HIP_OR_CUDA(a,b) a
20#elif defined(AMREX_USE_CUDA)
21#define AMREX_HIP_OR_CUDA(a,b) b
23#define AMREX_HIP_OR_CUDA(a,b) ((void)0);
26#if defined(AMREX_USE_HIP)
27#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) a
28#elif defined(AMREX_USE_CUDA)
29#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) b
30#elif defined(AMREX_USE_SYCL)
31#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) c
33#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) ((void)0);
37#define AMREX_GPU_OR_CPU(a,b) a
39#define AMREX_GPU_OR_CPU(a,b) b
43#define AMREX_SYCL_ONLY(a) a
45#define AMREX_SYCL_ONLY(a) ((void)0)
49#if (AMREX_SPACEDIM == 1)
50# define AMREX_SYCL_1D_ONLY(a) a
51# define AMREX_SYCL_2D_ONLY(a) ((void)0)
52# define AMREX_SYCL_3D_ONLY(a) ((void)0)
53#elif (AMREX_SPACEDIM == 2)
54# define AMREX_SYCL_1D_ONLY(a) ((void)0)
55# define AMREX_SYCL_2D_ONLY(a) a
56# define AMREX_SYCL_3D_ONLY(a) ((void)0)
57#elif (AMREX_SPACEDIM == 3)
58# define AMREX_SYCL_1D_ONLY(a) ((void)0)
59# define AMREX_SYCL_2D_ONLY(a) ((void)0)
60# define AMREX_SYCL_3D_ONLY(a) a
63# define AMREX_SYCL_1D_ONLY(a) ((void)0)
64# define AMREX_SYCL_2D_ONLY(a) ((void)0)
65# define AMREX_SYCL_3D_ONLY(a) ((void)0)
76#elif defined(AMREX_USE_CUDA)
82#if defined(AMREX_USE_GPU)
163 : m_prev_flag(std::exchange(in_single_stream_region,true))
180 : m_prev_flag(std::exchange(in_nosync_region,true))
191 [[nodiscard]]
inline constexpr bool inLaunchRegion () {
return false; }
193 [[nodiscard]]
inline constexpr bool setLaunchRegion (
bool) {
return false; }
195 [[nodiscard]]
inline constexpr bool inGraphRegion () {
return false; }
197 [[nodiscard]]
inline constexpr bool setGraphRegion (
bool) {
return false; }
199 struct [[nodiscard]] LaunchSafeGuard
201 explicit LaunchSafeGuard (
bool) {}
204 struct [[nodiscard]] GraphSafeGuard
206 explicit GraphSafeGuard (
bool) {}
210 [[nodiscard]]
inline constexpr bool inNoSyncRegion () {
return true; }
212 [[nodiscard]]
inline constexpr bool setNoSyncRegion (
bool) {
return true; }
213 struct [[nodiscard]] SingleStreamRegion {};
214 struct [[nodiscard]] NoSyncRegion {};
bool setGraphRegion(bool graph)
Definition AMReX_GpuControl.H:118
bool inGraphRegion()
Definition AMReX_GpuControl.H:115
bool setNoSyncRegion(bool b) noexcept
Definition AMReX_GpuControl.H:152
bool in_graph_region
Definition AMReX_GpuControl.cpp:8
bool in_launch_region
Definition AMReX_GpuControl.cpp:7
bool notInGraphRegion()
Definition AMReX_GpuControl.H:116
bool in_single_stream_region
Definition AMReX_GpuControl.cpp:9
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:86
bool inSingleStreamRegion() noexcept
Definition AMReX_GpuControl.H:145
bool in_nosync_region
Definition AMReX_GpuControl.cpp:10
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:87
bool setLaunchRegion(bool launch) noexcept
Definition AMReX_GpuControl.H:108
bool inNoSyncRegion() noexcept
Definition AMReX_GpuControl.H:146
bool setSingleStreamRegion(bool b) noexcept
Definition AMReX_GpuControl.H:148
Definition AMReX_Amr.cpp:49
RunOn
Definition AMReX_GpuControl.H:69
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:77
void launch(T const &n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:120
Definition AMReX_GpuControl.H:134
~GraphSafeGuard()
Definition AMReX_GpuControl.H:137
bool m_old
Definition AMReX_GpuControl.H:139
GraphSafeGuard(bool flag) noexcept
Definition AMReX_GpuControl.H:135
Definition AMReX_GpuControl.H:125
LaunchSafeGuard(bool flag) noexcept
Definition AMReX_GpuControl.H:126
bool m_old
Definition AMReX_GpuControl.H:130
~LaunchSafeGuard()
Definition AMReX_GpuControl.H:128
Definition AMReX_GpuControl.H:178
NoSyncRegion() noexcept
Definition AMReX_GpuControl.H:179
bool m_prev_flag
Definition AMReX_GpuControl.H:186
~NoSyncRegion()
Definition AMReX_GpuControl.H:183
Definition AMReX_GpuControl.H:161
SingleStreamRegion() noexcept
Definition AMReX_GpuControl.H:162
~SingleStreamRegion()
Definition AMReX_GpuControl.H:166
bool m_prev_flag
Definition AMReX_GpuControl.H:169