Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
massimim committed Feb 7, 2024
1 parent 77edf29 commit 475b95b
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 111 deletions.
7 changes: 7 additions & 0 deletions libNeonDomain/include/Neon/domain/details/bGridDisg/bGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ class bGrid : public Neon::domain::interface::GridBaseTemplate<bGrid<SBlock>,
*/
auto helpGetSetIdxAndGridIdx(Neon::index_3d idx) const -> std::tuple<Neon::SetIdx, Idx>;

template <typename ActiveCellLambda>
auto init_mask_field(ActiveCellLambda activeCellLambda) -> void;
auto helpGetClassField() -> Field<uint8_t, 1>&;

struct Data
{
auto init(const Neon::Backend& bk)
Expand Down Expand Up @@ -258,6 +262,9 @@ class bGrid : public Neon::domain::interface::GridBaseTemplate<bGrid<SBlock>,

AlphaGrid alphaGrid;
BetaGrid betaGrid;

Field<uint8_t, 1> maskClassField;

};
std::shared_ptr<Data> mData;
};
Expand Down
47 changes: 42 additions & 5 deletions libNeonDomain/include/Neon/domain/details/bGridDisg/bGrid_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ bGrid<SBlock>::bGrid(const Neon::Backend& backend,

mData->alphaGrid = details::cGrid::cGrid<SBlock, int(details::cGrid::ClassSelector::alpha)>(*this);
mData->betaGrid = details::cGrid::cGrid<SBlock, int(details::cGrid::ClassSelector::beta)>(*this);
init_mask_field(activeCellLambda);
}

template <typename SBlock>
Expand Down Expand Up @@ -332,11 +333,11 @@ auto bGrid<SBlock>::newContainer(const std::string& name,
{
const Neon::index_3d& defaultBlockSize = this->getDefaultBlock();
Neon::set::Container kContainer = Neon::set::Container::factory<execution>(name,
Neon::set::internal::ContainerAPI::DataViewSupport::on,
*this,
lambda,
defaultBlockSize,
[](const Neon::index_3d&) { return 0; });
Neon::set::internal::ContainerAPI::DataViewSupport::on,
*this,
lambda,
defaultBlockSize,
[](const Neon::index_3d&) { return 0; });
return kContainer;
}

Expand Down Expand Up @@ -534,4 +535,40 @@ auto bGrid<SBlock>::helpGetPartitioner1D() -> Neon::domain::tool::Partitioner1D&
return mData->partitioner1D;
}

template <typename SBlock>
template <typename ActiveCellLambda>
auto bGrid<SBlock>::init_mask_field([[maybe_unused]] ActiveCellLambda activeCellLambda) -> void
{
using returTypeOfLambda = typename std::invoke_result<ActiveCellLambda, Neon::index_3d>::type;
if constexpr (std::is_same_v<returTypeOfLambda, details::cGrid::ClassSelector>) {


auto maskField = this->newField<uint8_t, 1>("maskField", 1, 0, Neon::DataUse::HOST_DEVICE);
maskField.getGrid().template newContainer<Neon::Execution::host>(
"maskFieldInit",
[&](Neon::set::Loader& loader) {
auto maskFieldPartition = loader.load(maskField);
return [activeCellLambda, maskFieldPartition] (const auto& gIdx) mutable {
auto globalPosition = maskFieldPartition.getGlobalIndex(gIdx);
details::cGrid::ClassSelector voxelClass = activeCellLambda(globalPosition);
maskFieldPartition(gIdx, 0) = static_cast<uint8_t>(voxelClass);
// maskFieldPartition(gIdx, 0) = 33;
};
})
.run(Neon::Backend::mainStreamIdx);
this->getBackend().sync(Neon::Backend::mainStreamIdx);
maskField.updateDeviceData(Neon::Backend::mainStreamIdx);
this->getBackend().sync(Neon::Backend::mainStreamIdx);
maskField.template ioToVtk<int>("maskField", "maskField");
this->mData->maskClassField = maskField;
return;
}
}

template <typename SBlock>
auto bGrid<SBlock>::helpGetClassField() -> Field<uint8_t, 1>&
{
return mData->maskClassField;
}

} // namespace Neon::domain::details::disaggregated::bGrid
Original file line number Diff line number Diff line change
Expand Up @@ -58,83 +58,10 @@ struct GridTransformation_cGrid
Neon::DataView dataViewOfTheTableEntry,
Span& NEON_OUT span) {
typename FoundationGrid::Span const& foundationSpan = foundationGrid.getSpan(execution, setIdx, dataViewOfTheTableEntry);
span = foundationSpan;
// Neon::domain::tool::Partitioner1D const& foundationPartitioner1D = foundationGrid.helpGetPartitioner1D();
// auto const& spanLayout = foundationPartitioner1D.getSpanLayout();
// typename Idx::DataBlockCount iCountVirtualSingleClass;
// typename Idx::DataBlockCount iAndIupCountVirtualSingleClass;
// typename Idx::DataBlockCount internalClassFirstMemoryOffset;
// typename Idx::DataBlockCount bUpClassFirstMemoryOffset;
// typename Idx::DataBlockCount bDwClassFirstMemoryOffset;
//
// bool skipInternal = dataViewOfTheTableEntry == Neon::DataView::BOUNDARY;
//
// if constexpr (classSelector == ClassSelector::alpha) {
// auto const iCountVirtualAlpha = skipInternal ? 0 : spanLayout.getBoundsInternal(setIdx, Neon::domain::tool::partitioning::ByDomain::bulk).count;
// auto const iAndIupCountVirtualAlpha = iCountVirtualAlpha +
// spanLayout.getBoundsBoundary(setIdx,
// Neon::domain::tool::partitioning::ByDirection::up,
// Neon::domain::tool::partitioning::ByDomain::bulk)
// .count;
//
// iCountVirtualSingleClass = iCountVirtualAlpha;
// iAndIupCountVirtualSingleClass = iAndIupCountVirtualAlpha;
//
// internalClassFirstMemoryOffset = 0;
// bUpClassFirstMemoryOffset = spanLayout.getBoundsInternal(setIdx,
// Neon::domain::tool::partitioning::ByDomain::bc)
// .count;
// bDwClassFirstMemoryOffset = bUpClassFirstMemoryOffset +
// spanLayout.getBoundsBoundary(setIdx,
// Neon::domain::tool::partitioning::ByDirection::up,
// Neon::domain::tool::partitioning::ByDomain::bc)
// .count;
//
// span.init(foundationSpan,
// iCountVirtualSingleClass,
// iAndIupCountVirtualSingleClass,
// internalClassFirstMemoryOffset,
// bUpClassFirstMemoryOffset,
// bDwClassFirstMemoryOffset,
// dataViewOfTheTableEntry);
// }
// else {
// auto const iCountVirtualBeta = skipInternal
// ? 0
// : spanLayout.getBoundsInternal(setIdx, Neon::domain::tool::partitioning::ByDomain::bc).count;
//
// auto const iAndIupCountVirtualBeta = iCountVirtualBeta +
// spanLayout.getBoundsBoundary(setIdx,
// Neon::domain::tool::partitioning::ByDirection::up,
// Neon::domain::tool::partitioning::ByDomain::bc)
// .count;
//
// iCountVirtualSingleClass = iCountVirtualBeta;
// iAndIupCountVirtualSingleClass = iAndIupCountVirtualBeta;
//
// internalClassFirstMemoryOffset = spanLayout.getBoundsInternal(setIdx,
// Neon::domain::tool::partitioning::ByDomain::bulk)
// .count;
//
// bUpClassFirstMemoryOffset = internalClassFirstMemoryOffset +
// spanLayout.getBoundsBoundary(setIdx,
// Neon::domain::tool::partitioning::ByDirection::up,
// Neon::domain::tool::partitioning::ByDomain::bulk)
// .count;
// bDwClassFirstMemoryOffset = bUpClassFirstMemoryOffset +
// spanLayout.getBoundsBoundary(setIdx,
// Neon::domain::tool::partitioning::ByDirection::down,
// Neon::domain::tool::partitioning::ByDomain::bulk)
// .count;
//
// span.init(foundationSpan,
// iCountVirtualSingleClass,
// iAndIupCountVirtualSingleClass,
// internalClassFirstMemoryOffset,
// bUpClassFirstMemoryOffset,
// bDwClassFirstMemoryOffset,
// dataViewOfTheTableEntry);
// }
span = cSpan<SBlock, classSelector>(foundationSpan.mFirstDataBlockOffset,
foundationSpan.mActiveMask,
foundationSpan.mDataView,
foundationGrid.helpGetClassField().getPartition(execution, setIdx, dataViewOfTheTableEntry));
});
}

Expand Down
16 changes: 11 additions & 5 deletions libNeonDomain/include/Neon/domain/details/bGridDisgMask/bGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class bGrid : public Neon::domain::interface::GridBaseTemplate<bGrid<SBlock>,
using BlockIdx = uint32_t;

using AlphaGrid = typename Neon::domain::details::disaggregated::bGridMask::details::cGrid::cGrid<SBlock,
Neon::domain::details::disaggregated::bGridMask::details::cGrid::ClassSelector::alpha>;
Neon::domain::details::disaggregated::bGridMask::details::cGrid::ClassSelector::alpha>;
using BetaGrid = typename Neon::domain::details::disaggregated::bGridMask::details::cGrid::cGrid<SBlock,
Neon::domain::details::disaggregated::bGridMask::details::cGrid::ClassSelector::beta>;
Neon::domain::details::disaggregated::bGridMask::details::cGrid::ClassSelector::beta>;

bGrid() = default;
virtual ~bGrid();
Expand Down Expand Up @@ -223,6 +223,11 @@ class bGrid : public Neon::domain::interface::GridBaseTemplate<bGrid<SBlock>,
*/
auto helpGetSetIdxAndGridIdx(Neon::index_3d idx) const -> std::tuple<Neon::SetIdx, Idx>;

template <typename ActiveCellLambda>
auto init_mask_field(ActiveCellLambda activeCellLambda) -> void;
auto helpGetClassField() -> Field<uint8_t, 1>&;


struct Data
{
auto init(const Neon::Backend& bk)
Expand Down Expand Up @@ -256,13 +261,14 @@ class bGrid : public Neon::domain::interface::GridBaseTemplate<bGrid<SBlock>,
// Stencil neighbor indices
Neon::set::MemSet<NghIdx> mStencilNghIndex;

AlphaGrid alphaGrid;
BetaGrid betaGrid;
AlphaGrid alphaGrid;
BetaGrid betaGrid;
Field<uint8_t, 1> maskClassField;
};
std::shared_ptr<Data> mData;
};
extern template class bGrid<StaticBlock<4, 4, 4>>;
} // namespace Neon::domain::details::disaggregated::bGrid
} // namespace Neon::domain::details::disaggregated::bGridMask

#include "bField_imp.h"
#include "bGrid_imp.h"
56 changes: 45 additions & 11 deletions libNeonDomain/include/Neon/domain/details/bGridDisgMask/bGrid_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ bGrid<SBlock>::bGrid(const Neon::Backend& backend,
[&](Neon::index_3d idx) {
return activeCellLambda(idx) != details::cGrid::ClassSelector::outside;
},
// [&](Neon::index_3d idx) {
// return (activeCellLambda(idx) == details::cGrid::ClassSelector::beta)
// ? Neon::domain::tool::partitioning::ByDomain::bc
// : Neon::domain::tool::partitioning::ByDomain::bulk;
// },
// [&](Neon::index_3d idx) {
// return (activeCellLambda(idx) == details::cGrid::ClassSelector::beta)
// ? Neon::domain::tool::partitioning::ByDomain::bc
// : Neon::domain::tool::partitioning::ByDomain::bulk;
// },
nullptr,
SBlock::memBlockSize3D.template newType<int32_t>(),
domainSize,
Expand Down Expand Up @@ -278,6 +278,7 @@ bGrid<SBlock>::bGrid(const Neon::Backend& backend,
});
}

this->init_mask_field<activeCellLambda>();
mData->alphaGrid = details::cGrid::cGrid<SBlock, int(details::cGrid::ClassSelector::alpha)>(*this);
mData->betaGrid = details::cGrid::cGrid<SBlock, int(details::cGrid::ClassSelector::beta)>(*this);
}
Expand Down Expand Up @@ -333,11 +334,11 @@ auto bGrid<SBlock>::newContainer(const std::string& name,
{
const Neon::index_3d& defaultBlockSize = this->getDefaultBlock();
Neon::set::Container kContainer = Neon::set::Container::factory<execution>(name,
Neon::set::internal::ContainerAPI::DataViewSupport::on,
*this,
lambda,
defaultBlockSize,
[](const Neon::index_3d&) { return 0; });
Neon::set::internal::ContainerAPI::DataViewSupport::on,
*this,
lambda,
defaultBlockSize,
[](const Neon::index_3d&) { return 0; });
return kContainer;
}

Expand Down Expand Up @@ -535,4 +536,37 @@ auto bGrid<SBlock>::helpGetPartitioner1D() -> Neon::domain::tool::Partitioner1D&
return mData->partitioner1D;
}

} // namespace Neon::domain::details::disaggregated::bGrid
template <typename SBlock>
template <typename ActiveCellLambda>
auto bGrid<SBlock>::init_mask_field(ActiveCellLambda activeCellLambda) -> void
{
using returTypeOfLambda = typename std::invoke_result<ActiveCellLambda, Neon::index_3d>::type;
if constexpr (std::is_same_v<returTypeOfLambda, details::cGrid::ClassSelector>) {


auto maskField = this->newField<uint8_t, 1>("maskField", 1, 0, Neon::DataUse::HOST_DEVICE);
maskField.getGrid().template newContainer<Neon::Execution::host>(
"maskFieldInit",
[&](Neon::set::Loader& loader) {
auto maskFieldPartition = loader.load(maskField);
return [&, maskFieldPartition](const auto& gIdx) mutable {
details::cGrid::ClassSelector voxelClass = activeCellLambda(gIdx);
maskFieldPartition(gIdx, 0) = static_cast<uint8_t>(voxelClass);
};
})
.run(Neon::Backend::mainStreamIdx);
this->getBackend().sync(Neon::Backend::mainStreamIdx);
maskField.updateDeviceData(Neon::Backend::mainStreamIdx);
this->getBackend().sync(Neon::Backend::mainStreamIdx);
this->mData->maskClassField = maskField;
return;
}
}

template <typename SBlock>
auto bGrid<SBlock>::helpGetClassField() -> Field<uint8_t, 1>&
{
return mData->maskClassField;
}

} // namespace Neon::domain::details::disaggregated::bGridMask
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ namespace Neon::domain::tool::partitioning {
if (activeCellLambda(globalId)) {
isActiveBlock = true;
if (whatdomain == ByDomain::bc) {
std::cout << "HERE " << blockOrigin << std::endl;
byDomain = ByDomain::bc;
doBreak = true;
}
Expand Down
3 changes: 2 additions & 1 deletion libNeonDomain/tests/domain-map-disg/src/map.cu
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ auto run(TestData<G, T, C>& data) -> void
if (!isInside) {
return Neon::domain::details::disaggregated::bGrid::details::cGrid::ClassSelector::outside;
}
if (idx.rSum() % 2 == 0) {
if (idx.x == 0 || idx.y == 0 || idx.z == 0 || idx.x == grid.getDimension().x - 1 || idx.y == grid.getDimension().y - 1 || idx.z == grid.getDimension().z - 1) {
return Neon::domain::details::disaggregated::bGrid::details::cGrid::ClassSelector::beta;
}
return Neon::domain::details::disaggregated::bGrid::details::cGrid::ClassSelector::alpha;
Expand All @@ -151,6 +151,7 @@ auto run(TestData<G, T, C>& data) -> void


grid = tmp;
grid.helpGetClassField().template ioToVtk<int>("classField", "classField");
const std::string appName = TestInformation::fullName(grid.getImplementationName());
data.resetValuesToLinear(1, 100);

Expand Down
Loading

0 comments on commit 475b95b

Please sign in to comment.