1#ifndef AMREX_GPU_LAUNCH_H_
2#define AMREX_GPU_LAUNCH_H_
3#include <AMReX_Config.H>
30#define AMREX_GPU_NCELLS_PER_THREAD 3
31#define AMREX_GPU_Y_STRIDE 1
32#define AMREX_GPU_Z_STRIDE 1
35# define AMREX_LAUNCH_KERNEL(MT, blocks, threads, sharedMem, stream, ... ) \
36 amrex::launch_global<MT><<<blocks, threads, sharedMem, stream>>>(__VA_ARGS__)
37# define AMREX_LAUNCH_KERNEL_NOBOUND(blocks, threads, sharedMem, stream, ... ) \
38 amrex::launch_global <<<blocks, threads, sharedMem, stream>>>(__VA_ARGS__)
39#elif defined(AMREX_USE_HIP)
40# define AMREX_LAUNCH_KERNEL(MT, blocks, threads, sharedMem, stream, ... ) \
41 hipLaunchKernelGGL(launch_global<MT>, blocks, threads, sharedMem, stream, __VA_ARGS__)
42# define AMREX_LAUNCH_KERNEL_NOBOUND(blocks, threads, sharedMem, stream, ... ) \
43 hipLaunchKernelGGL(launch_global , blocks, threads, sharedMem, stream, __VA_ARGS__)
53#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
54 template<
class L,
class... Lambdas>
61 template<
class L,
class... Lambdas>
64 call_device(std::forward<Lambdas>(fs)...);
74 template<
class L,
class... Lambdas>
76 std::forward<L>(f0)();
81 template <
class T>
class LayoutData;
88 return AMREX_GPU_MAX_THREADS;
99 const auto len = bx.length3d();
101 Long j = (
offset - k*(len[0]*len[1])) / len[0];
102 Long i = (
offset - k*(len[0]*len[1])) - j*len[0];
105 static_cast<int>(k))};
107 return (bx &
Box(iv,iv,bx.type()));
153 Long numBlocks = (std::max(N,
Long(1)) + MT - 1) / MT;
155 numBlocks = std::min(numBlocks,
Long(std::numeric_limits<unsigned int>::max()/MT));
157 numBlocks = std::min(numBlocks,
Long(std::numeric_limits<int>::max()));
158 ec.numBlocks.x = numBlocks;
159 ec.numThreads.x = MT;
168 return makeExecutionConfig<MT>(box.numPts());
181 int numblocks_max = std::numeric_limits<int>::max();
183 Long nmax =
Long(MT) * numblocks_max;
186 auto nlaunches = int((N+nmax-1)/nmax);
189 for (
int i = 0; i < nlaunches; ++i) {
192 nblocks = numblocks_max;
195 nblocks = int((N+MT-1)/MT);
198 r[i].start_idx = ndone;
199 ndone +=
Long(nblocks) * MT;
201 r[i].nblocks = nblocks;
206 template <
int MT,
int dim>
209 return makeNExecutionConfigs<MT>(box.numPts());
232#if defined(AMREX_USE_GPU) || !defined(AMREX_USE_OMP)
242template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
270template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
278template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
282#pragma omp parallel for
283 for (T i = 0; i < n; ++i) {
294#if (AMREX_SPACEDIM == 1)
295#pragma omp parallel for
296 for (
int i = lo.x; i <= hi.x; ++i) {
299#elif (AMREX_SPACEDIM == 2)
300#pragma omp parallel for
301 for (
int j = lo.y; j <= hi.y; ++j) {
303 for (
int i = lo.x; i <= hi.x; ++i) {
308#pragma omp parallel for collapse(2)
309 for (
int k = lo.z; k <= hi.z; ++k) {
310 for (
int j = lo.y; j <= hi.y; ++j) {
312 for (
int i = lo.x; i <= hi.x; ++i) {
320template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
326#if (AMREX_SPACEDIM == 1)
327#pragma omp parallel for collapse(2)
328 for (T n = 0; n < ncomp; ++n) {
329 for (
int i = lo.x; i <= hi.x; ++i) {
333#elif (AMREX_SPACEDIM == 2)
334#pragma omp parallel for collapse(2)
335 for (T n = 0; n < ncomp; ++n) {
336 for (
int j = lo.y; j <= hi.y; ++j) {
338 for (
int i = lo.x; i <= hi.x; ++i) {
344#pragma omp parallel for collapse(3)
345 for (T n = 0; n < ncomp; ++n) {
346 for (
int k = lo.z; k <= hi.z; ++k) {
347 for (
int j = lo.y; j <= hi.y; ++j) {
349 for (
int i = lo.x; i <= hi.x; ++i) {
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:80
#define AMREX_ATTRIBUTE_FLATTEN_FOR
Definition AMReX_Extension.H:151
#define AMREX_GPU_Z_STRIDE
Definition AMReX_GpuLaunch.H:32
#define AMREX_GPU_NCELLS_PER_THREAD
Definition AMReX_GpuLaunch.H:30
#define AMREX_GPU_Y_STRIDE
Definition AMReX_GpuLaunch.H:31
#define AMREX_IF_ON_DEVICE(CODE)
Definition AMReX_GpuQualifiers.H:56
#define AMREX_GPU_GLOBAL
Definition AMReX_GpuQualifiers.H:19
#define AMREX_IF_ON_HOST(CODE)
Definition AMReX_GpuQualifiers.H:58
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
__host__ __device__ const int * hiVect() const &noexcept
Return a constant pointer the array of high end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:191
__host__ __device__ const int * loVect() const &noexcept
Return a constant pointer the array of low end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:186
__host__ __device__ BoxND & coarsen(int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition AMReX_Box.H:722
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:111
static void c_threads_and_blocks(const int *lo, const int *hi, dim3 &numBlocks, dim3 &numThreads) noexcept
Definition AMReX_GpuDevice.cpp:1007
static void n_threads_and_blocks(const Long N, dim3 &numBlocks, dim3 &numThreads) noexcept
Definition AMReX_GpuDevice.cpp:992
static constexpr int warp_size
Definition AMReX_GpuDevice.H:197
static void c_comps_threads_and_blocks(const int *lo, const int *hi, const int comps, dim3 &numBlocks, dim3 &numThreads) noexcept
Definition AMReX_GpuDevice.cpp:999
static void grid_stride_threads_and_blocks(dim3 &numBlocks, dim3 &numThreads) noexcept
Definition AMReX_GpuDevice.cpp:1065
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
amrex_long Long
Definition AMReX_INT.H:30
void ParallelForOMP(T n, L const &f) noexcept
Performance-portable kernel launch function with optional OpenMP threading.
Definition AMReX_GpuLaunch.H:243
__host__ __device__ Box getThreadBox(const Box &bx, Long offset) noexcept
Definition AMReX_GpuLaunch.H:96
Vector< ExecConfig > makeNExecutionConfigs(Long N) noexcept
Definition AMReX_GpuLaunch.H:178
constexpr std::size_t numThreadsPerBlockParallelFor()
Definition AMReX_GpuLaunch.H:87
ExecutionConfig makeExecutionConfig(Long N) noexcept
Definition AMReX_GpuLaunch.H:150
Definition AMReX_Amr.cpp:49
void launch_host(L &&f0) noexcept
Definition AMReX_GpuLaunch.H:72
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:319
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:138
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:193
__host__ __device__ BoxND< dim > surroundingNodes(const BoxND< dim > &b, int dir) noexcept
Return a BoxND with NODE based coordinates in direction dir that encloses BoxND b....
Definition AMReX_Box.H:1522
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:27
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
__global__ void launch_global(L f0, Lambdas... fs)
Definition AMReX_GpuLaunch.H:55
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:312
Definition AMReX_GpuLaunch.H:172
int nblocks
Definition AMReX_GpuLaunch.H:174
Long start_idx
Definition AMReX_GpuLaunch.H:173
Definition AMReX_GpuLaunch.H:118
ExecutionConfig(dim3 nb, dim3 nt, std::size_t sm=0) noexcept
Definition AMReX_GpuLaunch.H:140
ExecutionConfig(Long N) noexcept
Definition AMReX_GpuLaunch.H:137
dim3 numBlocks
Definition AMReX_GpuLaunch.H:143
dim3 numThreads
Definition AMReX_GpuLaunch.H:144
ExecutionConfig(const Box &box, int comps) noexcept
Definition AMReX_GpuLaunch.H:133
ExecutionConfig(const Box &box) noexcept
Definition AMReX_GpuLaunch.H:122
ExecutionConfig() noexcept
Definition AMReX_GpuLaunch.H:119
std::size_t sharedMem
Definition AMReX_GpuLaunch.H:145