-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example5 - simple stencil2d (#6)
* add example5 - simple stencil2d * review fixes change to a floating point number remove unused variables
- Loading branch information
1 parent
2a0c52d
commit 633ad92
Showing
4 changed files
with
61 additions
and
3 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
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,49 @@ | ||
// SPDX-FileCopyrightText: Intel Corporation | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <dr/mhp.hpp> | ||
#include <fmt/core.h> | ||
|
||
namespace mhp = dr::mhp; | ||
|
||
using T = float; | ||
using MDA = dr::mhp::distributed_mdarray<T, 2>; | ||
|
||
/* 2d stencil - simple operation on multi-dimensional array */ | ||
int main() { | ||
mhp::init(sycl::default_selector_v); | ||
|
||
std::size_t arr_size = 4; | ||
std::size_t radius = 1; | ||
std::array slice_starts{radius, radius}; | ||
std::array slice_ends{arr_size - radius, arr_size - radius}; | ||
|
||
auto dist = dr::mhp::distribution().halo(radius); | ||
MDA a({arr_size, arr_size}, dist); | ||
MDA b({arr_size, arr_size}, dist); | ||
mhp::iota(a, 1); | ||
mhp::iota(b, 1); | ||
|
||
auto in = dr::mhp::views::submdspan(a.view(), slice_starts, slice_ends); | ||
auto out = dr::mhp::views::submdspan(b.view(), slice_starts, slice_ends); | ||
|
||
auto mdspan_stencil_op = [](auto &&v) { | ||
auto [in, out] = v; | ||
out(0, 0) = (in(-1, 0) + in(0, -1) + in(0, 0) + in(0, 1) + in(1, 0)) / 4; | ||
}; | ||
|
||
mhp::halo(a).exchange(); | ||
mhp::stencil_for_each(mdspan_stencil_op, in, out); | ||
|
||
if (mhp::rank() == 0) { | ||
fmt::print("a: \n{} \n", a.mdspan()); | ||
fmt::print("b: \n{} \n", b.mdspan()); | ||
fmt::print("in: \n{} \n", in.mdspan()); | ||
fmt::print("out: \n{} \n", out.mdspan()); | ||
} | ||
|
||
mhp::finalize(); | ||
|
||
return 0; | ||
} |