Skip to content

Commit

Permalink
ci-mlir: add Ninja
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Nov 15, 2023
1 parent 0761781 commit ebfb1ee
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci-mlir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

name: CI - MLIR-based Testing

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
# Trigger the workflow on push or pull request,
# but only for the master branch
Expand Down Expand Up @@ -91,7 +95,7 @@ jobs:
if: steps.cache-binary.outputs.cache-hit != 'true'
run: |
cd llvm-project/build
cmake --build . --target mlir-opt mlir-cpu-runner
ninja
- name: Test with pytest and generate code coverage
run: |
Expand Down
96 changes: 94 additions & 2 deletions tests/test_xdsl_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from devito import Grid, TimeFunction, Eq, XDSLOperator
import numpy as np
import pytest

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


def test_xdsl_I():
Expand Down Expand Up @@ -34,4 +37,93 @@ def test_xdsl_III():
op = XDSLOperator([eq], opt=None)
op.apply(time_M=1)
assert (u.data[1, :] == 1.).all()
assert (u.data[0, :] == 2.).all()
assert (u.data[0, :] == 2.).all()


def test_diffusion_2D():
# Define a simple Devito Operator
grid = Grid(shape=(3, 3))

# Devito setup
f = TimeFunction(name='f', grid=grid, space_order=2)
f.data[:] = 1
eqn = Eq(f.dt, 0.5 * f.laplace)
op = Operator(Eq(f.forward, solve(eqn, f.forward)))
op.apply(time_M=1, dt=0.1)

# xDSL-Devito setup
f2 = TimeFunction(name='f2', grid=grid, space_order=2)
f2.data[:] = 1
eqn = Eq(f2.dt, 0.5 * f2.laplace)
op = XDSLOperator(Eq(f2.forward, solve(eqn, f2.forward)))
op.apply(time_M=1, dt=0.1)

assert np.isclose(f.data, f2.data, rtol=1e-06).all()


@pytest.mark.parametrize('shape', [(11, 11), (31, 31), (51, 51), (101, 101)])
def test_diffusion_2D_II(shape):
# Define a simple Devito Operator
grid = Grid(shape=shape)
rng = np.random.default_rng(123)
dx = 2. / (shape[0] - 1)
dy = 2. / (shape[1] - 1)
sigma = .1
dt = sigma * dx * dy
nt = 10

arr1 = rng.random(shape)

# Devito setup
f = TimeFunction(name='f', grid=grid, space_order=2)
f.data[:] = arr1
eqn = Eq(f.dt, 0.5 * f.laplace)
op = Operator(Eq(f.forward, solve(eqn, f.forward)))
op.apply(time_M=nt, dt=dt)

# xDSL-Devito setup
f2 = TimeFunction(name='f2', grid=grid, space_order=2)
f2.data[:] = arr1
eqn = Eq(f2.dt, 0.5 * f2.laplace)
op = XDSLOperator(Eq(f2.forward, solve(eqn, f2.forward)))
op.apply(time_M=nt, dt=dt)

max_error = np.max(np.abs(f.data - f2.data))
assert np.isclose(max_error, 0.0, atol=1e-04)
assert np.isclose(f.data, f2.data, rtol=1e-05).all()


@pytest.mark.parametrize('shape', [(11, 11, 11), (31, 31, 31), (51, 51, 51), (101, 101, 101)])
def test_diffusion_3D_II(shape):
shape = (10, 10, 10)
grid = Grid(shape=shape)
rng = np.random.default_rng(123)
dx = 2. / (shape[0] - 1)
dy = 2. / (shape[1] - 1)
dz = 2. / (shape[2] - 1)

sigma = .1
dt = sigma * dx * dy * dz
nt = 50

rng = np.random.default_rng(123)

arr1 = rng.random(shape)

# Devito setup
f = TimeFunction(name='f', grid=grid, space_order=2)
f.data[:] = arr1
eqn = Eq(f.dt, 0.5 * f.laplace)
op = Operator(Eq(f.forward, solve(eqn, f.forward)))
op.apply(time_M=nt, dt=dt)

# xDSL-Devito setup
f2 = TimeFunction(name='f2', grid=grid, space_order=2)
f2.data[:] = arr1
eqn = Eq(f2.dt, 0.5 * f2.laplace)
op = XDSLOperator(Eq(f2.forward, solve(eqn, f2.forward)))
op.apply(time_M=50, dt=dt)

max_error = np.max(np.abs(f.data - f2.data))
assert np.isclose(max_error, 0.0, atol=1e-04)
assert np.isclose(f.data, f2.data, rtol=1e-05).all()

0 comments on commit ebfb1ee

Please sign in to comment.