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