Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_GpuRange.H
Go to the documentation of this file.
1#ifndef AMREX_GPU_RANGE_H_
2#define AMREX_GPU_RANGE_H_
3#include <AMReX_Config.H>
4
6#include <AMReX_GpuControl.H>
7#include <AMReX_GpuError.H>
8#include <AMReX_Box.H>
9#include <AMReX_TypeTraits.H>
10#include <concepts>
11
12namespace amrex {
13
14template <std::integral T>
15bool isEmpty (T n) noexcept { return n <= 0; }
16
17template<int dim>
18AMREX_FORCE_INLINE bool isEmpty (BoxND<dim> const& b) noexcept { return b.isEmpty(); }
19
20namespace Gpu {
21
23namespace range_detail {
24
26template <std::integral T>
28Long size (T const& b) noexcept { return static_cast<Long>(b); }
29
30template <std::integral T>
32Long at (T const& /*b*/, Long offset) noexcept { return offset; }
33
35template<int dim>
37AMREX_FORCE_INLINE Long size (BoxND<dim> const& b) noexcept
38{
39 AMREX_IF_ON_DEVICE((return b.numPts();))
41 amrex::ignore_unused(b);
42 return 1;
43 ))
44}
45
46template<int dim>
48AMREX_FORCE_INLINE BoxND<dim> at (BoxND<dim> const& b, Long offset) noexcept
49{
51 auto iv = b.atOffset(offset);
52 return BoxND<dim>(iv,iv,b.ixType());
53 ))
55 amrex::ignore_unused(offset);
56 return b;
57 ))
58}
59
60template <typename T>
61struct range_impl
62{
64 explicit range_impl (T const& b) noexcept : m_b(b), m_n(range_detail::size(b)) {}
65
66#ifdef AMREX_USE_SYCL
67 range_impl (T const& b, Long gid, Long grange) noexcept
68 : m_b(b), m_n(range_detail::size(b)), m_gid(gid), m_grange(grange) {}
69#endif
70
71 struct iterator
72 {
74 iterator (T const& b, Long i, Long s) noexcept : mi_b(&b), mi_i(i), mi_s(s) {}
75
77 void operator++ () noexcept { mi_i += mi_s; }
78
80 bool operator!= (iterator const& rhs) const noexcept { return mi_i < rhs.mi_i; }
81
83 T operator* () const noexcept { return range_detail::at(*mi_b,mi_i); }
84
85 private:
86 T const* mi_b;
87 Long mi_i;
88 Long mi_s;
89 };
90
91 [[nodiscard]] AMREX_GPU_HOST_DEVICE
92 iterator begin () const noexcept {
93#if defined (__SYCL_DEVICE_ONLY__)
94 return iterator(m_b, m_gid, m_grange);
95#else
97 return iterator(m_b, blockDim.x*blockIdx.x+threadIdx.x, blockDim.x*gridDim.x);
98 ))
100 return iterator(m_b,0,1);
101 ))
102#endif
103 }
104
105 [[nodiscard]] AMREX_GPU_HOST_DEVICE
106 iterator end () const noexcept { return iterator(m_b,m_n,0); }
107
108private:
109 T m_b;
110 Long m_n;
111#ifdef AMREX_USE_SYCL
112 Long m_gid;
113 Long m_grange;
114#endif
115};
116}
118
119#ifdef AMREX_USE_SYCL
120template <typename T>
121range_detail::range_impl<T> Range (T const& b, Long gid, Long grange) noexcept {
122 return range_detail::range_impl<T>(b,gid,grange);
123}
124#endif
125
126template <typename T>
128range_detail::range_impl<T> Range (T const& b) noexcept { return range_detail::range_impl<T>(b); }
129
130}}
131
132#endif
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_IF_ON_DEVICE(CODE)
Definition AMReX_GpuQualifiers.H:56
#define AMREX_IF_ON_HOST(CODE)
Definition AMReX_GpuQualifiers.H:58
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1139
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:49
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ range_detail::range_impl< T > Range(T const &b) noexcept
Definition AMReX_GpuRange.H:128
Definition AMReX_Amr.cpp:50
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2018
bool isEmpty(T n) noexcept
Definition AMReX_GpuRange.H:15
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2028