Skip to content

Commit

Permalink
Merge branch 'bGridDisg' into DisgMultiResLBM
Browse files Browse the repository at this point in the history
  • Loading branch information
massimim committed Feb 7, 2024
2 parents 7f415a5 + 475b95b commit 0ac432f
Show file tree
Hide file tree
Showing 66 changed files with 6,055 additions and 60 deletions.
6 changes: 3 additions & 3 deletions benchmarks/lbm/lbm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
deviceType_LIST = 'cpu gpu'.split()
deviceType_LIST = 'gpu'.split()
deviceIds_LIST = "0 1 2 3 4 5 6 7".split()
grid_LIST = "dGrid bGrid_4_4_4".split()
grid_LIST = "bGrid_4_4_4 bGridMgpu_4_4_4".split()
domainSize_LIST = "64 80 96 112 128 144 160 176 192 208 224 240 256 272 288 304 320 336 352 368 384 400 416 432 448 464 480 496 512".split()
computeFP_LIST = "double float".split()
storageFP_LIST = "double float".split()
Expand Down Expand Up @@ -35,7 +35,7 @@ def getDeviceConfigurations(DEVICE_TYPE, deviceIds_LIST):
return [deviceIds_LIST[0]]

if goal_is_efficiency_max_num_devices:
return [deviceIds_LIST[0], deviceIds_LIST]
return [deviceIds_LIST[0], ' '.join(deviceIds_LIST)]


def printProgressBar(value, label):
Expand Down
52 changes: 31 additions & 21 deletions benchmarks/lbm/src/RunCavityTwoPop.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
#include "D3Q19.h"
#include "D3Q27.h"

#include "Neon/domain/bGrid.h"
#include "Neon/domain/dGrid.h"
#include "Neon/domain/Grids.h"
#include "Neon/domain/details/dGridDisg/dGrid.h"
#include "Neon/domain/details/dGridSoA/dGridSoA.h"
#include "Neon/domain/eGrid.h"

#include "./Lbm.h"
#include "CellType.h"
Expand Down Expand Up @@ -135,18 +133,18 @@ auto runFilterCollision(Config& config,
testCode << "_bgk";
return runFilterMethod<Collision::bgk, Lattice, Grid, Storage, Compute>(config, report, testCode);
}
// if (config.collisionCli.getOption() == Collision::kbc) {
// if (config.lattice != "d3q27" && config.lattice != "D3Q27") {
// Neon::NeonException e("runFilterCollision");
// e << "LBM kbc collision model only supports d3q27 lattice";
// NEON_THROW(e);
// }
// testCode << "_kbc";
// using L = D3Q27<Precision<Storage, Compute>>;
// if constexpr (std::is_same_v<Lattice, L>) {
// return runFilterMethod<Collision::kbc, Lattice, Grid, Storage, Compute>(config, report, testCode);
// }
// }
if (config.collisionCli.getOption() == Collision::kbc) {
if (config.lattice != "d3q27" && config.lattice != "D3Q27") {
Neon::NeonException e("runFilterCollision");
e << "LBM kbc collision model only supports d3q27 lattice";
NEON_THROW(e);
}
testCode << "_kbc";
using L = D3Q27<Precision<Storage, Compute>>;
if constexpr (std::is_same_v<Lattice, L>) {
return runFilterMethod<Collision::kbc, Lattice, Grid, Storage, Compute>(config, report, testCode);
}
}
NEON_DEV_UNDER_CONSTRUCTION("");
}

Expand Down Expand Up @@ -218,13 +216,25 @@ auto run(Config& config,
testCode << "___" << config.N << "_";
testCode << "_numDevs_" << config.devices.size();

if (config.gridType == "dGrid") {
testCode << "_dGrid";
return details::runFilterStoreType<Neon::dGrid>(config, report, testCode);
// if (config.gridType == "dGrid") {
// testCode << "_dGrid";
// return details::runFilterStoreType<Neon::dGrid>(config, report, testCode);
// }
// if (config.gridType == "dGridDisg") {
// testCode << "_dGridDisg";
// return details::runFilterStoreType<Neon::domain::details::disaggregated::dGrid::dGrid>(config, report, testCode);
// }
if (config.gridType == "bGrid_4_4_4") {
testCode << "_bGrid_4_4_4";
using Block = Neon::domain::details::bGrid::StaticBlock<4, 4, 4>;
using Grid = Neon::domain::details::bGrid::bGrid<Block>;
return details::runFilterStoreType<Grid>(config, report, testCode);
}
if (config.gridType == "dGridDisg") {
testCode << "_dGridDisg";
return details::runFilterStoreType<Neon::domain::details::disaggregated::dGrid::dGrid>(config, report, testCode);
if (config.gridType == "bGridMgpu_4_4_4") {
testCode << "_bGridMgpu_4_4_4";
using Block = Neon::domain::details::bGridMgpu::StaticBlock<4, 4, 4>;
using Grid = Neon::domain::details::bGridMgpu::bGrid<Block>;
return details::runFilterStoreType<Neon::bGridMgpu>(config, report, testCode);
}
// if (config.gridType == "eGrid") {
// if constexpr (!skipTest) {
Expand Down
1 change: 1 addition & 0 deletions libNeonDomain/include/Neon/domain/Grids.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#include "Neon/domain/bGrid.h"
#include "Neon/domain/dGridSoA.h"
#include "Neon/domain/bGridDisg.h"
#include "Neon/domain/bGridMgpuDisg.h"
6 changes: 6 additions & 0 deletions libNeonDomain/include/Neon/domain/bGridMgpuDisg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include "Neon/domain/details/bGridDisgMgpu//bGrid.h"

namespace Neon {
using bGridMgpu = Neon::domain::details::bGridMgpu::bGridMgpuDefault;
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class bPartition
getDomainSize()
const -> Neon::index_3d;

NEON_CUDA_HOST_DEVICE
auto mem() const -> T const *;

/**
Expand Down
4 changes: 1 addition & 3 deletions libNeonDomain/include/Neon/domain/details/bGridDisg/bField.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ class bField : public Neon::domain::interface::FieldBaseTemplate<T,
BlockViewField<T, 0> memoryField;
int cardinality;

// Neon::domain::tool::HaloTable1DPartitioning latticeHaloUpdateTable;
Neon::domain::tool::HaloTable1DPartitioning soaHaloUpdateTable;
// Neon::domain::tool::HaloTable1DPartitioning aosHaloUpdateTable;
Neon::domain::tool::HaloTable1DPartitioning mStandardHaloUpdateTable;
Neon::domain::tool::PartitionTable<Partition> partitionTable;
};
std::shared_ptr<Data> mData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ auto bField<T, C, SBlock>::newHaloUpdate(Neon::set::StencilSemantic stencilSeman
for (auto byDirection : {tool::partitioning::ByDirection::up,
tool::partitioning::ByDirection::down}) {

auto const& tableEntryByDir = mData->soaHaloUpdateTable.get(transferMode,
auto const& tableEntryByDir = mData->mStandardHaloUpdateTable.get(transferMode,
execution,
byDirection);

Expand Down Expand Up @@ -262,7 +262,7 @@ auto bField<T, C, SBlock>::initHaloUpdateTable() -> void
return res;
};

mData->soaHaloUpdateTable.forEachPutConfiguration(
mData->mStandardHaloUpdateTable.forEachPutConfiguration(
bk, [&](Neon::SetIdx setIdxSrc,
Execution execution,
Neon::domain::tool::partitioning::ByDirection byDirection,
Expand Down
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 @@ -136,6 +136,7 @@ namespace Neon::domain::details::disaggregated::bGrid {
getDomainSize()
const -> Neon::index_3d;

NEON_CUDA_HOST_DEVICE
auto mem() const -> T const *;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "Neon/domain/details/bGridDisgMask/BlockViewGrid//BlockViewGrid.h"
#include "Neon/domain/tools/GridTransformer.h"

namespace Neon::domain::details::disaggregated::bGridMask {

struct BlockView
{
public:
using Grid = Neon::domain::tool::GridTransformer<details::GridTransformation>::Grid;
template <typename T, int C = 0>
using Field = Grid::template Field<T, C>;
using index_3d = Neon::index_3d;

template <typename T, int C = 0>
static auto helpGetReference(T* mem, const int idx, const int card) -> std::enable_if_t<C == 0, T&>
{
return mem[idx * card];
}

template <typename T, int C = 0>
static auto helpGetReference(T* mem, const int idx, const int card) -> std::enable_if_t<C != 0, T&>
{
return mem[idx * C];
}

static constexpr Neon::MemoryLayout layout = Neon::MemoryLayout::arrayOfStructs;
};

} // namespace Neon::domain::details::disaggregated::bGrid
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#pragma once
#include <assert.h>

#include "Neon/core/core.h"
#include "Neon/core/types/DataUse.h"
#include "Neon/core/types/Macros.h"

#include "Neon/set/BlockConfig.h"
#include "Neon/set/Containter.h"
#include "Neon/set/DevSet.h"
#include "Neon/set/MemoryOptions.h"

#include "Neon/sys/memory/MemDevice.h"

#include "Neon/domain/aGrid.h"

#include "Neon/domain/interface/GridBaseTemplate.h"
#include "Neon/domain/interface/GridConcept.h"
#include "Neon/domain/interface/KernelConfig.h"
#include "Neon/domain/interface/LaunchConfig.h"
#include "Neon/domain/interface/Stencil.h"
#include "Neon/domain/interface/common.h"

#include "Neon/domain/tools/GridTransformer.h"
#include "Neon/domain/tools/SpanTable.h"

#include "Neon/domain/details/eGrid/eGrid.h"
#include "Neon/domain/patterns/PatternScalar.h"

#include "BlockViewPartition.h"

namespace Neon::domain::details::disaggregated::bGridMask {

namespace details {
struct GridTransformation
{
template <typename T, int C>
using Partition = BlockViewPartition<T, C>;
using Span = Neon::domain::details::eGrid::eSpan;
static constexpr Neon::set::internal::ContainerAPI::DataViewSupport dataViewSupport = Neon::set::internal::ContainerAPI::DataViewSupport::on;

using FoundationGrid = Neon::domain::details::eGrid::eGrid;
static constexpr Neon::set::details::ExecutionThreadSpan executionThreadSpan = FoundationGrid::executionThreadSpan;
using ExecutionThreadSpanIndexType = int32_t;
using Idx = FoundationGrid::Idx;

static auto getDefaultBlock(FoundationGrid& foundationGrid) -> Neon::index_3d const&
{
return foundationGrid.getDefaultBlock();
}

static auto initSpan(FoundationGrid& foundationGrid, Neon::domain::tool::SpanTable<Span>& spanTable) -> void
{
spanTable.forEachConfiguration([&](Neon::Execution execution,
Neon::SetIdx setIdx,
Neon::DataView dw,
Span& span) {
span = foundationGrid.getSpan(execution, setIdx, dw);
});
}

static auto initLaunchParameters(FoundationGrid& foundationGrid,
Neon::DataView dataView,
const Neon::index_3d& blockSize,
const size_t& shareMem) -> Neon::set::LaunchParameters
{
return foundationGrid.getLaunchParameters(dataView, blockSize, shareMem);
}

static auto helpGetGridIdx(FoundationGrid&,
Neon::SetIdx const&,
FoundationGrid::Idx const& fgIdx)
-> GridTransformation::Idx
{
GridTransformation::Idx tgIdx = fgIdx;
return tgIdx;
}

template <typename T, int C>
static auto initFieldPartition(FoundationGrid::Field<T, C>& foundationField,
Neon::domain::tool::PartitionTable<Partition<T, C>>& partitionTable) -> void
{
partitionTable.forEachConfiguration(
[&](Neon::Execution execution,
Neon::SetIdx setIdx,
Neon::DataView dw,
Partition<T, C>& partition) {
auto& foundationPartition = foundationField.getPartition(execution, setIdx, dw);
partition = Partition<T, C>(foundationPartition);
});
}
};
using BlockViewGrid = Neon::domain::tool::GridTransformer<details::GridTransformation>::Grid;

} // namespace details

} // namespace Neon::domain::details::bGrid
Loading

0 comments on commit 0ac432f

Please sign in to comment.