Skip to content

Commit

Permalink
Merge pull request #27 from xdslproject/stencil_mad_dash
Browse files Browse the repository at this point in the history
Merge the stencil mad dash branch into master
  • Loading branch information
AntonLydike authored Oct 4, 2023
2 parents 9e4c731 + e203d59 commit 94b77fe
Show file tree
Hide file tree
Showing 76 changed files with 8,885 additions and 802 deletions.
106 changes: 0 additions & 106 deletions .github/workflows/docker-bases.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.8
python-version: "3.10"
activate-environment: devito
environment-file: environment-dev.yml
auto-activate-base: false
Expand Down
138 changes: 69 additions & 69 deletions .github/workflows/pytest-core-nompi.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
name: CI-core
name: CI-core

on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master

jobs:
pytest:
name: ${{ matrix.name }}-${{ matrix.set }}
runs-on: "${{ matrix.os }}"
jobs:
pytest:
name: ${{ matrix.name }}-${{ matrix.set }}
runs-on: "${{ matrix.os }}"

env:
DEVITO_ARCH: "${{ matrix.arch }}"
DEVITO_LANGUAGE: ${{ matrix.language }}
OMP_NUM_THREADS: 2
env:
DEVITO_ARCH: "${{ matrix.arch }}"
DEVITO_LANGUAGE: ${{ matrix.language }}
OMP_NUM_THREADS: 2

strategy:
# Prevent all build to stop if a single one fails
fail-fast: false
strategy:
# Prevent all build to stop if a single one fails
fail-fast: false

matrix:
name: [
pytest-ubuntu-py310-gcc10-noomp
]
set: [base, adjoint]
include:
matrix:
name: [
pytest-ubuntu-py310-gcc10-noomp
]
set: [base, adjoint]
include:

- name: pytest-ubuntu-py310-gcc10-noomp
python-version: '3.10'
os: ubuntu-20.04
arch: "gcc-10"
language: "C"
sympy: "1.10"
- name: pytest-ubuntu-py310-gcc10-noomp
python-version: '3.10'
os: ubuntu-20.04
arch: "gcc-10"
language: "C"
sympy: "1.10"

- set: base
test-set: 'not adjoint'
- set: base
test-set: 'not adjoint'

- set: adjoint
test-set: 'adjoint'
- set: adjoint
test-set: 'adjoint'

exclude:
- name: pytest-osx-py37-clang-omp
set: adjoint
exclude:
- name: pytest-osx-py37-clang-omp
set: adjoint

steps:
- name: Checkout devito
uses: actions/checkout@v3
steps:
- name: Checkout devito
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
if: "!contains(matrix.name, 'docker')"
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
if: "!contains(matrix.name, 'docker')"
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install GCC ${{ matrix.arch }}
if: "runner.os == 'linux' && !contains(matrix.name, 'docker')"
run : |
sudo apt-get install -y ${{ matrix.arch }}
- name: Set tests (reduced number for OSX)
run : |
if [ "${{ runner.os }}" == 'macOS' ]; then
echo "::set-output name=TESTS::tests/test_operator.py"
else
echo "::set-output name=TESTS::tests/"
fi
id: set-tests
- name: Install GCC ${{ matrix.arch }}
if: "runner.os == 'linux' && !contains(matrix.name, 'docker')"
run : |
sudo apt-get install -y ${{ matrix.arch }}
- name: Set tests (reduced number for OSX)
run : |
if [ "${{ runner.os }}" == 'macOS' ]; then
echo "::set-output name=TESTS::tests/test_operator.py"
else
echo "::set-output name=TESTS::tests/"
fi
id: set-tests

- name: Install dependencies
if: "!contains(matrix.name, 'docker')"
run: |
pip install --upgrade pip
pip install -e .
pip install sympy==${{matrix.sympy}}
- name: Test with pytest
run: |
${{ steps.set-run.outputs.RUN_CMD }} ${{ matrix.arch }} --version
- name: Install dependencies
if: "!contains(matrix.name, 'docker')"
run: |
pip install --upgrade pip
pip install -e .
pip install sympy==${{matrix.sympy}}
- name: Test with pytest
run: |
${{ steps.set-run.outputs.RUN_CMD }} ${{ matrix.arch }} --version
${{ steps.set-run.outputs.RUN_CMD }} pytest -k "${{ matrix.test-set }}" -m "not parallel" --cov --cov-config=.coveragerc --cov-report=xml ${{ steps.set-tests.outputs.TESTS }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ docs/_build
.ipynb_checkpoints

devito.egg-info/*
venv
110 changes: 110 additions & 0 deletions 2d5pt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import argparse

import numpy as np

from devito import Constant, Eq, Grid, Operator, TimeFunction, XDSLOperator, solve

from devito.operator.profiling import PerfEntry, PerfKey, PerformanceSummary


def equation_and_time_function(nx: int, ny: int, so: int, to: int, init_value: int):
# Field initialization
grid = Grid(shape=(nx, ny))
u = TimeFunction(name="u", grid=grid, space_order=so, time_order=to)
# Create an equation with second-order derivatives
a = Constant(name="a")
eq = Eq(u.dt, a * u.laplace + 0.01)
stencil = solve(eq, u.forward)
eq0 = Eq(u.forward, stencil)

return (grid, u, eq0)


def run_operator(op: Operator, nt: int, dt: float):
res = op.apply(time_M=nt, a=0.1, dt=dt)
assert isinstance(res, PerformanceSummary)
o = res[PerfKey("section0", None)]
assert isinstance(o, PerfEntry)
return o.time


def main(bench_name: str):
parser = argparse.ArgumentParser(description="Process arguments.")

parser.add_argument(
"-d",
"--shape",
default=(11, 11),
type=int,
nargs="+",
help="Number of grid points along each axis",
)
parser.add_argument(
"-so",
"--space_order",
default=2,
type=int,
help="Space order of the simulation",
)
parser.add_argument(
"-to", "--time_order", default=1, type=int, help="Time order of the simulation"
)
parser.add_argument(
"-nt", "--nt", default=10, type=int, help="Simulation time in millisecond"
)
parser.add_argument(
"-bls", "--blevels", default=2, type=int, nargs="+", help="Block levels"
)
parser.add_argument("-xdsl", "--xdsl", default=False, action="store_true")
parser.add_argument("--mpi", default=False, action="store_true", help="run in MPI mode")
parser.add_argument("-nd", "--no_dump", default=False, action="store_true")
args = parser.parse_args()

nx, ny = args.shape
nt = args.nt
nu = 0.5
dx = 2.0 / (nx - 1)
dy = 2.0 / (ny - 1)
sigma = 0.25
dt = sigma * dx * dy / nu

so = args.space_order
to = args.time_order

init_value = 10

grid, u, eq0 = equation_and_time_function(nx, ny, so, to, init_value)

u.data[:, :, :] = 0
u.data[:, int(nx / 2), int(ny / 2)] = init_value
u.data[:, int(nx / 2), -int(ny / 2)] = -init_value

print("xdsl:", flush=True)

xop = XDSLOperator([eq0])
xop.apply(time_M=nt, a=0.1, dt=dt)

x_data = u.data.copy()

u.data[:, :, :] = 0
u.data[:, int(nx / 2), int(ny / 2)] = init_value
u.data[:, int(nx / 2), -int(ny / 2)] = -init_value

print("devito:", flush=True)

op = Operator([eq0])
op.apply(time_M=nt, a=0.1, dt=dt)

d_data = u.data

#print("mean squared error:", ((d_data - x_data)**2).mean())
#print("max abs error", np.abs((d_data - x_data)).max())
#print("max abs val", max(np.abs(d_data).max(), np.abs(x_data).max()))

if np.abs((d_data - x_data)).max() > 1e-5:
print(f"Failure, max abs error too high: {np.abs((d_data - x_data)).max()}")


if __name__ == "__main__":
bench_name = __file__.split(".")[0]
main(bench_name)
Loading

0 comments on commit 94b77fe

Please sign in to comment.