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
11namespace amrex {
12
13template <typename T, std::enable_if_t<std::is_integral_v<T>,int> = 0>
14bool isEmpty (T n) noexcept { return n <= 0; }
15
16template<int dim>
17AMREX_FORCE_INLINE bool isEmpty (BoxND<dim> const& b) noexcept { return b.isEmpty(); }
18
19namespace Gpu {
20
22namespace range_detail {
23
25template <typename T, std::enable_if_t<std::is_integral_v<T>,int> = 0>
27Long size (T const& b) noexcept { return static_cast<Long>(b); }
28
29template <typename T, std::enable_if_t<std::is_integral_v<T>,int> = 0>
31Long at (T const& /*b*/, Long offset) noexcept { return offset; }
32
34template<int dim>
36AMREX_FORCE_INLINE Long size (BoxND<dim> const& b) noexcept
37{
38 AMREX_IF_ON_DEVICE((return b.numPts();))
40 amrex::ignore_unused(b);
41 return 1;
42 ))
43}
44
45template<int dim>
47AMREX_FORCE_INLINE BoxND<dim> at (BoxND<dim> const& b, Long offset) noexcept
48{
50 auto iv = b.atOffset(offset);
51 return BoxND<dim>(iv,iv,b.ixType());
52 ))
54 amrex::ignore_unused(offset);
55 return b;
56 ))
57}
58
59template <typename T>
60struct range_impl
61{
63 explicit range_impl (T const& b) noexcept : m_b(b), m_n(range_detail::size(b)) {}
64
65#ifdef AMREX_USE_SYCL
66 range_impl (T const& b, Long gid, Long grange) noexcept
67 : m_b(b), m_n(range_detail::size(b)), m_gid(gid), m_grange(grange) {}
68#endif
69
70 struct iterator
71 {
73 iterator (T const& b, Long i, Long s) noexcept : mi_b(&b), mi_i(i), mi_s(s) {}
74
76 void operator++ () noexcept { mi_i += mi_s; }
77
79 bool operator!= (iterator const& rhs) const noexcept { return mi_i < rhs.mi_i; }
80
82 T operator* () const noexcept { return range_detail::at(*mi_b,mi_i); }
83
84 private:
85 T const* mi_b;
86 Long mi_i;
87 Long mi_s;
88 };
89
90 [[nodiscard]] AMREX_GPU_HOST_DEVICE
91 iterator begin () const noexcept {
92#if defined (__SYCL_DEVICE_ONLY__)
93 return iterator(m_b, m_gid, m_grange);
94#else
96 return iterator(m_b, blockDim.x*blockIdx.x+threadIdx.x, blockDim.x*gridDim.x);
97 ))
99 return iterator(m_b,0,1);
100 ))
101#endif
102 }
103
104 [[nodiscard]] AMREX_GPU_HOST_DEVICE
105 iterator end () const noexcept { return iterator(m_b,m_n,0); }
106
107private:
108 T m_b;
109 Long m_n;
110#ifdef AMREX_USE_SYCL
111 Long m_gid;
112 Long m_grange;
113#endif
114};
115}
117
118#ifdef AMREX_USE_SYCL
119template <typename T>
120range_detail::range_impl<T> Range (T const& b, Long gid, Long grange) noexcept {
121 return range_detail::range_impl<T>(b,gid,grange);
122}
123#endif
124
125template <typename T>
127range_detail::range_impl<T> Range (T const& b) noexcept { return range_detail::range_impl<T>(b); }
128
129}}
130
131#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:1089
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:127
Definition AMReX_Amr.cpp:49
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2006
bool isEmpty(T n) noexcept
Definition AMReX_GpuRange.H:14
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2015