-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adding Poisson solver, LBM, Game of Life, and Fractal application - Fix typo in cla.yml - Updating BibTeX with doi and pages Co-authored-by: Massimiliano <[email protected]>
- Loading branch information
Showing
40 changed files
with
1,357 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ script/* | |
|
||
libNeonCore/src/core/git_sha1.cpp | ||
|
||
temp | ||
temp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.19 FATAL_ERROR) | ||
|
||
add_subdirectory("fractal") | ||
add_subdirectory("lbm") | ||
add_subdirectory("gameOfLife") | ||
add_subdirectory("poisson") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-fractal) | ||
file(GLOB_RECURSE SrcFiles fractal.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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <iomanip> | ||
#include <sstream> | ||
|
||
#include "Neon/Neon.h" | ||
#include "Neon/domain/dGrid.h" | ||
#include "Neon/skeleton/Skeleton.h" | ||
|
||
template <typename FieldT> | ||
inline void draw_pixels(const int t, FieldT& field) | ||
{ | ||
printf("\n Exporting Frame =%d", t); | ||
int precision = 4; | ||
std::ostringstream oss; | ||
oss << std::setw(precision) << std::setfill('0') << t; | ||
std::string fname = "frame_" + oss.str(); | ||
field.ioToVtk(fname, "pixels"); | ||
} | ||
|
||
NEON_CUDA_HOST_DEVICE inline Neon::float_2d complex_sqr(Neon::float_2d& z) | ||
{ | ||
return Neon::float_2d(z.x * z.x - z.y * z.y, z.x * z.y * 2.0f); | ||
} | ||
|
||
NEON_CUDA_HOST_DEVICE inline Neon::float_2d complex_pow(Neon::float_2d& z, Neon::float_1d& n) | ||
{ | ||
Neon::float_1d radius = pow(z.norm(), n); | ||
Neon::float_1d angle = n * atan2(z.y, z.x); | ||
return Neon::float_2d(radius * cos(angle), radius * sin(angle)); | ||
} | ||
|
||
template <typename FieldT> | ||
inline Neon::set::Container FractalsContainer(FieldT& pixels, | ||
int32_t& time, | ||
int32_t n) | ||
{ | ||
return pixels.getGrid().getContainer( | ||
"FractalContainer", [&, n](Neon::set::Loader& L) { | ||
auto& px = L.load(pixels); | ||
auto& t = time; | ||
|
||
return [=] NEON_CUDA_HOST_DEVICE( | ||
const typename FieldT::Cell& idx) mutable { | ||
auto id = px.mapToGlobal(idx); | ||
|
||
Neon::float_2d c(-0.8, cos(t * 0.03) * 0.2); | ||
Neon::float_2d z((float(id.x) / float(n)) - 1.0f, | ||
(float(id.y) / float(n)) - 0.5f); | ||
z *= 2.0f; | ||
float iterations = 0; | ||
while (z.norm() < 20 && iterations < 50) { | ||
z = complex_sqr(z) + c; | ||
iterations += 1; | ||
} | ||
px(idx, 0) = 1.0f - iterations * 0.02; | ||
}; | ||
}); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
Neon::init(); | ||
if (Neon::sys::globalSpace::gpuSysObjStorage.numDevs() > 0) { | ||
int32_t n = 320; | ||
Neon::index_3d dim(2 * n, n, 1); | ||
std::vector<int> gpu_ids{0}; | ||
|
||
auto runtime = Neon::Runtime::stream; | ||
|
||
//runtime = Neon::Runtime::openmp; | ||
|
||
Neon::Backend backend(gpu_ids, runtime); | ||
|
||
using Grid = Neon::domain::dGrid; | ||
Grid grid( | ||
backend, dim, | ||
[](const Neon::index_3d& idx) -> bool { return true; }, | ||
Neon::domain::Stencil::s7_Laplace_t()); | ||
|
||
int cardinality = 1; | ||
float inactiveValue = 0.0f; | ||
auto pixels = grid.template newField<float>("pixels", cardinality, inactiveValue); | ||
|
||
Neon::skeleton::Skeleton skeleton(backend); | ||
|
||
int32_t time; | ||
skeleton.sequence({FractalsContainer(pixels, time, n)}, "fractal"); | ||
|
||
|
||
for (time = 0; time < 1000; ++time) { | ||
skeleton.run(); | ||
|
||
pixels.updateIO(0); | ||
//draw_pixels(time, pixels); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-gameOfLife) | ||
file(GLOB_RECURSE SrcFiles gameOfLife.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}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// References | ||
// https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life | ||
// https://tebs-game-of-life.com/rainbow/rainbow.html | ||
|
||
#include <assert.h> | ||
#include <cstdlib> | ||
#include <iomanip> | ||
#include <vector> | ||
|
||
#include "Neon/Neon.h" | ||
#include "Neon/domain/dGrid.h" | ||
#include "Neon/skeleton/Skeleton.h" | ||
|
||
template <typename FieldT> | ||
inline void exportVTI(FieldT& voxel_1, FieldT& voxel_2, int frame_id) | ||
{ | ||
auto io = [&](int f, FieldT& voxel) { | ||
printf("\n Exporting Frame =%d", f); | ||
int precision = 4; | ||
voxel.updateIO(0); | ||
std::ostringstream oss; | ||
oss << std::setw(precision) << std::setfill('0') << f; | ||
std::string fname = "gameOfLife_" + oss.str(); | ||
voxel.ioToVtk(fname, "GoL"); | ||
}; | ||
io(2 * frame_id, voxel_2); | ||
io(2 * frame_id + 1, voxel_1); | ||
} | ||
|
||
Neon::domain::Stencil createStencil() | ||
{ | ||
std::vector<Neon::index_3d> stencil; | ||
stencil.reserve(9); | ||
for (int x = -1; x <= 1; ++x) { | ||
for (int y = -1; y <= 1; ++y) { | ||
stencil.emplace_back(Neon::index_3d(x, y, 0)); | ||
} | ||
} | ||
return Neon::domain::Stencil(stencil); | ||
} | ||
|
||
template <typename FieldT> | ||
inline Neon::set::Container GoLContainer(const FieldT& in_cells, | ||
FieldT& out_cells, | ||
typename FieldT::Type length) | ||
{ | ||
using T = typename FieldT::Type; | ||
return in_cells.getGrid().getContainer( | ||
"GoLContainer", [&, length](Neon::set::Loader& L) { | ||
const auto& ins = L.load(in_cells, Neon::Compute::STENCIL); | ||
auto& out = L.load(out_cells); | ||
|
||
return [=] NEON_CUDA_HOST_DEVICE( | ||
const typename FieldT::Cell& idx) mutable { | ||
typename FieldT::ngh_idx ngh(0, 0, 0); | ||
const T default_value = 0; | ||
int alive = 0; | ||
T value = 0; | ||
T status = ins.nghVal(idx, ngh, 0, default_value).value; | ||
|
||
//+x | ||
ngh.x = 1; | ||
ngh.y = 0; | ||
ngh.z = 0; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
ngh.y = 1; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
|
||
//-x | ||
ngh.x = -1; | ||
ngh.y = 0; | ||
ngh.z = 0; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
ngh.y = -1; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
|
||
//+y | ||
ngh.x = 0; | ||
ngh.y = 1; | ||
ngh.z = 0; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
ngh.x = -1; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
|
||
//-y | ||
ngh.x = 0; | ||
ngh.y = -1; | ||
ngh.z = 0; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
ngh.x = 1; | ||
value = ins.nghVal(idx, ngh, 0, default_value).value; | ||
alive += (value > 0.0 ? 1 : 0); | ||
|
||
auto id_global = ins.mapToGlobal(idx); | ||
out(idx, 0) = ((T)id_global.x / length) * (T)((alive == 3 || (alive == 2 && status) ? 1 : 0)); | ||
}; | ||
}); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
Neon::init(); | ||
if (Neon::sys::globalSpace::gpuSysObjStorage.numDevs() > 0) { | ||
std::vector<int> gpu_ids{0}; | ||
auto runtime = Neon::Runtime::stream; | ||
Neon::Backend backend(gpu_ids, runtime); | ||
|
||
|
||
const Neon::index_3d grid_dim(256, 256, 1); | ||
const size_t num_frames = 500; | ||
|
||
using T = float; | ||
using Grid = Neon::domain::dGrid; | ||
Grid grid( | ||
backend, grid_dim, | ||
[](const Neon::index_3d& idx) -> bool { return true; }, | ||
createStencil()); | ||
|
||
int cardinality = 1; | ||
float inactiveValue = 0.0f; | ||
auto voxel_1 = grid.template newField<T>("GoL1", cardinality, inactiveValue); | ||
auto voxel_2 = grid.template newField<T>("GoL2", cardinality, inactiveValue); | ||
|
||
std::srand(19937); | ||
voxel_1.forEachActiveCell( | ||
[](const Neon::index_3d& idx, const int&, T& val) { | ||
if (idx.z == 0) { | ||
val = rand() % 2; | ||
} | ||
}); | ||
voxel_2.forEachActiveCell( | ||
[](const Neon::index_3d&, const int&, T& val) { val = 0; }); | ||
|
||
|
||
voxel_1.updateCompute(0); | ||
voxel_2.updateCompute(0); | ||
|
||
|
||
std::vector<Neon::set::Container> containers; | ||
containers.push_back(GoLContainer(voxel_1, voxel_2, T(grid_dim.x))); | ||
containers.push_back(GoLContainer(voxel_2, voxel_1, T(grid_dim.x))); | ||
|
||
Neon::skeleton::Skeleton skeleton(backend); | ||
skeleton.sequence(containers, "GoLSkeleton"); | ||
|
||
|
||
for (int f = 0; f < num_frames / 2; ++f) { | ||
skeleton.run(); | ||
|
||
backend.syncAll(); | ||
exportVTI(voxel_1, voxel_2, f); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-lbm) | ||
file(GLOB_RECURSE SrcFiles lbm.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}) |
Oops, something went wrong.