diff --git a/.github/workflows/docker_workflow.yml b/.github/workflows/docker_workflow.yml index d1152b5..80ca430 100644 --- a/.github/workflows/docker_workflow.yml +++ b/.github/workflows/docker_workflow.yml @@ -3,14 +3,14 @@ # SPDX-License-Identifier: BSD-3-Clause name: Docker +permissions: read-all on: - push: pull_request: workflow_dispatch: - # 8am UTC is 12am PST, 1am PDT - schedule: - - cron: '0 8 * * *' + push: + branches: + - main jobs: run_precommit: @@ -18,14 +18,17 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out - uses: actions/checkout@v3 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 with: - python-version: '3.10' + python-version: '3.11' cache: 'pip' - - name: Run pre-commit - uses: pre-commit/action@v3.0.0 + - name: Run checkers + run: | + pip install pre-commit + pre-commit run --all + run_examples: name: Build and run examples runs-on: ubuntu-latest @@ -38,9 +41,7 @@ jobs: - ${{ github.workspace }}:/src steps: - name: Check out - uses: actions/checkout@v3 - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.13 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Build examples run: | cmake -B build diff --git a/src/example1.cpp b/src/example1.cpp index 00394b5..b512116 100644 --- a/src/example1.cpp +++ b/src/example1.cpp @@ -2,31 +2,29 @@ // // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include -namespace mhp = dr::mhp; - int main(int argc, char **argv) { - mhp::init(sycl::default_selector_v); + dr::mp::init(sycl::default_selector_v); - mhp::distributed_vector dv(81); + dr::mp::distributed_vector dv(81); std::string decoded_string(80, 0); - mhp::copy( + dr::mp::copy( 0, std::string("Mjqqt%|twqi&%Ymnx%nx%ywfsxrnxnts%kwtr%ymj%tsj%fsi%tsq~%" "Inxywngzyji%Wfsljx%wjfqr&"), dv.begin()); - mhp::for_each(dv, [](char &val) { val -= 5; }); - mhp::copy(0, dv, decoded_string.begin()); + dr::mp::for_each(dv, [](char &val) { val -= 5; }); + dr::mp::copy(0, dv, decoded_string.begin()); - if (mhp::rank() == 0) + if (dr::mp::rank() == 0) fmt::print("{}\n", decoded_string); - mhp::finalize(); + dr::mp::finalize(); return 0; } diff --git a/src/example2.cpp b/src/example2.cpp index ed9f3f1..5829cdf 100644 --- a/src/example2.cpp +++ b/src/example2.cpp @@ -2,35 +2,33 @@ // // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include -namespace mhp = dr::mhp; - int main(int argc, char **argv) { - mhp::init(sycl::default_selector_v); + dr::mp::init(sycl::default_selector_v); fmt::print( "Hello, World! Distributed ranges process is running on rank {} / {} on " "host {}\n", - mhp::rank(), mhp::nprocs(), mhp::hostname()); + dr::mp::rank(), dr::mp::nprocs(), dr::mp::hostname()); std::size_t n = 100; - mhp::distributed_vector v(n); - mhp::iota(v, 1); + dr::mp::distributed_vector v(n); + dr::mp::iota(v, 1); - if (mhp::rank() == 0) { + if (dr::mp::rank() == 0) { auto &&segments = v.segments(); fmt::print("Created distributed vector of size {} with {} segments.\n", v.size(), segments.size()); } - fmt::print("Rank {} owns segment of size {} and content {}\n", mhp::rank(), - mhp::local_segment(v).size(), mhp::local_segment(v)); + fmt::print("Rank {} owns segment of size {} and content {}\n", dr::mp::rank(), + dr::mp::local_segment(v).size(), dr::mp::local_segment(v)); - mhp::finalize(); + dr::mp::finalize(); return 0; } diff --git a/src/example3.cpp b/src/example3.cpp index 236a995..a9c0c0a 100644 --- a/src/example3.cpp +++ b/src/example3.cpp @@ -2,11 +2,9 @@ // // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include -namespace mhp = dr::mhp; - /* The example simulates the elementary 1-d cellular automaton. Description of * what the automaton is and how it works can be found at * https://en.wikipedia.org/wiki/Elementary_cellular_automaton @@ -27,10 +25,10 @@ auto newvalue = [](auto &&p) { int main(int argc, char **argv) { - mhp::init(sycl::default_selector_v); + dr::mp::init(sycl::default_selector_v); - auto dist = dr::mhp::distribution().halo(1); - mhp::distributed_vector a1(asize + 2, 0, dist), + auto dist = dr::mp::distribution().halo(1); + dr::mp::distributed_vector a1(asize + 2, 0, dist), a2(asize + 2, 0, dist); auto in = rng::subrange(a1.begin() + 1, a1.end() - 1); @@ -39,23 +37,23 @@ int main(int argc, char **argv) { /* initial value of the automaton - customize it if you want to */ in[0] = 1; - if (mhp::rank() == 0) + if (dr::mp::rank() == 0) fmt::print("{}\n", in); for (std::size_t s = 0; s < steps; s++) { - dr::mhp::halo(in).exchange(); + dr::mp::halo(in).exchange(); - mhp::transform(in, out.begin(), newvalue); + dr::mp::transform(in, out.begin(), newvalue); std::swap(in, out); /* fmt::print() is rather slow here, as it gets element by element from * remote nodes. Use with care. */ - if (mhp::rank() == 0) + if (dr::mp::rank() == 0) fmt::print("{}\n", in); } - mhp::finalize(); + dr::mp::finalize(); return 0; } diff --git a/src/example4.cpp b/src/example4.cpp index c3cfc73..3bba51d 100644 --- a/src/example4.cpp +++ b/src/example4.cpp @@ -2,41 +2,40 @@ // // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include -namespace mhp = dr::mhp; using T = int; int main(int argc, char **argv) { - mhp::init(sycl::default_selector_v); + dr::mp::init(sycl::default_selector_v); std::size_t xdim = 9, ydim = 5; std::array extents2d = {xdim, ydim}; // any array with corresponding dimensions can be used - mhp::distributed_mdarray a(extents2d); - mhp::distributed_mdarray b(extents2d); - mhp::distributed_mdarray c(extents2d); + dr::mp::distributed_mdarray a(extents2d); + dr::mp::distributed_mdarray b(extents2d); + dr::mp::distributed_mdarray c(extents2d); // try populating the arrays with any data - mhp::iota(a, 100); - mhp::iota(b, 200); + dr::mp::iota(a, 100); + dr::mp::iota(b, 200); auto sum_op = [](auto v) { auto [in1, in2, out] = v; out = in1 + in2; }; - mhp::for_each(sum_op, a, b, c); + dr::mp::for_each(sum_op, a, b, c); - if (mhp::rank() == 0) { + if (dr::mp::rank() == 0) { fmt::print("A:\n{}\n", a.mdspan()); fmt::print("B:\n{}\n", b.mdspan()); fmt::print("C:\n{}\n", c.mdspan()); } - mhp::finalize(); + dr::mp::finalize(); return 0; } diff --git a/src/example5.cpp b/src/example5.cpp index b19d9b5..97964dc 100644 --- a/src/example5.cpp +++ b/src/example5.cpp @@ -2,48 +2,46 @@ // // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include -namespace mhp = dr::mhp; - using T = float; -using MDA = dr::mhp::distributed_mdarray; +using MDA = dr::mp::distributed_mdarray; /* 2d stencil - simple operation on multi-dimensional array */ int main() { - mhp::init(sycl::default_selector_v); + dr::mp::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 = mhp::distribution().halo(radius); + auto dist = dr::mp::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); + dr::mp::iota(a, 1); + dr::mp::iota(b, 1); - auto in = mhp::views::submdspan(a.view(), slice_starts, slice_ends); - auto out = mhp::views::submdspan(b.view(), slice_starts, slice_ends); + auto in = dr::mp::views::submdspan(a.view(), slice_starts, slice_ends); + auto out = dr::mp::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); + dr::mp::halo(a).exchange(); + dr::mp::stencil_for_each(mdspan_stencil_op, in, out); - if (mhp::rank() == 0) { + if (dr::mp::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(); + dr::mp::finalize(); return 0; } diff --git a/src/example6.cpp b/src/example6.cpp index 8470329..b434bf8 100644 --- a/src/example6.cpp +++ b/src/example6.cpp @@ -2,17 +2,15 @@ // // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include -namespace mhp = dr::mhp; - using T = uint16_t; -using MDA = dr::mhp::distributed_mdarray; +using MDA = dr::mp::distributed_mdarray; /* 2D pattern search in a distributed multidimensional (2D) array */ int main() { - mhp::init(sycl::default_selector_v); + dr::mp::init(sycl::default_selector_v); std::size_t arr_size = 7; // keep in mind that if you change the pattern size, you have to also change @@ -22,16 +20,16 @@ int main() { std::array slice_starts{radius - 1, radius - 1}; std::array slice_ends{arr_size - radius, arr_size - radius}; - auto dist = dr::mhp::distribution().halo(radius); + auto dist = dr::mp::distribution().halo(radius); MDA a({arr_size, arr_size}, dist); MDA occurrences_coords({arr_size, arr_size}); - mhp::iota(a, 1); - mhp::transform(a, a.begin(), [](auto &&v) { return v % 2; }); - mhp::fill(occurrences_coords, 0); + dr::mp::iota(a, 1); + dr::mp::transform(a, a.begin(), [](auto &&v) { return v % 2; }); + dr::mp::fill(occurrences_coords, 0); auto a_submdspan = - dr::mhp::views::submdspan(a.view(), slice_starts, slice_ends); + dr::mp::views::submdspan(a.view(), slice_starts, slice_ends); int pattern[pattern_size][pattern_size] = {{1, 0}, {0, 1}}; auto mdspan_pattern_op = [pattern](auto &&v) { @@ -44,16 +42,16 @@ int main() { } }; - mhp::halo(a).exchange(); - mhp::stencil_for_each(mdspan_pattern_op, a_submdspan, occurrences_coords); + dr::mp::halo(a).exchange(); + dr::mp::stencil_for_each(mdspan_pattern_op, a_submdspan, occurrences_coords); - if (mhp::rank() == 0) { + if (dr::mp::rank() == 0) { fmt::print("a: \n{} \n", a.mdspan()); fmt::print("pattern: \n{} \n", pattern); fmt::print("occurrences: \n{} \n", occurrences_coords.mdspan()); } - mhp::finalize(); + dr::mp::finalize(); return 0; }