Skip to content

Commit

Permalink
Merge pull request #32 from Autodesk/MultiResLBM
Browse files Browse the repository at this point in the history
Multi-resolution LBM Application
  • Loading branch information
Ahdhn authored Feb 14, 2023
2 parents 21b8d13 + 5631a0c commit 3b98084
Show file tree
Hide file tree
Showing 25 changed files with 1,203 additions and 255 deletions.
1 change: 1 addition & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add_subdirectory("fractal")
add_subdirectory("lbm")
add_subdirectory("gameOfLife")
add_subdirectory("poisson")
add_subdirectory("lbmMultiRes")
17 changes: 17 additions & 0 deletions apps/lbmMultiRes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)

set (APP_NAME app-lbmMultiRes)
file(GLOB_RECURSE SrcFiles lbmMultiRes.cu)

add_executable(${APP_NAME} ${SrcFiles})

target_link_libraries(${APP_NAME}
PUBLIC libNeonSkeleton)

set_target_properties(${APP_NAME} PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_RESOLVE_DEVICE_SYMBOLS ON)
set_target_properties(${APP_NAME} PROPERTIES FOLDER "apps")
source_group(TREE ${CMAKE_CURRENT_LIST_DIR} PREFIX "${APP_NAME}" FILES ${SrcFiles})

add_test(NAME ${APP_NAME} COMMAND ${APP_NAME})
781 changes: 781 additions & 0 deletions apps/lbmMultiRes/lbmMultiRes.cu

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions libNeonCore/include/Neon/core/types/vec/vec3d_integer.tdecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ class Vec_3d<IntegerType_ta, true, false>

NEON_CUDA_HOST_DEVICE inline bool operator!=(const Integer other[self_t::num_axis]) const;

NEON_CUDA_HOST_DEVICE inline self_t operator-() const;

/** Returns the most north-est-hi point buildable with A and B coordinates"
* C = A >> B is: C.v[i] = A.v[i] > B.v[i] ? A.v[i] : B.v[i]
* @param[in] B: second point for the operation.
Expand Down
7 changes: 7 additions & 0 deletions libNeonCore/include/Neon/core/types/vec/vec3d_integer.timp.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ NEON_CUDA_HOST_DEVICE inline Vec_3d<IntegerType_ta, true, false> Vec_3d<IntegerT
}


template <typename IntegerType_ta>
NEON_CUDA_HOST_DEVICE inline Vec_3d<IntegerType_ta, true, false> Vec_3d<IntegerType_ta, true, false>::operator-() const
{
Vec_3d<Integer> res(-x, -y, -z);
return res;
}

template <typename IntegerType_ta>
NEON_CUDA_HOST_DEVICE inline bool Vec_3d<IntegerType_ta, true, false>::operator>(const Vec_3d<IntegerType_ta, true, false>& B) const
{
Expand Down
2 changes: 1 addition & 1 deletion libNeonDomain/include/Neon/domain/internal/bGrid/bCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class bCell
//i.e., each entry in the mask array store the state of 32 voxels
static constexpr uint32_t sMaskSize = 32;

bCell() = default;
bCell();
virtual ~bCell() = default;

NEON_CUDA_HOST_DEVICE inline auto isActive() const -> bool;
Expand Down
10 changes: 10 additions & 0 deletions libNeonDomain/include/Neon/domain/internal/bGrid/bCell_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

namespace Neon::domain::internal::bGrid {

NEON_CUDA_HOST_DEVICE inline bCell::bCell()
: mLocation(std::numeric_limits<Location::Integer>::max(),
std::numeric_limits<Location::Integer>::max(),
std::numeric_limits<Location::Integer>::max()),
mBlockID(std::numeric_limits<uint32_t>::max()),
mIsActive(false),
mBlockSize(-1)
{
}

NEON_CUDA_HOST_DEVICE inline bCell::bCell(const Location& location)
{
mLocation = location;
Expand Down
2 changes: 1 addition & 1 deletion libNeonDomain/include/Neon/domain/internal/bGrid/bGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class bGrid : public Neon::domain::interface::GridBaseTemplate<bGrid, bCell>


auto getOrigins() const -> const Neon::set::MemSet_t<Neon::int32_3d>&;
auto getNeighbourBlocks() const -> const Neon::set::MemSet_t<uint32_t>&;
auto getNeighbourBlocks() const -> Neon::set::MemSet_t<uint32_t>&;
auto getActiveMask() const -> Neon::set::MemSet_t<uint32_t>&;
auto getBlockOriginTo1D() const -> Neon::domain::tool::PointHashTable<int32_t, uint32_t>&;

Expand Down
6 changes: 4 additions & 2 deletions libNeonDomain/include/Neon/domain/internal/bGrid/bPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class bPartition
NEON_CUDA_HOST_DEVICE inline auto nghVal(const Cell& eId,
uint8_t nghID,
int card,
const T& alternativeVal) const -> NghInfo<T>;
const T& alternativeVal) const -> NghInfo<T>;


NEON_CUDA_HOST_DEVICE inline void loadInSharedMemory(const Cell& cell,
Expand All @@ -62,11 +62,13 @@ class bPartition

NEON_CUDA_HOST_DEVICE inline Neon::index_3d mapToGlobal(const Cell& cell) const;

inline NEON_CUDA_HOST_DEVICE auto getNghCell(const Cell& cell, const nghIdx_t& offset) const -> Cell;

protected:
inline NEON_CUDA_HOST_DEVICE auto pitch(const Cell& cell, int card) const -> uint32_t;
inline NEON_CUDA_HOST_DEVICE auto setNghCell(const Cell& cell, const nghIdx_t& offset) const -> Cell;
inline NEON_CUDA_HOST_DEVICE auto getNghCell(const Cell& cell, const nghIdx_t& offset, const uint32_t* neighbourBlocks) const -> Cell;
inline NEON_CUDA_HOST_DEVICE auto shmemPitch(Cell cell, const int card) const -> Cell::Location::Integer;
inline NEON_CUDA_HOST_DEVICE auto getneighbourBlocksPtr(const Cell& cell) const -> const uint32_t*;

Neon::DataView mDataView;
T* mMem;
Expand Down
39 changes: 26 additions & 13 deletions libNeonDomain/include/Neon/domain/internal/bGrid/bPartition_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bPartition<T, C>::bPartition()
mNeighbourBlocks(nullptr),
mOrigin(nullptr),
mMask(nullptr),
mOutsideValue(0),
mOutsideValue(T()),
mStencilNghIndex(nullptr),
mIsInSharedMem(false),
mMemSharedMem(nullptr),
Expand Down Expand Up @@ -111,8 +111,25 @@ inline NEON_CUDA_HOST_DEVICE auto bPartition<T, C>::pitch(const Cell& cell, int
}

template <typename T, int C>
NEON_CUDA_HOST_DEVICE inline auto bPartition<T, C>::setNghCell(const Cell& cell,
const nghIdx_t& offset) const -> Cell
NEON_CUDA_HOST_DEVICE inline auto bPartition<T, C>::getneighbourBlocksPtr(const Cell& cell) const -> const uint32_t*
{
if (mSharedNeighbourBlocks != nullptr) {
return mSharedNeighbourBlocks;
} else {
return mNeighbourBlocks + (26 * cell.mBlockID);
}
}

template <typename T, int C>
NEON_CUDA_HOST_DEVICE inline auto bPartition<T, C>::getNghCell(const Cell& cell, const nghIdx_t& offset) const -> Cell
{
return getNghCell(cell, offset, getneighbourBlocksPtr(cell));
}

template <typename T, int C>
NEON_CUDA_HOST_DEVICE inline auto bPartition<T, C>::getNghCell(const Cell& cell,
const nghIdx_t& offset,
const uint32_t* neighbourBlocks) const -> Cell
{
Cell ngh_cell(cell.mLocation.x + offset.x,
cell.mLocation.y + offset.y,
Expand Down Expand Up @@ -151,15 +168,12 @@ NEON_CUDA_HOST_DEVICE inline auto bPartition<T, C>::setNghCell(const Cell& c
ngh_cell.mLocation.z -= cell.mBlockSize;
}

if (mSharedNeighbourBlocks != nullptr) {
ngh_cell.mBlockID = mSharedNeighbourBlocks[Cell::getNeighbourBlockID(block_offset)];
} else {
ngh_cell.mBlockID = mNeighbourBlocks[26 * cell.mBlockID + Cell::getNeighbourBlockID(block_offset)];
}
ngh_cell.mBlockID = neighbourBlocks[Cell::getNeighbourBlockID(block_offset)];

} else {
ngh_cell.mBlockID = cell.mBlockID;
}
ngh_cell.mIsActive = (ngh_cell.mBlockID != std::numeric_limits<uint32_t>::max());
return ngh_cell;
}

Expand Down Expand Up @@ -191,9 +205,9 @@ NEON_CUDA_HOST_DEVICE inline auto bPartition<T, C>::nghVal(const Cell& cell,
Cell swirl_cell = cell.toSwirl();
swirl_cell.mBlockSize = cell.mBlockSize;

Cell ngh_cell = setNghCell(swirl_cell, offset);
Cell ngh_cell = getNghCell(swirl_cell, offset, getneighbourBlocksPtr(swirl_cell));
ngh_cell.mBlockSize = cell.mBlockSize;
if (ngh_cell.mBlockID != std::numeric_limits<uint32_t>::max()) {
if (ngh_cell.isActive()) {
//TODO maybe ngh_cell should be mapped to its memory layout
ret.isValid = ngh_cell.computeIsActive(mMask);
if (ret.isValid) {
Expand All @@ -207,9 +221,8 @@ NEON_CUDA_HOST_DEVICE inline auto bPartition<T, C>::nghVal(const Cell& cell,
}

} else {
Cell ngh_cell = setNghCell(cell, offset);
ngh_cell.mBlockSize = cell.mBlockSize;
if (ngh_cell.mBlockID != std::numeric_limits<uint32_t>::max()) {
Cell ngh_cell = getNghCell(cell, offset, getneighbourBlocksPtr(cell));
if (ngh_cell.isActive()) {
ret.isValid = ngh_cell.computeIsActive(mMask);
if (ret.isValid) {
if (mIsInSharedMem) {
Expand Down
8 changes: 5 additions & 3 deletions libNeonDomain/include/Neon/domain/internal/mGrid/mField.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ class mField
Neon::computeMode_t::computeMode_e mode = Neon::computeMode_t::computeMode_e::par) -> void;


auto ioToVtk(const std::string& fileName,
const std::string& FieldName,
Neon::IoFileType ioFileType = Neon::IoFileType::ASCII) const -> void;
auto ioToVtk(std::string fileName,
bool outputLevels = true,
bool outputBlockID = true,
bool outputVoxelID = true,
bool filterOverlaps = true) const -> void;

auto load(Neon::set::Loader loader, int level, Neon::MultiResCompute compute) -> typename xField<T, C>::Partition&;

Expand Down
Loading

0 comments on commit 3b98084

Please sign in to comment.