Skip to content

Commit

Permalink
Fix child info
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Jul 4, 2023
1 parent c1326a3 commit f51c845
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 71 deletions.
4 changes: 2 additions & 2 deletions libNeonDomain/include/Neon/domain/details/bGrid/bIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class bIndex
NEON_CUDA_HOST_DEVICE inline auto getDataBlockIdx() const -> DataBlockIdx const&;
NEON_CUDA_HOST_DEVICE inline auto setInDataBlockIdx(InDataBlockIdx const&) -> void;
NEON_CUDA_HOST_DEVICE inline auto setDataBlockIdx(DataBlockIdx const&) -> void;
NEON_CUDA_HOST_DEVICE inline auto isActive() -> bool;
NEON_CUDA_HOST_DEVICE inline auto isActive() const -> bool;
// the local index within the block
InDataBlockIdx mInDataBlockIdx;
DataBlockIdx mDataBlockIdx{};
Expand Down Expand Up @@ -132,7 +132,7 @@ NEON_CUDA_HOST_DEVICE auto bIndex<SBlock>::getInDataBlockIdx() const -> const bI
}

template <typename SBlock>
NEON_CUDA_HOST_DEVICE auto bIndex<SBlock>::isActive() -> bool
NEON_CUDA_HOST_DEVICE auto bIndex<SBlock>::isActive() const -> bool
{
return mDataBlockIdx != std::numeric_limits<typename bIndex::DataBlockIdx>::max();
}
Expand Down
40 changes: 20 additions & 20 deletions libNeonDomain/include/Neon/domain/details/mGrid/mPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,42 @@ class mPartition : public Neon::domain::details::bGrid::bPartition<T, C, kStatic

~mPartition() = default;

explicit mPartition(int level,
T* mem,
T* memParent,
T* memChild,
int cardinality,
uint32_t* neighbourBlocks,
Neon::int32_3d* origin,
uint32_t* parent,
MaskT* mask,
MaskT* maskLowerLevel,
MaskT* maskUpperLevel,
uint32_t* childBlockID,
uint32_t* parentNeighbourBlocks,
NghIdx* stencilNghIndex,
int* refFactors,
int* spacing);
explicit mPartition(int level,
T* mem,
T* memParent,
T* memChild,
int cardinality,
Idx::DataBlockIdx* neighbourBlocks,
Neon::int32_3d* origin,
Idx::DataBlockIdx* parent,
MaskT* mask,
MaskT* maskLowerLevel,
MaskT* maskUpperLevel,
Idx::DataBlockIdx* childBlockID,
Idx::DataBlockIdx* parentNeighbourBlocks,
NghIdx* stencilNghIndex,
int* refFactors,
int* spacing);

/**
* get the child of a cell
* @param parent_cell the parent at which the child is queried
* @param parentCell the parent at which the child is queried
* @param child which child to return. A cell has number of children defined by the branching factor
* at the level. This defines the 3d local index of the child
* @param card which cardinality is desired from the child
* @param alternativeVal in case the child requested is not present
*/
NEON_CUDA_HOST_DEVICE inline auto childVal(const Idx& parent_cell,
NEON_CUDA_HOST_DEVICE inline auto childVal(const Idx& parentCell,
const NghIdx child,
int card,
const T& alternativeVal) const -> NghData;

/**
* Get a cell that represents the child of a parent cell
* @param parent_cell the parent cell that its child is requested
* @param parentCell the parent cell that its child is requested
* @param child the child 3d local index relative to the parent
*/
NEON_CUDA_HOST_DEVICE inline auto getChild(const Idx& parent_cell,
NEON_CUDA_HOST_DEVICE inline auto getChild(const Idx& parentCell,
NghIdx child) const -> Idx;


Expand Down
61 changes: 27 additions & 34 deletions libNeonDomain/include/Neon/domain/details/mGrid/mPartition_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ mPartition<T, C>::mPartition(int level,
int cardinality,
Idx::DataBlockIdx* neighbourBlocks,
Neon::int32_3d* origin,
uint32_t* parentBlockID,
Idx::DataBlockIdx* parentBlockID,
MaskT* mask,
MaskT* maskLowerLevel,
MaskT* maskUpperLevel,
uint32_t* childBlockID,
uint32_t* parentNeighbourBlocks,
Idx::DataBlockIdx* childBlockID,
Idx::DataBlockIdx* parentNeighbourBlocks,
NghIdx* stencilNghIndex,
int* refFactors,
int* spacing)
Expand Down Expand Up @@ -75,35 +75,28 @@ NEON_CUDA_HOST_DEVICE inline auto mPartition<T, C>::getSpacing(const int level)
template <typename T, int C>
inline NEON_CUDA_HOST_DEVICE auto mPartition<T, C>::childID(const Idx& gidx) const -> uint32_t
{
// return the child block id corresponding to this cell
// the child block id lives at level mLevel-1

//const uint32_t childPitch =
// // stride across all block before cell's block
// gidx.getDataBlockIdx() *
// gidx.memBlock3DSize.x * gidx.memBlock3DSize * gidx.memBlock3DSize +
// // stride within the block
// gidx.getInDataBlockIdx().x +
// gidx.getInDataBlockIdx().y * gidx.memBlock3DSize.x +
// gidx.getInDataBlockIdx().z * gidx.memBlock3DSize.x * gidx.memBlock3DSize.y;
//
//return mChildBlockID[childPitch];
return std::numeric_limits<uint32_t>::max();
// return the child block id corresponding to this gidx
//
// gidx.mDataBlockIdx * kMemBlockSizeX * kMemBlockSizeY * kMemBlockSizeZ +
// (i + j * kUserBlockSizeX + k * kUserBlockSizeX * kUserBlockSizeY) * kUserBlockSizeX* kUserBlockSizeY* kUserBlockSizeZ +
// x + y* refFactor + z* refFactor* refFactor
return mChildBlockID[this->helpGetPitch(gidx, 0)];
}

template <typename T, int C>
NEON_CUDA_HOST_DEVICE inline auto mPartition<T, C>::getChild(const Idx& parent_cell,
NEON_CUDA_HOST_DEVICE inline auto mPartition<T, C>::getChild(const Idx& parentCell,
NghIdx child) const -> Idx
{
Idx childCell;
childCell.mDataBlockIdx = std::numeric_limits<typename Idx::DataBlockIdx>::max();

//if (hasChildren(parent_cell)) {
// childCell.mDataBlockIdx = childID(parent_cell);
// childCell.mInDataBlockIdx.x = child.x;
// childCell.mInDataBlockIdx.y = child.y;
// childCell.mInDataBlockIdx.z = child.z;
//}
if (hasChildren(parentCell)) {
childCell.mDataBlockIdx = childID(parentCell);
int ref = getRefFactor(mLevel);
childCell.mInDataBlockIdx.x = (ref * parentCell.mInDataBlockIdx.x + child.x) % kMemBlockSizeX;
childCell.mInDataBlockIdx.y = (ref * parentCell.mInDataBlockIdx.y + child.y) % kMemBlockSizeY;
childCell.mInDataBlockIdx.z = (ref * parentCell.mInDataBlockIdx.z + child.z) % kMemBlockSizeZ;
}
return childCell;
}

Expand All @@ -123,26 +116,26 @@ NEON_CUDA_HOST_DEVICE inline auto mPartition<T, C>::childVal(const Idx& childCel
}

template <typename T, int C>
NEON_CUDA_HOST_DEVICE inline auto mPartition<T, C>::childVal(const Idx& parent_cell,
NEON_CUDA_HOST_DEVICE inline auto mPartition<T, C>::childVal(const Idx& parentCell,
const NghIdx child,
int card,
const T& alternativeVal) const -> NghData
{
NghData ret;
ret.mData = alternativeVal;
ret.mIsValid = false;
//if (!parent_cell.mIsActive || !hasChildren(parent_cell)) {
// return ret;
//}
if (!parentCell.isActive() || !hasChildren(parentCell)) {
return ret;
}

//Idx child_cell = getChild(parent_cell, child);
Idx childCell = getChild(parentCell, child);

//if (!child_cell.mIsActive) {
// return ret;
//}
if (!childCell.isActive()) {
return ret;
}

//ret.mIsValid = true;
//ret.mData = childVal(child_cell, card);
ret.mIsValid = true;
ret.mData = childVal(childCell, card);

return ret;
}
Expand Down
15 changes: 7 additions & 8 deletions libNeonDomain/src/domain/details/mGrid/mGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,15 @@ mGrid::mGrid(

auto [setIdx, childBlockID] = mData->grids[l - 1].helpGetSetIdxAndGridIdx(childId);

uint32_t pitch = blockIdx * kMemBlockSizeX * kMemBlockSizeY * kMemBlockSizeZ +
(i * kUserBlockSizeX + x) +
(j * kUserBlockSizeY + y) * kMemBlockSizeY +
(k * kUserBlockSizeZ + z) * kMemBlockSizeY * kMemBlockSizeZ;

if (setIdx.idx() == -1) {
mData->mChildBlockID[l].eRef(devID,
blockIdx * kMemBlockSizeX * kMemBlockSizeY * kMemBlockSizeZ +
(i + j * kUserBlockSizeX + k * kUserBlockSizeX * kUserBlockSizeY) * kUserBlockSizeX * kUserBlockSizeY * kUserBlockSizeZ +
x + y * refFactor + z * refFactor * refFactor) = std::numeric_limits<Idx::DataBlockIdx>::max();
mData->mChildBlockID[l].eRef(devID, pitch) = std::numeric_limits<Idx::DataBlockIdx>::max();
} else {
mData->mChildBlockID[l].eRef(devID,
blockIdx * kMemBlockSizeX * kMemBlockSizeY * kMemBlockSizeZ +
(i + j * kUserBlockSizeX + k * kUserBlockSizeX * kUserBlockSizeY) * kUserBlockSizeX * kUserBlockSizeY * kUserBlockSizeZ +
x + y * refFactor + z * refFactor * refFactor) = childBlockID.getDataBlockIdx();
mData->mChildBlockID[l].eRef(devID, pitch) = childBlockID.getDataBlockIdx();
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions libNeonSkeleton/tests/unit/sUt_multiRes/src/MultiResChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ void MultiResChild()
const Neon::index_3d dim(24, 24, 24);
const std::vector<int> gpuIds(nGPUs, 0);

const Neon::domain::mGridDescriptor descriptor({1, 1, 1});
Neon::mGridDescriptor<1> descriptor(3);

for (auto runtime : {Neon::Runtime::openmp, Neon::Runtime::stream}) {
for (auto runtime : {Neon::Runtime::openmp /*, Neon::Runtime::stream*/}) {

auto bk = Neon::Backend(gpuIds, runtime);

Expand All @@ -32,7 +32,7 @@ void MultiResChild()
}},
Neon::domain::Stencil::s7_Laplace_t(),
descriptor);

auto XField = grid.newField<Type>("XField", 1, -1);
auto isRefinedField = grid.newField<Type>("isRefined", 1, -1);

Expand All @@ -59,18 +59,18 @@ void MultiResChild()

for (int level = 0; level < descriptor.getDepth(); ++level) {

auto container = grid.getContainer(
auto container = grid.newContainer(

"hasChildren", level, [&, level, descriptor](Neon::set::Loader& loader) {
auto& xLocal = XField.load(loader, level, Neon::MultiResCompute::MAP);
auto& isRefinedLocal = isRefinedField.load(loader, level, Neon::MultiResCompute::MAP);


return [=] NEON_CUDA_HOST_DEVICE(const Neon::domain::mGrid::Cell& cell) mutable {
return [=] NEON_CUDA_HOST_DEVICE(const Neon::domain::mGrid::Idx& cell) mutable {
if (xLocal.hasChildren(cell)) {
isRefinedLocal(cell, 0) = 1;

Neon::index_3d cellOrigin = xLocal.mapToGlobal(cell);
Neon::index_3d cellOrigin = xLocal.getGlobalIndex(cell);

const int refFactor = xLocal.getRefFactor(level - 1);

Expand Down Expand Up @@ -136,4 +136,4 @@ TEST(MultiRes, Child)
if (Neon::sys::globalSpace::gpuSysObjStorage.numDevs() > 0) {
MultiResChild();
}
}
}

0 comments on commit f51c845

Please sign in to comment.