Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_GpuTypes.H
Go to the documentation of this file.
1#ifndef AMREX_GPU_TYPES_H_
2#define AMREX_GPU_TYPES_H_
3#include <AMReX_Config.H>
4
5#ifdef AMREX_USE_GPU
6
7#include <AMReX_Extension.H>
9
10#ifdef AMREX_USE_SYCL
11# include <sycl/sycl.hpp>
12# include <cstddef>
13#endif
14
15namespace amrex {
16
17#ifdef AMREX_USE_SYCL
18
19struct dim3 {
20 unsigned int x = 1;
21 unsigned int y = 1;
22 unsigned int z = 1;
23 dim3 () = default;
24 constexpr dim3 (unsigned int x_, unsigned int y_=1, unsigned int z_=1) : x(x_),y(y_),z(z_) {}
25};
26
27struct Dim1 {
28 std::size_t x;
29};
30
31struct gpuStream_t {
32 sycl::queue* queue = nullptr;
33 bool operator== (gpuStream_t const& rhs) const noexcept { return queue == rhs.queue; }
34 bool operator!= (gpuStream_t const& rhs) const noexcept { return queue != rhs.queue; }
35};
36
37#endif
38
39}
40
41#endif
42
43namespace amrex::Gpu {
44
45#if defined(AMREX_USE_SYCL)
46
47struct Handler
48{
49 AMREX_GPU_HOST_DEVICE constexpr
50 Handler (sycl::nd_item<1> const* a_item = nullptr, void* a_local = nullptr,
51 int a_n_active_threds = -1)
52 : item(a_item), local(a_local), numActiveThreads(a_n_active_threds) {}
53
55 bool isFullBlock () const {
56 return (numActiveThreads >= int(item->get_local_range(0)) ||
57 numActiveThreads <= 0);
58 }
59
60 std::size_t globalIdx () const { return item->get_global_linear_id(); }
61 std::size_t blockIdx () const { return item->get_group_linear_id(); }
62 std::size_t threadIdx () const { return item->get_local_linear_id(); }
63 //
64 std::size_t gridDim () const { return item->get_group_range(0); }
65 std::size_t blockDim () const { return item->get_local_range(0); }
66
67 // warp index in block
68 std::size_t warpIdx () const { return item->get_sub_group().get_group_id()[0]; }
69 // lane index in warp
70 std::size_t laneIdx () const { return item->get_sub_group().get_local_id()[0]; }
71 // warp size
72 std::size_t warpDim () const { return item->get_sub_group().get_group_range()[0]; }
73
74 void* sharedMemory () const { return local; }
75
76 void sharedBarrier () const { item->barrier(sycl::access::fence_space::local_space); }
77 void globalBarrier () const { item->barrier(sycl::access::fence_space::global_space); }
78 void syncThreads () const { item->barrier(sycl::access::fence_space::global_and_local); }
79
80 sycl::nd_item<1> const* item;
81 void* local; // SYCL shared local memory
83};
84
85#elif defined(AMREX_USE_GPU)
86
87struct Handler
88{
89 AMREX_GPU_HOST_DEVICE constexpr explicit Handler (int n_active_threads = -1)
90 : numActiveThreads(n_active_threads) {}
91
93 bool isFullBlock () const {
94 return (numActiveThreads >= (int)blockDim.x ||
95 numActiveThreads <= 0);
96 }
97
99};
100
101#else
102
103struct Handler {};
104
105#endif
106
107}
108
109#endif
Compiler- and backend-specific extension macros (e.g., restrict, SIMD, inline).
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Definition AMReX_BaseFwd.H:60
Definition AMReX_Amr.cpp:50
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:79
bool operator==(A1 const &a1, A2 const &a2)
Definition AMReX_GpuAllocators.H:214
bool operator!=(A1 const &a1, A2 const &a2)
Definition AMReX_GpuAllocators.H:222
Definition AMReX_GpuTypes.H:88
int numActiveThreads
Definition AMReX_GpuTypes.H:98
__host__ __device__ constexpr Handler(int n_active_threads=-1)
Definition AMReX_GpuTypes.H:89
__host__ __device__ bool isFullBlock() const
Definition AMReX_GpuTypes.H:93