Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_GpuLaunchGlobal.H
Go to the documentation of this file.
1#ifndef AMREX_GPU_LAUNCH_GLOBAL_H_
2#define AMREX_GPU_LAUNCH_GLOBAL_H_
3#include <AMReX_Config.H>
4
6
7#if defined(AMREX_USE_CUDA) && defined(__GNUC__)
8#pragma GCC diagnostic push
9#pragma GCC diagnostic ignored "-Wunused-parameter"
10#endif
11
12namespace amrex {
13
14#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
15 // We cannot take rvalue lambdas.
16 template<class L>
17 AMREX_GPU_GLOBAL void launch_global (L f0) { f0(); }
18
19#if defined(AMREX_USE_CUDA) && defined(AMREX_GPU_MIN_BLOCKS)
20 namespace detail {
21 // Min blocks of mt threads for AMREX_GPU_MIN_BLOCKS blocks of
22 // AMREX_GPU_MAX_THREADS threads. Rounded down, so for mt up to
23 // AMREX_GPU_MIN_BLOCKS*AMREX_GPU_MAX_THREADS the kernel's register cap is
24 // not below -maxrregcount, which non-inlined callees are compiled with.
25 // At most 16, the lowest per-SM block limit of supported GPUs.
26 constexpr int launch_min_blocks (int mt) {
27 int n = AMREX_GPU_MIN_BLOCKS * AMREX_GPU_MAX_THREADS / mt;
28 return (n < 1) ? 1 : ((n > 16) ? 16 : n);
29 }
30 }
31#endif
32
33 // With AMREX_GPU_MIN_BLOCKS (CUDA only), registers per thread are capped so
34 // that this many blocks of AMREX_GPU_MAX_THREADS threads fit on an SM.
35 // Note that -maxrregcount is ignored for kernels with launch bounds.
36 template<int amrex_launch_bounds_max_threads, class L>
37#if defined(AMREX_USE_CUDA) && defined(AMREX_GPU_MIN_BLOCKS)
38 __launch_bounds__(amrex_launch_bounds_max_threads,
39 detail::launch_min_blocks(amrex_launch_bounds_max_threads))
40#else
41 __launch_bounds__(amrex_launch_bounds_max_threads)
42#endif
43 AMREX_GPU_GLOBAL void launch_global (L f0) { f0(); }
44
45 template<int amrex_launch_bounds_max_threads, int min_blocks, class L>
46 __launch_bounds__(amrex_launch_bounds_max_threads, min_blocks)
47 AMREX_GPU_GLOBAL void launch_global (L f0) { f0(); }
48#endif
49
50}
51
52#if defined(AMREX_USE_CUDA) && defined(__GNUC__)
53#pragma GCC diagnostic pop
54#endif
55
56#endif
#define AMREX_GPU_GLOBAL
Definition AMReX_GpuQualifiers.H:19
Definition AMReX_Amr.cpp:50
__global__ void launch_global(L f0, Lambdas... fs)
Definition AMReX_GpuLaunch.H:68