From 4760cf5be3598b613139b0f984cd0ceb7056d623 Mon Sep 17 00:00:00 2001 From: Massimiliano Meneghin Date: Wed, 6 Dec 2023 09:40:11 +0100 Subject: [PATCH] WIP - fixing issue with alpha and beta containers. --- .../domain/details/bGridDisg/bPartition.h | 282 ++++---- .../domain/details/bGridDisg/bPartition_imp.h | 7 + .../tools/partitioning/SpanClassifier.h | 647 +++++++++--------- .../Neon/set/container/SequenceContainer.h | 2 +- .../src/set/container/SequenceContainer.cpp | 2 +- 5 files changed, 477 insertions(+), 463 deletions(-) diff --git a/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition.h b/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition.h index ac15b73c..7af86346 100644 --- a/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition.h +++ b/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition.h @@ -9,182 +9,184 @@ namespace Neon::domain::details::disaggregated::bGrid { -template -class bSpan; - -template -class bPartition -{ - public: - using Span = bSpan; - using Idx = bIndex; - using NghIdx = typename Idx::NghIdx; - using Type = T; - using NghData = Neon::domain::NghData; - - using BlockViewGrid = Neon::domain::tool::GridTransformer::Grid; - using BlockViewGridIdx = BlockViewGrid::Idx; - - public: - bPartition(); - - ~bPartition() = default; - - explicit bPartition(int setIdx, - int mCardinality, - T* mMem, - typename Idx::DataBlockIdx* mBlockConnectivity, - typename SBlock::BitMask const* NEON_RESTRICT mMask, - Neon::int32_3d* mOrigin, - NghIdx* mStencilNghIndex, - Neon::int32_3d mDomainSize); - - /** - * Retrieve the cardinality of the field. - */ - inline NEON_CUDA_HOST_DEVICE auto - cardinality() + template + class bSpan; + + template + class bPartition { + public: + using Span = bSpan; + using Idx = bIndex; + using NghIdx = typename Idx::NghIdx; + using Type = T; + using NghData = Neon::domain::NghData; + + using BlockViewGrid = Neon::domain::tool::GridTransformer::Grid; + using BlockViewGridIdx = BlockViewGrid::Idx; + + public: + bPartition(); + + ~bPartition() = default; + + explicit bPartition(int setIdx, + int mCardinality, + T *mMem, + typename Idx::DataBlockIdx *mBlockConnectivity, + typename SBlock::BitMask const *NEON_RESTRICT mMask, + Neon::int32_3d *mOrigin, + NghIdx *mStencilNghIndex, + Neon::int32_3d mDomainSize); + + /** + * Retrieve the cardinality of the field. + */ + inline NEON_CUDA_HOST_DEVICE auto + cardinality() const -> int; - /** - * Gets the field metadata at a cartesian point. - */ - inline NEON_CUDA_HOST_DEVICE auto - operator()(const Idx& cell, - int card) - -> T&; - - /** - * Gets the field metadata at a cartesian point. - */ - inline NEON_CUDA_HOST_DEVICE auto - operator()(const Idx& cell, - int card) - const -> const T&; - - /** - * Gets the field metadata at a neighbour cartesian point. - */ - NEON_CUDA_HOST_DEVICE inline auto - getNghData(const Idx& cell, - const NghIdx& offset, - const int card) + /** + * Gets the field metadata at a cartesian point. + */ + inline NEON_CUDA_HOST_DEVICE auto + operator()(const Idx &cell, + int card) + -> T &; + + /** + * Gets the field metadata at a cartesian point. + */ + inline NEON_CUDA_HOST_DEVICE auto + operator()(const Idx &cell, + int card) + const -> const T &; + + /** + * Gets the field metadata at a neighbour cartesian point. + */ + NEON_CUDA_HOST_DEVICE inline auto + getNghData(const Idx &cell, + const NghIdx &offset, + const int card) const -> NghData; - /** - * Gets the field metadata at a neighbour cartesian point. - */ - NEON_CUDA_HOST_DEVICE inline auto - getNghData(const Idx& eId, - uint8_t nghID, - int card) + /** + * Gets the field metadata at a neighbour cartesian point. + */ + NEON_CUDA_HOST_DEVICE inline auto + getNghData(const Idx &eId, + uint8_t nghID, + int card) const -> NghData; - /** - * Gets the field metadata at a neighbour cartesian point. - */ - template - NEON_CUDA_HOST_DEVICE inline auto - getNghData(const Idx& eId, - int card) + /** + * Gets the field metadata at a neighbour cartesian point. + */ + template + NEON_CUDA_HOST_DEVICE inline auto + getNghData(const Idx &eId, + int card) const -> NghData; - /** - * Gets the field metadata at a neighbour cartesian point. - */ - template - NEON_CUDA_HOST_DEVICE inline auto - getNghData(const Idx& eId, - int card, - T defaultValue) + /** + * Gets the field metadata at a neighbour cartesian point. + */ + template + NEON_CUDA_HOST_DEVICE inline auto + getNghData(const Idx &eId, + int card, + T defaultValue) const -> NghData; - template - NEON_CUDA_HOST_DEVICE inline auto - getNghData(const Idx& gidx, - int card, - LambdaVALID funIfValid, - LambdaNOTValid funIfNOTValid = nullptr) - const -> std::enable_if_t && (std::is_invocable_v || std::is_same_v), void>; - - template - NEON_CUDA_HOST_DEVICE inline auto - writeNghData(const Idx& gidx, - int card, - T value) + template + NEON_CUDA_HOST_DEVICE inline auto + getNghData(const Idx &gidx, + int card, + LambdaVALID funIfValid, + LambdaNOTValid funIfNOTValid = nullptr) + const -> std::enable_if_t && (std::is_invocable_v || + std::is_same_v), void>; + + template + NEON_CUDA_HOST_DEVICE inline auto + writeNghData(const Idx &gidx, + int card, + T value) -> bool; - /** - * Gets the global coordinates of the cartesian point. - */ - NEON_CUDA_HOST_DEVICE inline auto - getGlobalIndex(const Idx& cell) + /** + * Gets the global coordinates of the cartesian point. + */ + NEON_CUDA_HOST_DEVICE inline auto + getGlobalIndex(const Idx &cell) const -> Neon::index_3d; - NEON_CUDA_HOST_DEVICE inline auto - isActive(const Idx& cell, - const typename SBlock::BitMask* mask = nullptr) const -> bool; + NEON_CUDA_HOST_DEVICE inline auto + isActive(const Idx &cell, + const typename SBlock::BitMask *mask = nullptr) const -> bool; - NEON_CUDA_HOST_DEVICE inline auto - getDomainSize() + NEON_CUDA_HOST_DEVICE inline auto + getDomainSize() const -> Neon::index_3d; - /** - * Gets the Idx for in the block view space. - */ - NEON_CUDA_HOST_DEVICE inline auto - getBlockViewIdx(const Idx& cell) + auto mem() const -> T const *; + + /** + * Gets the Idx for in the block view space. + */ + NEON_CUDA_HOST_DEVICE inline auto + getBlockViewIdx(const Idx &cell) const -> BlockViewGridIdx; - NEON_CUDA_HOST_DEVICE inline auto - helpGetPitch(const Idx& cell, int card) + NEON_CUDA_HOST_DEVICE inline auto + helpGetPitch(const Idx &cell, int card) const -> uint32_t; - NEON_CUDA_HOST_DEVICE inline auto - helpGetValidIdxPitchExplicit(const Idx& idx, int card) + NEON_CUDA_HOST_DEVICE inline auto + helpGetValidIdxPitchExplicit(const Idx &idx, int card) const -> uint32_t; - NEON_CUDA_HOST_DEVICE inline auto - helpNghPitch(const Idx& nghIdx, int card) + NEON_CUDA_HOST_DEVICE inline auto + helpNghPitch(const Idx &nghIdx, int card) const -> std::tuple; - NEON_CUDA_HOST_DEVICE inline auto - helpGetNghIdx(const Idx& idx, const NghIdx& offset) + NEON_CUDA_HOST_DEVICE inline auto + helpGetNghIdx(const Idx &idx, const NghIdx &offset) const -> Idx; - template - NEON_CUDA_HOST_DEVICE inline auto - helpGetNghIdx(const Idx& idx) + template + NEON_CUDA_HOST_DEVICE inline auto + helpGetNghIdx(const Idx &idx) const -> Idx; - NEON_CUDA_HOST_DEVICE inline auto - helpGetNghIdx(const Idx& idx, const NghIdx& offset, const typename Idx::DataBlockIdx* blockConnectivity) + NEON_CUDA_HOST_DEVICE inline auto + helpGetNghIdx(const Idx &idx, const NghIdx &offset, const typename Idx::DataBlockIdx *blockConnectivity) const -> Idx; - template - NEON_CUDA_HOST_DEVICE inline auto - helpGetNghIdx(const Idx& idx, const typename Idx::DataBlockIdx* blockConnectivity) + template + NEON_CUDA_HOST_DEVICE inline auto + helpGetNghIdx(const Idx &idx, const typename Idx::DataBlockIdx *blockConnectivity) const -> Idx; - int mCardinality; - T* mMem; - NghIdx const* NEON_RESTRICT mStencilNghIndex; - typename Idx::DataBlockIdx const* NEON_RESTRICT mBlockConnectivity; - typename SBlock::BitMask const* NEON_RESTRICT mMask; - Neon::int32_3d const* NEON_RESTRICT mOrigin; - int mSetIdx; - int mMultiResDiscreteIdxSpacing = 1; - Neon::int32_3d mDomainSize; -}; + int mCardinality; + T *mMem; + NghIdx const *NEON_RESTRICT mStencilNghIndex; + typename Idx::DataBlockIdx const *NEON_RESTRICT mBlockConnectivity; + typename SBlock::BitMask const *NEON_RESTRICT mMask; + Neon::int32_3d const *NEON_RESTRICT mOrigin; + int mSetIdx; + int mMultiResDiscreteIdxSpacing = 1; + Neon::int32_3d mDomainSize; + }; } // namespace Neon::domain::details::disaggregated::bGrid diff --git a/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition_imp.h b/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition_imp.h index 207c9fba..f535c5c2 100644 --- a/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition_imp.h +++ b/libNeonDomain/include/Neon/domain/details/bGridDisg/bPartition_imp.h @@ -61,6 +61,13 @@ NEON_CUDA_HOST_DEVICE inline auto bPartition:: return mDomainSize; } +template +NEON_CUDA_HOST_DEVICE inline auto bPartition:: +mem() const -> T const *{ + return mMem; +} + + template NEON_CUDA_HOST_DEVICE inline auto bPartition:: getBlockViewIdx(const Idx& gidx) diff --git a/libNeonDomain/include/Neon/domain/tools/partitioning/SpanClassifier.h b/libNeonDomain/include/Neon/domain/tools/partitioning/SpanClassifier.h index 7d628ece..66c6ddc9 100644 --- a/libNeonDomain/include/Neon/domain/tools/partitioning/SpanClassifier.h +++ b/libNeonDomain/include/Neon/domain/tools/partitioning/SpanClassifier.h @@ -1,4 +1,5 @@ #pragma once + #include "Neon/core/core.h" @@ -7,342 +8,346 @@ #include "Neon/domain/tools/PointHashTable.h" #include "Neon/domain/tools/SpaceCurves.h" #include "Neon/domain/tools/partitioning/SpanDecomposition.h" + namespace Neon::domain::tool::partitioning { -struct Hash -{ - std::vector id1dTo3d; - Neon::domain::tool::PointHashTable id3dTo1d; - - auto reHash(Neon::domain::tool::spaceCurves::EncoderType encoderType) -> void - { - // std::cout << "BEFORE Cartesian "; - // for (int i = 0; i < int(id1dTo3d.size()); i++) { - // std::cout << id1dTo3d[i] << " "; - // } - // std::cout << std::endl - // << " ID "; - // for (int i = 0; i < int(id1dTo3d.size()); i++) { - // std::cout << *id3dTo1d.getMetadata(id1dTo3d[i]) << " "; - // } - // std::cout << std::endl - // << " CODE "; - // for (int i = 0; i < int(id1dTo3d.size()); i++) { - // std::cout << Neon::domain::tool::spaceCurves::Encoder::encode(spaceCurve, id3dTo1d.getBBox(), id1dTo3d[i]) << " "; - // } - // std::cout << std::endl; - // std::cout << " BOX " << id3dTo1d.getBBox(); - // - // std::cout << std::endl; - - // Encoding all points w.r.t the encoder type - std::vector code; - for (auto const& point : id1dTo3d) { - code.push_back(Neon::domain::tool::spaceCurves::Encoder::encode(encoderType, id3dTo1d.getBBox(), point)); - } - // Sort id1dTo3d w.r.t. the codes - std::vector permutation = getSortedPermutation(code, [](uint64_t a, uint64_t b) { - return a < b; - }); - id1dTo3d = applyPermutation(id1dTo3d, permutation); - for (uint64_t i = 0; i < id1dTo3d.size(); i++) { - *(id3dTo1d.getMetadata(id1dTo3d[i])) = i; + struct Hash { + std::vector id1dTo3d; + Neon::domain::tool::PointHashTable id3dTo1d; + + auto reHash(Neon::domain::tool::spaceCurves::EncoderType encoderType) -> void { + // std::cout << "BEFORE Cartesian "; + // for (int i = 0; i < int(id1dTo3d.size()); i++) { + // std::cout << id1dTo3d[i] << " "; + // } + // std::cout << std::endl + // << " ID "; + // for (int i = 0; i < int(id1dTo3d.size()); i++) { + // std::cout << *id3dTo1d.getMetadata(id1dTo3d[i]) << " "; + // } + // std::cout << std::endl + // << " CODE "; + // for (int i = 0; i < int(id1dTo3d.size()); i++) { + // std::cout << Neon::domain::tool::spaceCurves::Encoder::encode(spaceCurve, id3dTo1d.getBBox(), id1dTo3d[i]) << " "; + // } + // std::cout << std::endl; + // std::cout << " BOX " << id3dTo1d.getBBox(); + // + // std::cout << std::endl; + + // Encoding all points w.r.t the encoder type + std::vector code; + for (auto const &point: id1dTo3d) { + code.push_back( + Neon::domain::tool::spaceCurves::Encoder::encode(encoderType, id3dTo1d.getBBox(), point)); + } + // Sort id1dTo3d w.r.t. the codes + std::vector permutation = getSortedPermutation(code, [](uint64_t a, uint64_t b) { + return a < b; + }); + id1dTo3d = applyPermutation(id1dTo3d, permutation); + for (uint64_t i = 0; i < id1dTo3d.size(); i++) { + *(id3dTo1d.getMetadata(id1dTo3d[i])) = i; + } + // + // std::cout << "AFTER Cartesian "; + // for (int i = 0; i < int(id1dTo3d.size()); i++) { + // std::cout << id1dTo3d[i] << " "; + // } + // std::cout << std::endl + // << " ID "; + // for (int i = 0; i < int(id1dTo3d.size()); i++) { + // std::cout << *id3dTo1d.getMetadata(id1dTo3d[i]) << " "; + // } + // std::cout << std::endl + // << " CODE "; + // for (int i = 0; i < int(id1dTo3d.size()); i++) { + // std::cout << Neon::domain::tool::spaceCurves::Encoder::encode(spaceCurve, id3dTo1d.getBBox(), id1dTo3d[i]) << " "; + // } + // std::cout << std::endl; } - // - // std::cout << "AFTER Cartesian "; - // for (int i = 0; i < int(id1dTo3d.size()); i++) { - // std::cout << id1dTo3d[i] << " "; - // } - // std::cout << std::endl - // << " ID "; - // for (int i = 0; i < int(id1dTo3d.size()); i++) { - // std::cout << *id3dTo1d.getMetadata(id1dTo3d[i]) << " "; - // } - // std::cout << std::endl - // << " CODE "; - // for (int i = 0; i < int(id1dTo3d.size()); i++) { - // std::cout << Neon::domain::tool::spaceCurves::Encoder::encode(spaceCurve, id3dTo1d.getBBox(), id1dTo3d[i]) << " "; - // } - // std::cout << std::endl; - } - private: - template - std::vector getSortedPermutation( - const std::vector& vec, - Compare const& compare) - { - std::vector p(vec.size()); - std::iota(p.begin(), p.end(), 0); - std::sort(p.begin(), p.end(), - [&](std::size_t i, std::size_t j) { return compare(vec[i], vec[j]); }); - return p; - } + private: + template + std::vector getSortedPermutation( + const std::vector &vec, + Compare const &compare) { + std::vector p(vec.size()); + std::iota(p.begin(), p.end(), 0); + std::sort(p.begin(), p.end(), + [&](std::size_t i, std::size_t j) { return compare(vec[i], vec[j]); }); + return p; + } - template - std::vector applyPermutation( - const std::vector& vec, - const std::vector& p) - { - std::vector sorted_vec(vec.size()); - std::transform(p.begin(), p.end(), sorted_vec.begin(), - [&](std::size_t i) { return vec[i]; }); - return sorted_vec; - } -}; - -class SpanClassifier -{ - public: - SpanClassifier() = default; - - template - SpanClassifier(const Neon::Backend& backend, - const ActiveCellLambda& activeCellLambda, - const BcLambda& bcLambda, - const Block3dIdxToBlockOrigin& block3dIdxToBlockOrigin, - const GetVoxelAbsolute3DIdx& getVoxelAbsolute3DIdx, - const Neon::int32_3d& block3DSpan, - const Neon::int32_3d& dataBlockSize3D, - const Neon::int32_3d& domainSize, - const Neon::domain::Stencil stencil, - const int& discreteVoxelSpacing, - Neon::domain::tool::spaceCurves::EncoderType encoderType, - std::shared_ptr sp); - - - /** - * For the partition setIdx, it returns a vector that maps local ids to 3d points. - * The local ids are local in terms of partition, domain and direction classes. - */ - [[nodiscard]] auto getMapper1Dto3D(Neon::SetIdx const& setIdx, - ByPartition, - ByDirection, - ByDomain) const - -> const std::vector&; - - /** - * For the partition setIdx, it returns a hash object that maps 3d points to local ids - * The local ids are local in terms of partition, domain and direction classes. - */ - [[nodiscard]] auto getMapper3Dto1D(Neon::SetIdx const& setIdx, - ByPartition, - ByDirection, - ByDomain) const - -> const Neon::domain::tool::PointHashTable&; - - [[nodiscard]] auto countInternal(Neon::SetIdx setIdx, - ByDomain byDomain) const -> int; - - [[nodiscard]] auto countInternal(Neon::SetIdx setIdx) const -> int; - - [[nodiscard]] auto countBoundary(Neon::SetIdx setIdx, - ByDirection byDirection, - ByDomain byDomain) const -> int; - - - [[nodiscard]] auto countBoundary(Neon::SetIdx setIdx) const -> int; - - auto getMapper1Dto3D(Neon::SetIdx const& setIdx, - ByPartition, - ByDirection, - ByDomain) - -> std::vector&; - - auto getMapper3Dto1D(Neon::SetIdx const& setIdx, - ByPartition, - ByDirection, - ByDomain) - -> Neon::domain::tool::PointHashTable&; - - private: - auto addPoint(Neon::SetIdx const& setIdx, - Neon::int32_3d const& int323D, - ByPartition byPartition, - ByDirection byDirection, - ByDomain byDomain) -> void; - - - using Leve0_Info = Hash; - using Leve1_ByDomain = std::array; - using Leve2_ByDirection = std::array; - using Leve3_ByPartition = std::array; - using Data = Neon::set::DataSet; - - Data mData; - std::shared_ptr mSpanDecomposition; -}; - - -template -SpanClassifier::SpanClassifier(const Neon::Backend& backend, - const ActiveCellLambda& activeCellLambda, - const BcLambda& bcLambda, - const Block3dIdxToBlockOrigin& block3dIdxToBlockOrigin, - const GetVoxelAbsolute3DIdx& getVoxelAbsolute3DIdx, - const Neon::int32_3d& block3DSpan, - const Neon::int32_3d& dataBlockSize3D, - const Neon::int32_3d& domainSize, - const Neon::domain::Stencil stencil, - const int& discreteVoxelSpacing, - Neon::domain::tool::spaceCurves::EncoderType spaceFillingType, - std::shared_ptr spanDecompositionNoUse) -{ - mData = backend.devSet().newDataSet(); - mSpanDecomposition = spanDecompositionNoUse; - - ByDirection defaultForInternal = ByDirection::up; - - mData.forEachSeq([&](SetIdx, auto& leve3ByPartition) { - // using Leve0_Info = Info; - // using Leve1_ByDomain = std::array; - // using Leve2_ByDirection = std::array; - // using Leve3_ByPartition = std::array; - // using Data = Neon::set::DataSet; - for (auto& level2 : leve3ByPartition) { - for (auto& level1 : level2) { - for (auto& level0 : level1) { - level0.id3dTo1d = Neon::domain::tool::PointHashTable(block3DSpan); - } - } + template + std::vector applyPermutation( + const std::vector &vec, + const std::vector &p) { + std::vector sorted_vec(vec.size()); + std::transform(p.begin(), p.end(), sorted_vec.begin(), + [&](std::size_t i) { return vec[i]; }); + return sorted_vec; } - }); - - // Computing the stencil radius at block granularity - // If the dataBlockEdge is equal to 1 (element sparse block) the radius is - // the same as the stencil radius. - auto const zRadius = [&stencil, dataBlockSize3D]() -> int { - auto maxRadius = stencil.getRadius(); - maxRadius = ((maxRadius - 1) / dataBlockSize3D.z) + 1; - return maxRadius; - }(); - - // For each Partition - backend.devSet() - .forEachSetIdxSeq( - [&](const Neon::SetIdx& setIdx) { - int beginZ = mSpanDecomposition->getFirstZSliceIdx()[setIdx]; - int lastZ = mSpanDecomposition->getLastZSliceIdx()[setIdx]; - - std::vector const boundaryDwSlices = [&] { - std::vector result; - for (int i = 0; i < zRadius; i++) { - result.push_back(beginZ + i); + }; + + class SpanClassifier { + public: + SpanClassifier() = default; + + template + SpanClassifier(const Neon::Backend &backend, + const ActiveCellLambda &activeCellLambda, + const BcLambda &bcLambda, + const Block3dIdxToBlockOrigin &block3dIdxToBlockOrigin, + const GetVoxelAbsolute3DIdx &getVoxelAbsolute3DIdx, + const Neon::int32_3d &block3DSpan, + const Neon::int32_3d &dataBlockSize3D, + const Neon::int32_3d &domainSize, + const Neon::domain::Stencil stencil, + const int &discreteVoxelSpacing, + Neon::domain::tool::spaceCurves::EncoderType encoderType, + std::shared_ptr sp); + + + /** + * For the partition setIdx, it returns a vector that maps local ids to 3d points. + * The local ids are local in terms of partition, domain and direction classes. + */ + [[nodiscard]] auto getMapper1Dto3D(Neon::SetIdx const &setIdx, + ByPartition, + ByDirection, + ByDomain) const + -> const std::vector &; + + /** + * For the partition setIdx, it returns a hash object that maps 3d points to local ids + * The local ids are local in terms of partition, domain and direction classes. + */ + [[nodiscard]] auto getMapper3Dto1D(Neon::SetIdx const &setIdx, + ByPartition, + ByDirection, + ByDomain) const + -> const Neon::domain::tool::PointHashTable &; + + [[nodiscard]] auto countInternal(Neon::SetIdx setIdx, + ByDomain byDomain) const -> int; + + [[nodiscard]] auto countInternal(Neon::SetIdx setIdx) const -> int; + + [[nodiscard]] auto countBoundary(Neon::SetIdx setIdx, + ByDirection byDirection, + ByDomain byDomain) const -> int; + + + [[nodiscard]] auto countBoundary(Neon::SetIdx setIdx) const -> int; + + auto getMapper1Dto3D(Neon::SetIdx const &setIdx, + ByPartition, + ByDirection, + ByDomain) + -> std::vector &; + + auto getMapper3Dto1D(Neon::SetIdx const &setIdx, + ByPartition, + ByDirection, + ByDomain) + -> Neon::domain::tool::PointHashTable &; + + private: + auto addPoint(Neon::SetIdx const &setIdx, + Neon::int32_3d const &int323D, + ByPartition byPartition, + ByDirection byDirection, + ByDomain byDomain) -> void; + + + using Leve0_Info = Hash; + using Leve1_ByDomain = std::array; + using Leve2_ByDirection = std::array; + using Leve3_ByPartition = std::array; + using Data = Neon::set::DataSet; + + Data mData; + std::shared_ptr mSpanDecomposition; + }; + + + template + SpanClassifier::SpanClassifier(const Neon::Backend &backend, + const ActiveCellLambda &activeCellLambda, + const BcLambda &bcLambda, + const Block3dIdxToBlockOrigin &block3dIdxToBlockOrigin, + const GetVoxelAbsolute3DIdx &getVoxelAbsolute3DIdx, + const Neon::int32_3d &block3DSpan, + const Neon::int32_3d &dataBlockSize3D, + const Neon::int32_3d &domainSize, + const Neon::domain::Stencil stencil, + const int &discreteVoxelSpacing, + Neon::domain::tool::spaceCurves::EncoderType spaceFillingType, + std::shared_ptr spanDecompositionNoUse) { + mData = backend.devSet().newDataSet(); + mSpanDecomposition = spanDecompositionNoUse; + + ByDirection defaultForInternal = ByDirection::up; + + mData.forEachSeq([&](SetIdx, auto &leve3ByPartition) { + // using Leve0_Info = Info; + // using Leve1_ByDomain = std::array; + // using Leve2_ByDirection = std::array; + // using Leve3_ByPartition = std::array; + // using Data = Neon::set::DataSet; + for (auto &level2: leve3ByPartition) { + for (auto &level1: level2) { + for (auto &level0: level1) { + level0.id3dTo1d = Neon::domain::tool::PointHashTable(block3DSpan); } - return result; - }(); + } + } + }); + + // Computing the stencil radius at block granularity + // If the dataBlockEdge is equal to 1 (element sparse block) the radius is + // the same as the stencil radius. + auto const zRadius = [&stencil, dataBlockSize3D]() -> int { + auto maxRadius = stencil.getRadius(); + maxRadius = ((maxRadius - 1) / dataBlockSize3D.z) + 1; + return maxRadius; + }(); + + // For each Partition + backend.devSet() + .forEachSetIdxSeq( + [&](const Neon::SetIdx &setIdx) { + int beginZ = mSpanDecomposition->getFirstZSliceIdx()[setIdx]; + int lastZ = mSpanDecomposition->getLastZSliceIdx()[setIdx]; + + std::vector const boundaryDwSlices = [&] { + std::vector result; + for (int i = 0; i < zRadius; i++) { + result.push_back(beginZ + i); + } + return result; + }(); + + std::vector const boundaryUpSlices = [&] { + std::vector result; + for (int i = zRadius - 1; i >= 0; i--) { + result.push_back(lastZ - i); + } + return result; + }(); + + auto inspectBlock = [&](int bx, int by, int bz, ByPartition byPartition, + ByDirection byDirection) { + Neon::int32_3d blockOrigin = block3dIdxToBlockOrigin({bx, by, bz}); + + bool doBreak = false; + bool isActiveBlock = false; + ByDomain byDomain = ByDomain::bulk; + for (int z = 0; (z < dataBlockSize3D.z && !doBreak); z++) { + for (int y = 0; (y < dataBlockSize3D.y && !doBreak); y++) { + for (int x = 0; (x < dataBlockSize3D.x && !doBreak); x++) { + + const Neon::int32_3d globalId = getVoxelAbsolute3DIdx(blockOrigin, + {x, y, z}); + if (globalId < domainSize * discreteVoxelSpacing) { + + if constexpr (std::is_same_v) { + if (activeCellLambda(globalId)) { + byDomain = ByDomain::bulk; + isActiveBlock = true; + doBreak = true; + break; + } + } else if constexpr (std::is_same_v::type, bool>) { + NEON_THROW_UNSUPPORTED_OPERATION("bool"); + } else if constexpr (std::is_same_v::type, ByDomain>) { + auto whatdomain = bcLambda(globalId); + if (activeCellLambda(globalId)) { + isActiveBlock = true; + if (whatdomain == ByDomain::bc) { + std::cout << "HERE " << blockOrigin << std::endl; + byDomain = ByDomain::bc; + doBreak = true; + } + } + } - std::vector const boundaryUpSlices = [&] { - std::vector result; - for (int i = zRadius - 1; i >= 0; i--) { - result.push_back(lastZ - i); - } - return result; - }(); - - auto inspectBlock = [&](int bx, int by, int bz, ByPartition byPartition, ByDirection byDirection) { - Neon::int32_3d blockOrigin = block3dIdxToBlockOrigin({bx, by, bz}); - - bool doBreak = false; - bool isActiveBlock = false; - ByDomain byDomain = ByDomain::bulk; - for (int z = 0; (z < dataBlockSize3D.z && !doBreak); z++) { - for (int y = 0; (y < dataBlockSize3D.y && !doBreak); y++) { - for (int x = 0; (x < dataBlockSize3D.x && !doBreak); x++) { - - const Neon::int32_3d globalId = getVoxelAbsolute3DIdx(blockOrigin, {x, y, z}); - if (globalId < domainSize * discreteVoxelSpacing) { - if (activeCellLambda(globalId)) { - doBreak = true; - isActiveBlock = true; - Neon::int32_3d const pointInBlock(bx + x, by + y, bz + z); - if constexpr (std::is_same_v) { - byDomain = ByDomain::bulk; - doBreak = true; - break; - } else if constexpr (std::is_same_v::type, bool>) { - NEON_THROW_UNSUPPORTED_OPERATION("bool"); - } else if constexpr (std::is_same_v::type, ByDomain>) { - if (bcLambda(pointInBlock) == ByDomain::bc) { - byDomain = ByDomain::bc; } } } } - } - } - } - if (isActiveBlock) { - Neon::int32_3d const point(bx, by, bz); - addPoint(setIdx, point, byPartition, byDirection, byDomain); - } - }; - if (backend.deviceCount() > 1) { - // We are running in the inner partition blocks - if (beginZ + zRadius > lastZ - zRadius) { - std::cout << spanDecompositionNoUse->toString(backend); - - NeonException exception("1D Partitioner"); - exception << "Domain too small for the number of devices that was providded.\n"; - exception << "Block Span " << block3DSpan << "\n"; - exception << spanDecompositionNoUse->toString(backend); - NEON_THROW(exception); - } - for (int bz = beginZ + zRadius; bz <= lastZ - zRadius; bz++) { - for (int by = 0; by < block3DSpan.y; by++) { - for (int bx = 0; bx < block3DSpan.x; bx++) { - inspectBlock(bx, by, bz, ByPartition::internal, defaultForInternal); - } - } - } - // We are running in the inner partition blocks - for (auto& bz : boundaryDwSlices) { - for (int by = 0; by < block3DSpan.y; by++) { - for (int bx = 0; bx < block3DSpan.x; bx++) { - inspectBlock(bx, by, bz, ByPartition::boundary, ByDirection::down); - } - } - } + if (isActiveBlock) { + Neon::int32_3d const point(bx, by, bz); + addPoint(setIdx, point, byPartition, byDirection, byDomain); + } + }; + if (backend.deviceCount() > 1) { + // We are running in the inner partition blocks + if (beginZ + zRadius > lastZ - zRadius) { + std::cout << spanDecompositionNoUse->toString(backend); + + NeonException exception("1D Partitioner"); + exception << "Domain too small for the number of devices that was providded.\n"; + exception << "Block Span " << block3DSpan << "\n"; + exception << spanDecompositionNoUse->toString(backend); + NEON_THROW(exception); + } + for (int bz = beginZ + zRadius; bz <= lastZ - zRadius; bz++) { + for (int by = 0; by < block3DSpan.y; by++) { + for (int bx = 0; bx < block3DSpan.x; bx++) { + inspectBlock(bx, by, bz, ByPartition::internal, defaultForInternal); + } + } + } + // We are running in the inner partition blocks + for (auto &bz: boundaryDwSlices) { + for (int by = 0; by < block3DSpan.y; by++) { + for (int bx = 0; bx < block3DSpan.x; bx++) { + inspectBlock(bx, by, bz, ByPartition::boundary, ByDirection::down); + } + } + } - // We are running in the inner partition blocks - for (auto& bz : boundaryUpSlices) { - for (int by = 0; by < block3DSpan.y; by++) { - for (int bx = 0; bx < block3DSpan.x; bx++) { - inspectBlock(bx, by, bz, ByPartition::boundary, ByDirection::up); - } - } - } - } else { - // We are running in the inner partition blocks - for (int bz = beginZ; bz <= lastZ; bz++) { - for (int by = 0; by < block3DSpan.y; by++) { - for (int bx = 0; bx < block3DSpan.x; bx++) { - inspectBlock(bx, by, bz, ByPartition::internal, defaultForInternal); + // We are running in the inner partition blocks + for (auto &bz: boundaryUpSlices) { + for (int by = 0; by < block3DSpan.y; by++) { + for (int bx = 0; bx < block3DSpan.x; bx++) { + inspectBlock(bx, by, bz, ByPartition::boundary, ByDirection::up); + } + } + } + } else { + // We are running in the inner partition blocks + for (int bz = beginZ; bz <= lastZ; bz++) { + for (int by = 0; by < block3DSpan.y; by++) { + for (int bx = 0; bx < block3DSpan.x; bx++) { + inspectBlock(bx, by, bz, ByPartition::internal, defaultForInternal); + } + } + } } - } + }); + + mData.forEachSeq([&](SetIdx, auto &leve3ByPartition) { + // using Leve0_Info = Info; + // using Leve1_ByDomain = std::array; + // using Leve2_ByDirection = std::array; + // using Leve3_ByPartition = std::array; + // using Data = Neon::set::DataSet; + for (auto &level2: leve3ByPartition) { + for (auto &level1: level2) { + for (auto &level0: level1) { + level0.reHash(spaceFillingType); } } - }); - - mData.forEachSeq([&](SetIdx, auto& leve3ByPartition) { - // using Leve0_Info = Info; - // using Leve1_ByDomain = std::array; - // using Leve2_ByDirection = std::array; - // using Leve3_ByPartition = std::array; - // using Data = Neon::set::DataSet; - for (auto& level2 : leve3ByPartition) { - for (auto& level1 : level2) { - for (auto& level0 : level1) { - level0.reHash(spaceFillingType); - } } - } - }); -} + }); + } } // namespace Neon::domain::tool::partitioning diff --git a/libNeonSet/include/Neon/set/container/SequenceContainer.h b/libNeonSet/include/Neon/set/container/SequenceContainer.h index 69cf93d8..f7709a9f 100644 --- a/libNeonSet/include/Neon/set/container/SequenceContainer.h +++ b/libNeonSet/include/Neon/set/container/SequenceContainer.h @@ -32,7 +32,7 @@ struct SequenceContainer : ContainerAPI Neon::DataView dataView = Neon::DataView::STANDARD) -> void override; - auto setSequence() const -> const std::vector&; + auto getSequence() const -> const std::vector&; private: std::vector mSequence; diff --git a/libNeonSet/src/set/container/SequenceContainer.cpp b/libNeonSet/src/set/container/SequenceContainer.cpp index 5dd3a82c..14b08db6 100644 --- a/libNeonSet/src/set/container/SequenceContainer.cpp +++ b/libNeonSet/src/set/container/SequenceContainer.cpp @@ -22,7 +22,7 @@ auto SequenceContainer:: } auto SequenceContainer:: - setSequence() + getSequence() const -> const std::vector& { return mSequence;