18#include <hip/hip_runtime.h>
22#if defined(__CUDACC__) || defined(__HIP__)
23#define FORCUDA __host__ __device__
34template<
unsigned base,
unsigned exp>
40template<
unsigned base>
42 static constexpr unsigned value = 1;
55 std::shared_ptr<bElem>
dat;
73 [](
bElem *p) { free(p); });
96template<
unsigned dims>
130template<
unsigned ... Ds>
142template<
unsigned ... xs>
151 static constexpr unsigned value = x;
159template<
unsigned x,
unsigned ... xs>
161 static constexpr unsigned value = x *
cal_size<xs ...>::value;
173template<
unsigned ... offs>
180template<
unsigned off>
182 static constexpr unsigned value = off;
191template<
unsigned dim,
unsigned off,
unsigned ...offs>
231 par(par), b(b), pos(pos), nvec(nvec), wvec(wvec) {
237 unsigned dir = i + D;
238 unsigned d = pos * 3 + dir / D;
240 unsigned l = dir % D;
241 unsigned w = wvec * F + l % F;
242 unsigned n = nvec * (D / F) + l / F;
243 unsigned offset = n * par->VECLEN + w;
245 return par->dat[par->bInfo->adj[b][d] * par->step + offset];
272 par(par), b(b), pos(pos), nvec(nvec), wvec(wvec) {
278 unsigned dir = i + D;
279 unsigned d = pos * 3 + dir / D;
281 unsigned l = dir % D;
282 unsigned w = wvec * F + l % F;
283 unsigned n = nvec * (D / F) + l / F;
310 par(par), b(b), pos(pos), nvec(nvec), wvec(wvec) {
315 typename std::conditional<
sizeof...(BDims) ==
sizeof...(Folds), bool,
void>::type>
318 unsigned dir = i + D;
319 unsigned d = pos * 3 + dir / D;
321 unsigned l = dir % D;
323 unsigned n = nvec * D + l;
325 typename std::conditional<
sizeof...(BDims) ==
sizeof...(Folds), bool,
void>::type>(par, b, d, n, w);
360 static constexpr unsigned VECLEN =
cal_size<Folds...>::value;
361 static constexpr unsigned BRICKSIZE =
cal_size<BDims...>::value;
371 typename std::conditional<
sizeof...(BDims) ==
sizeof...(Folds), bool,
void>::type>
operator[](
unsigned b) {
373 typename std::conditional<
sizeof...(BDims) ==
sizeof...(Folds), bool,
void>::type>(
this, b, 0, 0, 0);
377 template<
unsigned ... Offsets>
380 unsigned off =
cal_offs<
sizeof...(BDims), Offsets...>::value;
381 return &dat[bInfo->
adj[b][off] * step];
391 bStorage = brickStorage;
392 dat = bStorage.
dat.get() + offset;
393 step = (unsigned) bStorage.
step;
#define FORCUDA
Overloaded attributes for potentially GPU-usable functions (in place of host device etc....
Definition: brick.h:25
#define ALIGN
BrickStorage allocation alignment.
Definition: brick.h:15
Metadata related to bricks.
Definition: brick.h:97
unsigned(* adjlist)[static_power< 3, dims >::value]
Adjacency list type.
Definition: brick.h:99
unsigned nbricks
Number of bricks in this list.
Definition: brick.h:103
adjlist adj
Adjacency list.
Definition: brick.h:101
BrickInfo(unsigned nbricks)
Creating an empty metadata consisting of the specified number of bricks.
Definition: brick.h:109
BrickStorage mmap_alloc(long step)
Allocate a new brick storage BrickStorage::mmap_alloc(long, long)
Definition: brick.h:119
BrickStorage allocate(long step)
Allocate a new brick storage BrickStorage::allocate()
Definition: brick.h:114
BrickStorage mmap_alloc(long step, void *mmap_fd, size_t offset)
Allocate a new brick storage BrickStorage::mmap_alloc(long, long, void*, size_t)
Definition: brick.h:124
Initializing and holding the storage of bricks.
Definition: brick.h:53
std::shared_ptr< bElem > dat
Pointer holding brick data.
Definition: brick.h:55
long chunks
Number of chunks.
Definition: brick.h:61
static BrickStorage allocate(long chunks, size_t step)
Allocation using *alloc.
Definition: brick.h:68
void * mmap_info
MMAP data structure when using mmap as allocator.
Definition: brick.h:65
static BrickStorage mmap_alloc(long chunks, long step)
mmap allocator using default (new) file
Definition: memfd.cpp:103
size_t step
Size of a chunk in number of elements.
Definition: brick.h:63
Brick data structure.
Definition: brick.h:356
BrickStorage bStorage
Definition: brick.h:366
Brick< Dim< BDims... >, Dim< Folds... > > mytype
Shorthand for this struct's type.
Definition: brick.h:357
FORCUDA bElem * neighbor(unsigned b)
Return the adjacency list of brick b
Definition: brick.h:379
size_t step
Spacing between bricks in unit of bElem (BrickStorage)
Definition: brick.h:364
myBrickInfo * bInfo
Pointer to (possibly shared) metadata.
Definition: brick.h:363
bElem * dat
Offsetted memory (BrickStorage)
Definition: brick.h:365
FORCUDA _BrickAccessor< mytype, Dim< BDims... >, Dim< Folds... >, typename std::conditional< sizeof...(BDims)==sizeof...(Folds), bool, void >::type > operator[](unsigned b)
Indexing operator returns: Accessing brick elements using [].
Definition: brick.h:371
Brick(myBrickInfo *bInfo, const BrickStorage &brickStorage, unsigned offset)
Initialize a brick data structure.
Definition: brick.h:390
Generic base template, see Brick< Dim< BDims... >, Dim< Folds... > >
Definition: brick.h:340
Empty template to specify an n-D list.
Definition: brick.h:131
unsigned nvec
Which vector.
Definition: brick.h:267
unsigned wvec
Position within a vector.
Definition: brick.h:268
T * par
parent Brick data structure reference
Definition: brick.h:263
unsigned pos
Accumulative position within adjacency list.
Definition: brick.h:266
FORCUDA _BrickAccessor< T, Dim< BDims... >, Dim< Folds... >, bool > operator[](unsigned i)
Definition: brick.h:276
FORCUDA _BrickAccessor(T *par, unsigned b, unsigned pos, unsigned nvec, unsigned wvec)
Definition: brick.h:271
unsigned b
Reference (center) brick.
Definition: brick.h:265
FORCUDA _BrickAccessor(T *par, unsigned b, unsigned pos, unsigned nvec, unsigned wvec)
Definition: brick.h:309
unsigned nvec
Which vector.
Definition: brick.h:305
unsigned b
Reference (center) brick.
Definition: brick.h:303
unsigned pos
Accumulative position within adjacency list.
Definition: brick.h:304
T * par
parent Brick data structure reference
Definition: brick.h:301
FORCUDA _BrickAccessor< T, Dim< BDims... >, Dim< Folds... >, typename std::conditional< sizeof...(BDims)==sizeof...(Folds), bool, void >::type > operator[](unsigned i)
Definition: brick.h:316
unsigned wvec
Position within a vector.
Definition: brick.h:306
T * par
parent Brick data structure reference
Definition: brick.h:222
FORCUDA bElem & operator[](unsigned i)
Definition: brick.h:235
unsigned wvec
Position within a vector.
Definition: brick.h:227
FORCUDA _BrickAccessor(T *par, unsigned b, unsigned pos, unsigned nvec, unsigned wvec)
Definition: brick.h:230
unsigned b
Reference (center) brick.
Definition: brick.h:224
unsigned nvec
Which vector.
Definition: brick.h:226
unsigned pos
Accumulative position within adjacency list.
Definition: brick.h:225
Generic base template for Accessing brick elements using [].
Definition: brick.h:215
Generic base template for Calculating the offset within the adjacency list.
Definition: brick.h:174
Generic base template for Calculate the product of n numbers in a template.
Definition: brick.h:143
Compute Statically compute exponentials.
Definition: brick.h:35
static constexpr unsigned value
Definition: brick.h:36
Interface to code generator.
#define bElem
Basic datatype for all brick elements.
Definition: vecscatter.h:13