Skip to content

Commit

Permalink
Merge pull request #455 from kubagalecki/kernel-arg-refactor
Browse files Browse the repository at this point in the history
Constant memory refactor
  • Loading branch information
llaniewski authored Oct 23, 2023
2 parents 365770c + 0890776 commit 57dd196
Show file tree
Hide file tree
Showing 22 changed files with 667 additions and 652 deletions.
28 changes: 15 additions & 13 deletions src/CartLatticeAccess.hpp.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,23 @@ class CartLatticeAccess {
const z_t z;
const flag_t nt;
const range_int<0,1,0,1> nx, ny, nz;
const CartLatticeContainer* container;
public:
CudaDeviceFunction CartLatticeAccess(const int& x_, const int& y_, const int& z_) :
CudaDeviceFunction CartLatticeAccess(const int& x_, const int& y_, const int& z_, const CartLatticeContainer& container_) :
x(x_),y(y_),z(z_),
nt(fetchNodeType(constContainer, x, y, z)),
nx(constContainer.nx),ny(constContainer.ny),nz(constContainer.nz)
nt(fetchNodeType(container_, x, y, z)),
nx(container_.nx),ny(container_.ny),nz(container_.nz),
container(&container_)
{ }
CudaDeviceFunction real_t getX() const { return constContainer.px + x; }
CudaDeviceFunction real_t getY() const { return constContainer.py + y; }
CudaDeviceFunction real_t getZ() const { return constContainer.pz + z; }
CudaDeviceFunction real_t getX() const { return container->px + x; }
CudaDeviceFunction real_t getY() const { return container->py + y; }
CudaDeviceFunction real_t getZ() const { return container->pz + z; }
CudaDeviceFunction flag_t getNodeType() const { return nt; }

CudaDeviceFunction inline cut_t getQ(const int& d) const {
if (constContainer.Q == NULL) return NO_CUT;
if (!container->Q) return NO_CUT;
size_t i = ((((size_t)d)*nz+z)*ny+y)*nx+x;
return constContainer.Q[i];
return container->Q[i];
}

<?R for (f in rows(Fields)) { ?>
Expand All @@ -299,7 +301,7 @@ template <class dx_t, class dy_t, class dz_t>
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
{
storage_t ret; <?R
con = make.context("constContainer.in");
con = make.context("container->in");
p = PV(c("x","y","z"));
dp = PV(c("dx","dy","dz"));
if (f$minx == f$maxx) dp[1] = f$minx
Expand All @@ -318,7 +320,7 @@ template <class N>
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::pop<?%s s$suffix ?>(N & node) const
{
storage_t val; <?R
con = make.context("constContainer.in",pocket=TRUE);
con = make.context("container->in",pocket=TRUE);
for (d in rows(Density)[s$load.densities]) {
f = rows(Fields)[[match(d$field, Fields$name)]]
dp = c(-d$dx, -d$dy, -d$dz)
Expand All @@ -332,7 +334,7 @@ template <class N>
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>(N & node) const
{
storage_t val; <?R
con = make.context("constContainer.out",pocket=TRUE);
con = make.context("container->out",pocket=TRUE);
for (f in rows(Fields)[s$save.fields]) { ?>
val = <?%s real_to_storage(paste("node",f$name,sep="."),f) ?>; <?R
con=save.field("val", f, p, con)
Expand All @@ -344,7 +346,7 @@ template < class x_t, class y_t, class z_t >
template <class N>
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::push<?%s s$suffix ?>_adj(N & node) const
{ <?R
con = make.context("constContainer.adjout",pocket=TRUE);
con = make.context("container->adjout",pocket=TRUE);
for (d in rows(Density)[s$load.densities]) {
f = rows(Fields)[[match(d$field, Fields$name)]]
dp = c(-d$dx, -d$dy, -d$dz)
Expand All @@ -357,7 +359,7 @@ template < class x_t, class y_t, class z_t >
template <class N>
CudaDeviceFunction void CartLatticeAccess< x_t, y_t, z_t >::pop<?%s s$suffix ?>_adj(N & node) const
{ <?R
con = make.context("constContainer.adjin",pocket=TRUE);
con = make.context("container->adjin",pocket=TRUE);
for (f in rows(Fields)[s$save.fields]) {
val = paste("node",f$adjoint_name,sep=".")
con = field.access( d=val, f, p, pattern="put", access="getsum", MContext=con)
Expand Down
Loading

0 comments on commit 57dd196

Please sign in to comment.