@@ -60,11 +60,8 @@ namespace amrex {
60
60
struct Array4
61
61
{
62
62
T* AMREX_RESTRICT p;
63
- Long jstride = 0 ;
64
- Long kstride = 0 ;
65
- Long nstride = 0 ;
66
63
Dim3 begin{1 ,1 ,1 };
67
- Dim3 end {0 ,0 ,0 }; // end is hi + 1
64
+ Dim3 len {0 ,0 ,0 };
68
65
int ncomp=0 ;
69
66
70
67
AMREX_GPU_HOST_DEVICE
@@ -74,22 +71,16 @@ namespace amrex {
74
71
AMREX_GPU_HOST_DEVICE
75
72
constexpr Array4 (Array4<std::remove_const_t <T>> const & rhs) noexcept
76
73
: p(rhs.p),
77
- jstride(rhs.jstride),
78
- kstride(rhs.kstride),
79
- nstride(rhs.nstride),
80
74
begin(rhs.begin),
81
- end (rhs.end ),
75
+ len (rhs.len ),
82
76
ncomp(rhs.ncomp)
83
77
{}
84
78
85
79
AMREX_GPU_HOST_DEVICE
86
80
constexpr Array4 (T* a_p, Dim3 const & a_begin, Dim3 const & a_end, int a_ncomp) noexcept
87
81
: p(a_p),
88
- jstride(a_end.x-a_begin.x),
89
- kstride(jstride*(a_end.y-a_begin.y)),
90
- nstride(kstride*(a_end.z-a_begin.z)),
91
82
begin(a_begin),
92
- end( a_end) ,
83
+ len{ a_end. x -a_begin. x , a_end. y -a_begin. y , a_end. z -a_begin. z } ,
93
84
ncomp (a_ncomp)
94
85
{}
95
86
@@ -99,12 +90,9 @@ namespace amrex {
99
90
std::remove_const_t <U>>,int > = 0 >
100
91
AMREX_GPU_HOST_DEVICE
101
92
constexpr Array4 (Array4<U> const & rhs, int start_comp) noexcept
102
- : p((T*)(rhs.p+start_comp*rhs.nstride)),
103
- jstride(rhs.jstride),
104
- kstride(rhs.kstride),
105
- nstride(rhs.nstride),
93
+ : p((T*)(rhs.p+start_comp*rhs.nstride())),
106
94
begin(rhs.begin),
107
- end (rhs.end ),
95
+ len (rhs.len ),
108
96
ncomp(rhs.ncomp-start_comp)
109
97
{}
110
98
@@ -114,25 +102,31 @@ namespace amrex {
114
102
std::remove_const_t <U>>,int > = 0 >
115
103
AMREX_GPU_HOST_DEVICE
116
104
constexpr Array4 (Array4<U> const & rhs, int start_comp, int num_comps) noexcept
117
- : p((T*)(rhs.p+start_comp*rhs.nstride)),
118
- jstride(rhs.jstride),
119
- kstride(rhs.kstride),
120
- nstride(rhs.nstride),
105
+ : p((T*)(rhs.p+start_comp*rhs.nstride())),
121
106
begin(rhs.begin),
122
- end (rhs.end ),
107
+ len (rhs.len ),
123
108
ncomp(num_comps)
124
109
{}
125
110
126
111
AMREX_GPU_HOST_DEVICE
127
112
explicit operator bool () const noexcept { return p != nullptr ; }
128
113
114
+ [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
115
+ Long jstride () const noexcept { return Long (len.x ); }
116
+
117
+ [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
118
+ Long kstride () const noexcept { return Long (len.x )*Long (len.y ); }
119
+
120
+ [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
121
+ Long nstride () const noexcept { return Long (len.x )*Long (len.y )*Long (len.z ); }
122
+
129
123
template <class U =T, std::enable_if_t <!std::is_void_v<U>,int > = 0 >
130
124
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
131
125
U& operator () (int i, int j, int k) const noexcept {
132
126
#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
133
127
index_assert (i,j,k,0 );
134
128
#endif
135
- return p[(i-begin.x )+(j-begin.y )*jstride+(k-begin.z )*kstride];
129
+ return p[(i-begin.x )+(j-begin.y )*jstride () +(k-begin.z )*kstride () ];
136
130
}
137
131
138
132
template <class U =T, std::enable_if_t <!std::is_void_v<U>,int > = 0 >
@@ -141,7 +135,7 @@ namespace amrex {
141
135
#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
142
136
index_assert (i,j,k,n);
143
137
#endif
144
- return p[(i-begin.x )+(j-begin.y )*jstride+(k-begin.z )*kstride+n*nstride];
138
+ return p[(i-begin.x )+(j-begin.y )*jstride () +(k-begin.z )*kstride () +n*nstride () ];
145
139
}
146
140
147
141
template <class U =T, std::enable_if_t <!std::is_void_v<U>,int > = 0 >
@@ -150,7 +144,7 @@ namespace amrex {
150
144
#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
151
145
index_assert (i,j,k,0 );
152
146
#endif
153
- return p + ((i-begin.x )+(j-begin.y )*jstride+(k-begin.z )*kstride);
147
+ return p + ((i-begin.x )+(j-begin.y )*jstride () +(k-begin.z )*kstride () );
154
148
}
155
149
156
150
template <class U =T, std::enable_if_t <!std::is_void_v<U>,int > = 0 >
@@ -159,7 +153,7 @@ namespace amrex {
159
153
#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
160
154
index_assert (i,j,k,n);
161
155
#endif
162
- return p + ((i-begin.x )+(j-begin.y )*jstride+(k-begin.z )*kstride+n*nstride);
156
+ return p + ((i-begin.x )+(j-begin.y )*jstride () +(k-begin.z )*kstride () +n*nstride () );
163
157
}
164
158
165
159
template <class U =T, std::enable_if_t <!std::is_void_v<U>,int > = 0 >
@@ -241,22 +235,22 @@ namespace amrex {
241
235
242
236
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
243
237
std::size_t size () const noexcept {
244
- return this ->nstride * this ->ncomp ;
238
+ return this ->nstride () * this ->ncomp ;
245
239
}
246
240
247
241
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
248
242
int nComp () const noexcept { return ncomp; }
249
243
250
244
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
251
245
bool contains (int i, int j, int k) const noexcept {
252
- return (i>=begin.x && i<end. x && j>=begin.y && j<end. y && k>=begin.z && k<end. z );
246
+ return (i>=begin.x && i<(begin. x +len. x ) && j>=begin.y && j<(begin. y +len. y ) && k>=begin.z && k<(begin. z +len. z ) );
253
247
}
254
248
255
249
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
256
250
bool contains (IntVect const & iv) const noexcept {
257
- return AMREX_D_TERM ( iv[0 ]>=begin.x && iv[0 ]<end. x ,
258
- && iv[1 ]>=begin.y && iv[1 ]<end. y ,
259
- && iv[2 ]>=begin.z && iv[2 ]<end. z );
251
+ return AMREX_D_TERM ( iv[0 ]>=begin.x && iv[0 ]<(begin. x +len. x ) ,
252
+ && iv[1 ]>=begin.y && iv[1 ]<(begin. y +len. y ) ,
253
+ && iv[2 ]>=begin.z && iv[2 ]<(begin. z +len. z ) );
260
254
}
261
255
262
256
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
@@ -268,21 +262,21 @@ namespace amrex {
268
262
AMREX_GPU_HOST_DEVICE inline
269
263
void index_assert (int i, int j, int k, int n) const
270
264
{
271
- if (i<begin.x || i>=end. x || j<begin.y || j>=end. y || k<begin.z || k>=end. z
265
+ if (i<begin.x || i>=(begin. x +len. x ) || j<begin.y || j>=(begin. y +len. y ) || k<begin.z || k>=(begin. z +len. z )
272
266
|| n < 0 || n >= ncomp) {
273
267
AMREX_IF_ON_DEVICE ((
274
268
AMREX_DEVICE_PRINTF (" (%d,%d,%d,%d) is out of bound (%d:%d,%d:%d,%d:%d,0:%d)\n " ,
275
- i, j, k, n, begin.x , end. x -1 , begin.y , end. y -1 ,
276
- begin.z , end. z -1 , ncomp-1 );
269
+ i, j, k, n, begin.x , (begin. x +len. x ) -1 , begin.y , (begin. y +len. y ) -1 ,
270
+ begin.z , (begin. z +len. z ) -1 , ncomp-1 );
277
271
amrex::Abort ();
278
272
))
279
273
AMREX_IF_ON_HOST ((
280
274
std::stringstream ss;
281
275
ss << " (" << i << " ," << j << " ," << k << " ," << n
282
276
<< " ) is out of bound ("
283
- << begin.x << " :" << end. x -1 << " ,"
284
- << begin.y << " :" << end. y -1 << " ,"
285
- << begin.z << " :" << end. z -1 << " ,"
277
+ << begin.x << " :" << (begin. x +len. x ) -1 << " ,"
278
+ << begin.y << " :" << (begin. y +len. y ) -1 << " ,"
279
+ << begin.z << " :" << (begin. z +len. z ) -1 << " ,"
286
280
<< " 0:" << ncomp-1 << " )" ;
287
281
amrex::Abort (ss.str ());
288
282
))
@@ -292,15 +286,19 @@ namespace amrex {
292
286
293
287
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
294
288
CellData<T> cellData (int i, int j, int k) const noexcept {
295
- return CellData<T>{this ->ptr (i,j,k), nstride, ncomp};
289
+ return CellData<T>{this ->ptr (i,j,k), nstride () , ncomp};
296
290
}
297
291
};
298
292
299
293
template <class Tto , class Tfrom >
300
294
[[nodiscard]] AMREX_GPU_HOST_DEVICE
301
295
Array4<Tto> ToArray4 (Array4<Tfrom> const & a_in) noexcept
302
296
{
303
- return Array4<Tto>((Tto*)(a_in.p ), a_in.begin , a_in.end , a_in.ncomp );
297
+ return Array4<Tto>((Tto*)(a_in.p ), a_in.begin ,
298
+ Dim3{a_in.begin .x + a_in.len .x ,
299
+ a_in.begin .y + a_in.len .y ,
300
+ a_in.begin .z + a_in.len .z },
301
+ a_in.ncomp );
304
302
}
305
303
306
304
template <class T >
@@ -314,14 +312,21 @@ namespace amrex {
314
312
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
315
313
Dim3 ubound (Array4<T> const & a) noexcept
316
314
{
317
- return Dim3{a.end .x -1 ,a.end .y -1 ,a.end .z -1 };
315
+ return Dim3{a.begin .x +a.len .x -1 ,a.begin .y +a.len .y -1 ,a.begin .z +a.len .z -1 };
316
+ }
317
+
318
+ template <class T >
319
+ [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
320
+ Dim3 end (Array4<T> const & a) noexcept
321
+ {
322
+ return Dim3{a.begin .x +a.len .x ,a.begin .y +a.len .y ,a.begin .z +a.len .z };
318
323
}
319
324
320
325
template <class T >
321
326
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
322
327
Dim3 length (Array4<T> const & a) noexcept
323
328
{
324
- return Dim3{a. end . x -a. begin . x ,a. end . y -a. begin . y ,a. end . z -a. begin . z } ;
329
+ return a. len ;
325
330
}
326
331
327
332
template <typename T>
0 commit comments