Skip to content

Commit 96b5fae

Browse files
authored
Merge pull request #454 from kubagalecki/develop
Refactor in preparation for arbitrary grid development
2 parents d66b8b3 + 86dd7a4 commit 96b5fae

23 files changed

+1068
-1148
lines changed

src/LatticeAccess.inc.cpp.Rt renamed to src/CartLatticeAccess.hpp.Rt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
source("conf.R")
33
c_header()
44
?>
5-
/** \file LatticeAccess.cu
5+
/** \file CartLatticeAccess.hpp
66
*/
77

8+
#ifndef LATTICEACCESS_HPP
9+
#define LATTICEACCESS_HPP
10+
811
#include "Consts.h"
912
#include "Global.h"
10-
#include "Lattice.h"
1113
#include <mpi.h>
1214
#include "range_int.hpp"
15+
#include "CartLatticeContainer.h"
1316

1417
#ifndef STORAGE_BITS
1518
#define storage_to_real(x__) x__
@@ -34,12 +37,6 @@
3437
#define real_to_storage_shift(x__,y__) real_to_storage(x__)
3538
#endif
3639

37-
/// Get only type of node
38-
CudaDeviceFunction flag_t LatticeContainer::getType(int x, int y, int z) const
39-
{
40-
return NodeType[(x + nx*(y + ny*z))];
41-
}
42-
4340
/// Push all densities
4441

4542
<?R
@@ -253,18 +250,22 @@ resolve.symmetries = function(D) {
253250

254251
?>
255252

253+
CudaDeviceFunction flag_t fetchNodeType(const CartLatticeContainer& container, int x, int y, int z) {
254+
return container.NodeType[(x + container.nx*(y + container.ny*z))];
255+
}
256+
256257
template < class x_t, class y_t, class z_t >
257-
class LatticeAccess {
258+
class CartLatticeAccess {
258259
private:
259260
const x_t x;
260261
const y_t y;
261262
const z_t z;
262263
const flag_t nt;
263264
const range_int<0,1,0,1> nx, ny, nz;
264265
public:
265-
CudaDeviceFunction LatticeAccess(const int& x_, const int& y_, const int& z_) :
266+
CudaDeviceFunction CartLatticeAccess(const int& x_, const int& y_, const int& z_) :
266267
x(x_),y(y_),z(z_),
267-
nt(constContainer.getType(x,y,z)),
268+
nt(fetchNodeType(constContainer, x, y, z)),
268269
nx(constContainer.nx),ny(constContainer.ny),nz(constContainer.nz)
269270
{ }
270271
CudaDeviceFunction real_t getX() const { return constContainer.px + x; }
@@ -295,7 +296,7 @@ class LatticeAccess {
295296
<?R for (f in rows(Fields)) { ?>
296297
template < class x_t, class y_t, class z_t >
297298
template <class dx_t, class dy_t, class dz_t>
298-
CudaDeviceFunction real_t LatticeAccess< x_t, y_t, z_t >::load_<?%s f$nicename ?> (const dx_t & dx, const dy_t & dy, const dz_t & dz) const
299+
CudaDeviceFunction real_t CartLatticeAccess< x_t, y_t, z_t >::load_<?%s f$nicename ?> (const dx_t & dx, const dy_t & dy, const dz_t & dz) const
299300
{
300301
storage_t ret; <?R
301302
con = make.context("constContainer.in");
@@ -314,7 +315,7 @@ CudaDeviceFunction real_t LatticeAccess< x_t, y_t, z_t >::load_<?%s f$nicename ?
314315
for (s in rows(all_stages)) { ?>
315316
template < class x_t, class y_t, class z_t >
316317
template <class N>
317-
CudaDeviceFunction void LatticeAccess< x_t, y_t, z_t >::pop<?%s s$suffix ?>(N & node) const
318+
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::pop<?%s s$suffix ?>(N & node) const
318319
{
319320
storage_t val; <?R
320321
con = make.context("constContainer.in",pocket=TRUE);
@@ -328,7 +329,7 @@ CudaDeviceFunction void LatticeAccess< x_t, y_t, z_t >::pop<?%s s$suffix ?>(N &
328329

329330
template < class x_t, class y_t, class z_t >
330331
template <class N>
331-
CudaDeviceFunction void LatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>(N & node) const
332+
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>(N & node) const
332333
{
333334
storage_t val; <?R
334335
con = make.context("constContainer.out",pocket=TRUE);
@@ -341,7 +342,7 @@ CudaDeviceFunction void LatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>(N &
341342
<?R if (ADJOINT) { ?>
342343
template < class x_t, class y_t, class z_t >
343344
template <class N>
344-
CudaDeviceFunction void LatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>_adj(N & node) const
345+
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>_adj(N & node) const
345346
{ <?R
346347
con = make.context("constContainer.adjout",pocket=TRUE);
347348
for (d in rows(Density)[s$load.densities]) {
@@ -354,7 +355,7 @@ CudaDeviceFunction void LatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>_adj
354355

355356
template < class x_t, class y_t, class z_t >
356357
template <class N>
357-
CudaDeviceFunction void LatticeAccess< x_t, y_t, z_t >::pop<?%s s$suffix ?>_adj(N & node) const
358+
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::pop<?%s s$suffix ?>_adj(N & node) const
358359
{ <?R
359360
con = make.context("constContainer.adjin",pocket=TRUE);
360361
for (f in rows(Fields)[s$save.fields]) {
@@ -478,3 +479,4 @@ public:
478479
template < class ACC >
479480
using AccessComposite = <?%s str ?>;
480481

482+
#endif // LATTICEACCESS_HPP

src/CartLatticeContainer.h.Rt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?R
2+
source("conf.R");
3+
c_header()
4+
?>
5+
/** \file CartLatticeContainer.h
6+
File defining CartLatticeContainer and some additional CUDA functions
7+
*/
8+
9+
#ifndef LATTICECONTAINER_H
10+
#define LATTICECONTAINER_H
11+
12+
#include "Consts.h"
13+
#include "Global.h"
14+
15+
/// Main data structure for the lattice
16+
/**
17+
Main data structure for storing solution (Snapshots)
18+
in the lattice. It stores the internal part of the fields
19+
and margins.
20+
*/
21+
struct FTabs { <?R
22+
for (m in NonEmptyMargin) { ?>
23+
storage_t* <?%s m$name ?>; ///< Data on [<?%2d m$dx ?>,<?%2d m$dy?>,<?%2d m$dz?>] margin<?R
24+
} ?>
25+
void Clear(int,int,int);
26+
void PreAlloc(int,int,int);
27+
void Free();
28+
};
29+
30+
/// Container class used for storing all the data needed on GPU
31+
/**
32+
Main class for storing the data needed on GPU and running kernels.
33+
CartLatticeContainer is the container class which
34+
owns all the data needed by the kernels on device
35+
like pointers to the global gpu memory etc.
36+
It defines push/pop functions allowing access
37+
to node data stored in memory.
38+
*/
39+
class CartLatticeContainer {
40+
public:
41+
FTabs in; ///< Main FTabs used for Primal iteration as input
42+
FTabs out; ///< Main FTabs used for Primal iteration as output
43+
#ifdef ADJOINT
44+
FTabs adjout; ///< FTabs used for Adjoint iteration as output
45+
FTabs adjin; ///< FTabs used for Adjoint iteration as input
46+
#endif
47+
flag_t * NodeType; ///< Table of flags/NodeTypes of all the nodes
48+
cut_t* Q;
49+
int nx, ny, nz; ///< Size of the Lattice region
50+
real_t px,py,pz;
51+
};
52+
53+
static_assert(std::is_trivially_copyable<CartLatticeContainer>::value, "CartLatticeContainer must be trivially copyable");
54+
55+
#endif // LATTICECONTAINER_H

src/CartLatticeExecutor.h.Rt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?R
2+
source("conf.R")
3+
c_header();
4+
?>
5+
/** \file CartLatticeExecutor.h
6+
*/
7+
8+
#ifndef CARTLATTICEEXECUTOR_H
9+
#define CARTLATTICEEXECUTOR_H
10+
11+
#include "CartLatticeContainer.h"
12+
#include "LatticeData.hpp"
13+
14+
struct CartLatticeExecutor {
15+
CartLatticeContainer container;
16+
LatticeData data;
17+
18+
template < eOperationType I, eCalculateGlobals G, eStage S >
19+
void RunBorder(CudaStream_t stream) const;
20+
template < eOperationType I, eCalculateGlobals G, eStage S >
21+
void RunInterior(CudaStream_t stream) const;
22+
void Color(uchar4 *out_ptr);
23+
24+
void CopyToConst() const;
25+
26+
template < eOperationType I, eCalculateGlobals G, eStage S >
27+
static CudaDeviceFunction void NodeToColor(int x, int y, int z, uchar4 *optr);
28+
};
29+
30+
CudaGlobalFunction void ColorKernel(uchar4 *optr, int z);
31+
32+
<?R
33+
for (q in rows(Quantities)) { ifdef(q$adjoint);
34+
if (q$adjoint) {
35+
node = "Node_Adj"
36+
} else {
37+
node = "Node"
38+
}
39+
?>
40+
CudaGlobalFunction void get<?%s q$name ?>(lbRegion r, <?%s q$type ?> * tab, real_t scale); <?R
41+
for (tp in c("float","double"))
42+
{ ?>
43+
CudaGlobalFunction void get<?%s q$name ?>_<?%s tp ?>(lbRegion , <?%s tp ?> *, int);
44+
<?R
45+
}
46+
}
47+
ifdef() ?>
48+
49+
#endif // CARTLATTICEEXECUTOR_H

0 commit comments

Comments
 (0)