1#ifndef AMREX_GPU_CONTROL_H_
2#define AMREX_GPU_CONTROL_H_
3#include <AMReX_Config.H>
10#if defined(AMREX_USE_HIP) || defined(AMREX_USE_CUDA)
11#define AMREX_GPU_STREAM_ALLOC_SUPPORT 1
14#if defined(AMREX_USE_HIP)
15#define AMREX_HIP_OR_CUDA(a,b) a
16#elif defined(AMREX_USE_CUDA)
17#define AMREX_HIP_OR_CUDA(a,b) b
19#define AMREX_HIP_OR_CUDA(a,b) ((void)0);
22#if defined(AMREX_USE_HIP)
23#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) a
24#elif defined(AMREX_USE_CUDA)
25#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) b
26#elif defined(AMREX_USE_SYCL)
27#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) c
29#define AMREX_HIP_OR_CUDA_OR_SYCL(a,b,c) ((void)0);
33#define AMREX_GPU_OR_CPU(a,b) a
35#define AMREX_GPU_OR_CPU(a,b) b
39#define AMREX_SYCL_ONLY(a) a
41#define AMREX_SYCL_ONLY(a) ((void)0)
45#if (AMREX_SPACEDIM == 1)
46# define AMREX_SYCL_1D_ONLY(a) a
47# define AMREX_SYCL_2D_ONLY(a) ((void)0)
48# define AMREX_SYCL_3D_ONLY(a) ((void)0)
49#elif (AMREX_SPACEDIM == 2)
50# define AMREX_SYCL_1D_ONLY(a) ((void)0)
51# define AMREX_SYCL_2D_ONLY(a) a
52# define AMREX_SYCL_3D_ONLY(a) ((void)0)
53#elif (AMREX_SPACEDIM == 3)
54# define AMREX_SYCL_1D_ONLY(a) ((void)0)
55# define AMREX_SYCL_2D_ONLY(a) ((void)0)
56# define AMREX_SYCL_3D_ONLY(a) a
59# define AMREX_SYCL_1D_ONLY(a) ((void)0)
60# define AMREX_SYCL_2D_ONLY(a) ((void)0)
61# define AMREX_SYCL_3D_ONLY(a) ((void)0)
69#define AMREX_DEFAULT_RUNON
71#define AMREX_DEFAULT_RUNON =amrex::RunOn::Host
78#elif defined(AMREX_USE_CUDA)
84#if defined(AMREX_USE_GPU)
165 : m_prev_flag(std::exchange(in_single_stream_region,true))
182 : m_prev_flag(std::exchange(in_nosync_region,true))
199 [[nodiscard]]
constexpr bool inGraphRegion () {
return false; }
201 [[nodiscard]]
constexpr bool setGraphRegion (
bool) {
return false; }
203 struct [[nodiscard]] LaunchSafeGuard
205 explicit LaunchSafeGuard (
bool) {}
208 struct [[nodiscard]] GraphSafeGuard
210 explicit GraphSafeGuard (
bool) {}
217 struct [[nodiscard]] SingleStreamRegion {};
218 struct [[nodiscard]] NoSyncRegion {
219 static constexpr bool inNoSyncRegionPreviously () {
return true; }
bool setGraphRegion(bool graph)
Definition AMReX_GpuControl.H:120
bool inGraphRegion()
Definition AMReX_GpuControl.H:117
bool setNoSyncRegion(bool b) noexcept
Definition AMReX_GpuControl.H:154
bool in_graph_region
Definition AMReX_GpuControl.cpp:8
bool in_launch_region
Definition AMReX_GpuControl.cpp:7
bool notInGraphRegion()
Definition AMReX_GpuControl.H:118
bool in_single_stream_region
Definition AMReX_GpuControl.cpp:9
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
bool inSingleStreamRegion() noexcept
Definition AMReX_GpuControl.H:147
bool in_nosync_region
Definition AMReX_GpuControl.cpp:10
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:89
bool setLaunchRegion(bool launch) noexcept
Definition AMReX_GpuControl.H:110
bool inNoSyncRegion() noexcept
Definition AMReX_GpuControl.H:148
bool setSingleStreamRegion(bool b) noexcept
Definition AMReX_GpuControl.H:150
Definition AMReX_Amr.cpp:50
RunOn
Definition AMReX_GpuControl.H:65
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:79
void launch(T const &n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:122
Definition AMReX_GpuControl.H:136
~GraphSafeGuard()
Definition AMReX_GpuControl.H:139
GraphSafeGuard(bool flag) noexcept
Definition AMReX_GpuControl.H:137
Definition AMReX_GpuControl.H:127
LaunchSafeGuard(bool flag) noexcept
Definition AMReX_GpuControl.H:128
~LaunchSafeGuard()
Definition AMReX_GpuControl.H:130
Definition AMReX_GpuControl.H:180
NoSyncRegion() noexcept
Definition AMReX_GpuControl.H:181
bool inNoSyncRegionPreviously() const
Definition AMReX_GpuControl.H:187
bool m_prev_flag
Definition AMReX_GpuControl.H:190
~NoSyncRegion()
Definition AMReX_GpuControl.H:185
Definition AMReX_GpuControl.H:163
SingleStreamRegion() noexcept
Definition AMReX_GpuControl.H:164
~SingleStreamRegion()
Definition AMReX_GpuControl.H:168