Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into container
Browse files Browse the repository at this point in the history
  • Loading branch information
massimim committed Aug 8, 2022
2 parents 0a944c3 + 13c5e28 commit b2cefa1
Show file tree
Hide file tree
Showing 30 changed files with 1,351 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
Thank you for your submission, we really appreciate it. We ask that you sign our Contributor License Agreement before we can accept your contribution.
If you are contributing on behalf of your employer you must fill out our **Corporate Contributor License Agreement** which can be found [here](https://github.com/Autodesk/autodesk.github.io/releases/download/1.0/ADSK.Form.Corp.Contrib.Agmt.for.Open.Source.docx).
If you are contributing on behalf of yourself you must agree to our **Individual Contributor License Agreement** by reviewing [this document](https://github.com/Autodesk/autodesk.github.io/releases/download/1.0/ADSK.Form.Ind.Contrib.Agmt.for.Open.Source.docx) and signing it or by replying below a with a comment containing the following text:
If you are contributing on behalf of yourself you must agree to our **Individual Contributor License Agreement** by reviewing [this document](https://github.com/Autodesk/autodesk.github.io/releases/download/1.0/ADSK.Form.Ind.Contrib.Agmt.for.Open.Source.docx) and signing it or by replying below with a comment containing the following text:
#custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA'
#custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
#lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
#use-dco-flag: true - If you are using DCO instead of CLA
#use-dco-flag: true - If you are using DCO instead of CLA
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ add_subdirectory("libNeonSet")
add_subdirectory("libNeonDomain")
add_subdirectory("libNeonSkeleton")
add_subdirectory("libNeonSolver")
add_subdirectory("apps")


#-------------------------------------------------------------------#
Expand Down Expand Up @@ -107,5 +108,4 @@ message("|| CUDA Compile flags : ${CMAKE_CUDA_FLAGS}")
message("|| CUDA ARCHS : ${CMAKE_CUDA_ARCHITECTURES}")
#message("|| NeonCXXFlags : ${NeonCXXFlags}")
#message("|| NeonCUDAFlags : ${NeonCUDAFlags}")
message("||")
message("\\===================================================")
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ Neon is licenced under the Apache License, Version 2.0. For more information ple
## How to cite Neon

```
@article{Meneghin:2022:NAM,
title = {Neon: A Multi-GPU Programming Model for Grid-based Computations},
booktitle = {Proceedings of the 36th IEEE International Parallel and Distributed Processing Symposium},
series = {IPDPS 2022},
year = 2022,
month = june,
author = {Meneghin, Massimiliano and Mahmoud, Ahmed H. and Jayaraman, Pradeep Kumar and Morris, Nigel J. W.},
url = {https://escholarship.org/uc/item/9fz7k633}
@INPROCEEDINGS{Meneghin:2022:NAM,
author = {Meneghin, Massimiliano and Mahmoud, Ahmed H. and Jayaraman, Pradeep Kumar and Morris, Nigel J. W.},
booktitle = {Proceedings of the 36th IEEE International Parallel and Distributed Processing Symposium},
title = {Neon: A Multi-GPU Programming Model for Grid-based Computations},
year = {2022},
month = {june},
pages = {817--827},
doi = {10.1109/IPDPS53621.2022.00084},
url = {https://escholarship.org/uc/item/9fz7k633}
}
```
6 changes: 6 additions & 0 deletions apps/CMakeLists.txt
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")
17 changes: 17 additions & 0 deletions apps/fractal/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-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})
96 changes: 96 additions & 0 deletions apps/fractal/fractal.cu
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);
}
}
}
Binary file added apps/fractal/fractals.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions apps/gameOfLife/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-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})
Binary file added apps/gameOfLife/conways.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
163 changes: 163 additions & 0 deletions apps/gameOfLife/gameOfLife.cu
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;
}
17 changes: 17 additions & 0 deletions apps/lbm/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-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})
Loading

0 comments on commit b2cefa1

Please sign in to comment.