Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating apps to the latest Neon API. #55

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)

#add_subdirectory("fractal")
#add_subdirectory("lbm")
#add_subdirectory("gameOfLife")
add_subdirectory("fractal")
add_subdirectory("lbm")
add_subdirectory("gameOfLife")
#add_subdirectory("poisson")
add_subdirectory("lbmMultiRes")
#add_subdirectory("lbmMultiRes")
18 changes: 9 additions & 9 deletions apps/fractal/fractal.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "Neon/domain/dGrid.h"
#include "Neon/skeleton/Skeleton.h"

template <typename FieldT>
inline void draw_pixels(const int t, FieldT& field)
template <typename Field>
inline void draw_pixels(const int t, Field& field)
{
printf("\n Exporting Frame =%d", t);
int precision = 4;
Expand All @@ -28,19 +28,19 @@ NEON_CUDA_HOST_DEVICE inline Neon::float_2d complex_pow(Neon::float_2d& z, Neon:
return Neon::float_2d(radius * cos(angle), radius * sin(angle));
}

template <typename FieldT>
inline Neon::set::Container FractalsContainer(FieldT& pixels,
template <typename Field>
inline Neon::set::Container FractalsContainer(Field& pixels,
int32_t& time,
int32_t n)
{
return pixels.getGrid().getContainer(
return pixels.getGrid().newContainer(
"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);
const typename Field::Idx& idx) mutable {
auto id = px.getGlobalIndex(idx);

Neon::float_2d c(-0.8, cos(t * 0.03) * 0.2);
Neon::float_2d z((float(id.x) / float(n)) - 1.0f,
Expand All @@ -59,7 +59,7 @@ inline Neon::set::Container FractalsContainer(FieldT& pixels,
int main(int argc, char** argv)
{
Neon::init();
if (Neon::sys::globalSpace::gpuSysObjStorage.numDevs() > 0) {
if ( Neon::Backend::countAvailableGpus() > 0) {
int32_t n = 320;
Neon::index_3d dim(2 * n, n, 1);
std::vector<int> gpu_ids{0};
Expand Down Expand Up @@ -90,7 +90,7 @@ int main(int argc, char** argv)
skeleton.run();

pixels.updateHostData(0);
//draw_pixels(time, pixels);
draw_pixels(time, pixels);
}
}
}
50 changes: 25 additions & 25 deletions apps/gameOfLife/gameOfLife.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#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)
template <typename Field>
inline void exportVTI(Field& voxel_1, Field& voxel_2, int frame_id)
{
auto io = [&](int f, FieldT& voxel) {
auto io = [&](int f, Field& voxel) {
printf("\n Exporting Frame =%d", f);
int precision = 4;
voxel.updateHostData(0);
Expand All @@ -39,66 +39,66 @@ Neon::domain::Stencil createStencil()
return Neon::domain::Stencil(stencil);
}

template <typename FieldT>
inline Neon::set::Container GoLContainer(const FieldT& in_cells,
FieldT& out_cells,
typename FieldT::Type length)
template <typename Field>
inline Neon::set::Container GoLContainer(const Field& in_cells,
Field& out_cells,
typename Field::Type length)
{
using T = typename FieldT::Type;
return in_cells.getGrid().getContainer(
using T = typename Field::Type;
return in_cells.getGrid().newContainer(
"GoLContainer", [&, length](Neon::set::Loader& L) {
const auto& ins = L.load(in_cells, Neon::Compute::STENCIL);
const auto& ins = L.load(in_cells, Neon::Pattern::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;
const typename Field::Idx& idx) mutable {
typename Field::NghIdx ngh(0, 0, 0);
const T default_value = 0;
int alive = 0;
T value = 0;
T status = ins.getNghData(idx, ngh, 0, default_value).getData();

//+x
ngh.x = 1;
ngh.y = 0;
ngh.z = 0;
value = ins.nghVal(idx, ngh, 0, default_value).value;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
alive += (value > 0.0 ? 1 : 0);
ngh.y = 1;
value = ins.nghVal(idx, ngh, 0, default_value).value;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
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;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
alive += (value > 0.0 ? 1 : 0);
ngh.y = -1;
value = ins.nghVal(idx, ngh, 0, default_value).value;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
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;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
alive += (value > 0.0 ? 1 : 0);
ngh.x = -1;
value = ins.nghVal(idx, ngh, 0, default_value).value;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
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;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
alive += (value > 0.0 ? 1 : 0);
ngh.x = 1;
value = ins.nghVal(idx, ngh, 0, default_value).value;
value = ins.getNghData(idx, ngh, 0, default_value).getData();
alive += (value > 0.0 ? 1 : 0);

auto id_global = ins.mapToGlobal(idx);
auto id_global = ins.getGlobalIndex(idx);
out(idx, 0) = ((T)id_global.x / length) * (T)((alive == 3 || (alive == 2 && status) ? 1 : 0));
};
});
Expand Down
Loading
Loading