Skip to content

Commit

Permalink
openssf issue (#12)
Browse files Browse the repository at this point in the history
* openssf issue

* update namespaces

* github auto disabled scheduled workflows on inactive repos

* pre-commit issues

* build issues

* avoid double test

* save file
  • Loading branch information
rscohn2 authored Sep 23, 2024
1 parent 1515916 commit c267492
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 83 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/docker_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
# 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:
name: Run pre-commit
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/[email protected]
- name: Run checkers
run: |
pip install pre-commit
pre-commit run --all
run_examples:
name: Build and run examples
runs-on: ubuntu-latest
Expand All @@ -38,9 +41,7 @@ jobs:
- ${{ github.workspace }}:/src
steps:
- name: Check out
uses: actions/checkout@v3
- name: Setup cmake
uses: jwlawson/[email protected]
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Build examples
run: |
cmake -B build
Expand Down
18 changes: 8 additions & 10 deletions src/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,29 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include <dr/mhp.hpp>
#include <dr/mp.hpp>
#include <fmt/core.h>

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<char> dv(81);
dr::mp::distributed_vector<char> 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;
}
20 changes: 9 additions & 11 deletions src/example2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include <dr/mhp.hpp>
#include <dr/mp.hpp>
#include <fmt/core.h>

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<int> v(n);
mhp::iota(v, 1);
dr::mp::distributed_vector<int> 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;
}
20 changes: 9 additions & 11 deletions src/example3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include <dr/mhp.hpp>
#include <dr/mp.hpp>
#include <fmt/core.h>

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
Expand All @@ -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<uint8_t> a1(asize + 2, 0, dist),
auto dist = dr::mp::distribution().halo(1);
dr::mp::distributed_vector<uint8_t> a1(asize + 2, 0, dist),
a2(asize + 2, 0, dist);

auto in = rng::subrange(a1.begin() + 1, a1.end() - 1);
Expand All @@ -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;
}
21 changes: 10 additions & 11 deletions src/example4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,40 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include <dr/mhp.hpp>
#include <dr/mp.hpp>
#include <fmt/core.h>

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<std::size_t, 2> extents2d = {xdim, ydim};

// any array with corresponding dimensions can be used
mhp::distributed_mdarray<T, 2> a(extents2d);
mhp::distributed_mdarray<T, 2> b(extents2d);
mhp::distributed_mdarray<T, 2> c(extents2d);
dr::mp::distributed_mdarray<T, 2> a(extents2d);
dr::mp::distributed_mdarray<T, 2> b(extents2d);
dr::mp::distributed_mdarray<T, 2> 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;
}
26 changes: 12 additions & 14 deletions src/example5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,46 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include <dr/mhp.hpp>
#include <dr/mp.hpp>
#include <fmt/core.h>

namespace mhp = dr::mhp;

using T = float;
using MDA = dr::mhp::distributed_mdarray<T, 2>;
using MDA = dr::mp::distributed_mdarray<T, 2>;

/* 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;
}
26 changes: 12 additions & 14 deletions src/example6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include <dr/mhp.hpp>
#include <dr/mp.hpp>
#include <fmt/core.h>

namespace mhp = dr::mhp;

using T = uint16_t;
using MDA = dr::mhp::distributed_mdarray<T, 2>;
using MDA = dr::mp::distributed_mdarray<T, 2>;

/* 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
Expand All @@ -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) {
Expand All @@ -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;
}

0 comments on commit c267492

Please sign in to comment.