Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
0b92950
compiler: Add FuncPtrCall
ZoeLeibowitz Dec 13, 2023
ceba1b9
misc: Update docstring
ZoeLeibowitz Dec 13, 2023
1c8ef94
compiler: Edit names, move position of Callback and other small edits
ZoeLeibowitz Dec 19, 2023
1d6c21e
misc: Update docstring for Callback
ZoeLeibowitz Jan 5, 2024
1b50fc7
misc: Clean up blank lines
ZoeLeibowitz Jan 6, 2024
dd3b021
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
8302ea1
try petscfunc from abstractfunc
ZoeLeibowitz Nov 27, 2023
e7e5c5f
latest.
ZoeLeibowitz Nov 30, 2023
5fa3ba7
remove data allignment
ZoeLeibowitz Dec 4, 2023
09dbaec
new petsc types
ZoeLeibowitz Dec 4, 2023
b2202c5
add const func in petscfunction
ZoeLeibowitz Dec 7, 2023
2063c1d
dsl: Simplify PETScFunction class and add diff dtypes inside test_pet…
ZoeLeibowitz Dec 19, 2023
a5dbdc7
dsl: Inherit from DiscreteFunction for PETScFunction instead?'
ZoeLeibowitz Dec 19, 2023
3592bf7
compiler: Switch PETScFunction to inherit from Array
ZoeLeibowitz Dec 20, 2023
8b80d5b
compiler: Edit PETScFunction to inherit from ArrayBasic
ZoeLeibowitz Dec 20, 2023
d557f96
misc: Fix pytest for test_petsc.py
ZoeLeibowitz Dec 20, 2023
ffc0503
compiler: Edit _C_ctype property of PETScFunction to utilise CustomDtype
ZoeLeibowitz Dec 20, 2023
5e292ad
compiler: Edit _C_ctype property of PETScFunction
ZoeLeibowitz Dec 20, 2023
71d109c
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
17e8570
compiler: Change name to PETScArray from PETScFunction
ZoeLeibowitz Jan 2, 2024
e5df434
compiler: Add intermediate class between PETScArray and ArrayBasic
ZoeLeibowitz Jan 4, 2024
c56405f
compiler: Remove PETSc specific checks in place_definitions
ZoeLeibowitz Jan 4, 2024
ee12a33
compiler: Remove PETSc specific check from place_definitions and edit…
ZoeLeibowitz Jan 4, 2024
651885a
compiler: Remove is_PETScArray
ZoeLeibowitz Jan 4, 2024
43bbdca
compiler: Remove elif is_ObjectArray and use alloc_object_.. inside t…
ZoeLeibowitz Jan 4, 2024
4dcc4b9
misc: Delete empty file
ZoeLeibowitz Jan 8, 2024
f1b31a2
misc: Move dtype_to_petsctype to petsc.py and clean up blank lines
ZoeLeibowitz Jan 8, 2024
9aec979
misc: Clean up blank line
ZoeLeibowitz Jan 8, 2024
866ac5f
Update nodes.py
ZoeLeibowitz Feb 23, 2024
16028ad
Update nodes.py
ZoeLeibowitz Feb 23, 2024
34ea750
compiler: Add FuncPtrCall
ZoeLeibowitz Dec 13, 2023
dd2a906
compiler: Edit names, move position of Callback and other small edits
ZoeLeibowitz Dec 19, 2023
54c21de
types: Update PETScArray to have liveness
ZoeLeibowitz Feb 28, 2024
978cd38
compiler: Switch get to pop in PETScArray
ZoeLeibowitz Mar 1, 2024
77a0d0b
types: Move liveness to ArrayBasic from PETScArray
ZoeLeibowitz Mar 11, 2024
fe08af8
misc: clean
ZoeLeibowitz Mar 11, 2024
4cae443
types: Make PETScArrays differentiable
ZoeLeibowitz Mar 11, 2024
aa0a27e
types: Introduce PETScFunction class to enable differentiablity and t…
ZoeLeibowitz Mar 12, 2024
850d5c0
types: Update PETScArray
ZoeLeibowitz Mar 14, 2024
d74b316
types: Edit init file for petsc types
ZoeLeibowitz Mar 14, 2024
504ee2e
revert file messed up rebase
ZoeLeibowitz Mar 15, 2024
4203481
types: Add coefficients arg to PETScArray
ZoeLeibowitz Mar 15, 2024
61c0404
types: Add basic PETScEq
ZoeLeibowitz Mar 15, 2024
cd95a1e
types: Add PETScSolve and simple iet pass
ZoeLeibowitz Mar 18, 2024
73f714f
tests: Add test for PETScSolve
ZoeLeibowitz Mar 18, 2024
0275205
misc: Clean
ZoeLeibowitz Mar 18, 2024
b341fea
misc: Clean up
ZoeLeibowitz Mar 18, 2024
4c0fb93
misc: Add a comment in types/petsc.py
ZoeLeibowitz Mar 18, 2024
2b8309c
types: Update PETScEq default solver params
ZoeLeibowitz Mar 18, 2024
ca6a96a
types: Remove hasattr from LoweredEq, create common node class for pe…
ZoeLeibowitz Mar 27, 2024
de8c6c4
compiler: Edit iteration bound check in cluster.py i.e change PETScAr…
ZoeLeibowitz Mar 27, 2024
37bb900
compiler: Remove deep nesting in cluster.py isinstance check for Arra…
ZoeLeibowitz Mar 28, 2024
fc37305
compiler: Replace additions in LoweredEq with PETScRHS class which is…
ZoeLeibowitz Mar 28, 2024
b8efafd
misc: Clean
ZoeLeibowitz Mar 28, 2024
4268b47
compiler: Remove target and solver params from LinearSolverExpression
ZoeLeibowitz Mar 28, 2024
c13181d
compiler: Reduce elif statements inside iet/algorithms by using a PET…
ZoeLeibowitz Mar 28, 2024
d875a9d
types: Change name from PETScRHS to LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
206f84e
types: Edit LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
ad70691
compiler: Small edit in LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
d3f52db
compiler: Small edit to hash in LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
ea36ecf
compiler: Remove function from iet/algorithms and replace with just t…
ZoeLeibowitz Mar 28, 2024
2035333
compiler: Remove unecessary __init__ from LinearSolverExpression
ZoeLeibowitz Apr 2, 2024
6370848
compiler: Remove printer for LinearSolveExpr
ZoeLeibowitz Apr 2, 2024
6734a2d
misc: Clean up
ZoeLeibowitz Apr 2, 2024
acf2327
compiler: Edit PETScArrays to support devito multi-dim indexing
ZoeLeibowitz Apr 17, 2024
a1fa4dd
misc: clean
ZoeLeibowitz Apr 17, 2024
b10beaf
tests: Add test for no automatic cast generation with PETScArrays
ZoeLeibowitz Apr 19, 2024
07f8e99
misc: Docstring edit in test petsc
ZoeLeibowitz Apr 19, 2024
b700c43
compiler: Add PETScIndexedData
ZoeLeibowitz Apr 19, 2024
ddc36c4
misc: Clean
ZoeLeibowitz Apr 19, 2024
4a7e436
compiler: Add indexedbases back and simplify PETScArray symbolic shape
ZoeLeibowitz Apr 19, 2024
db50cc5
types: Reverse dmda and therefore casting to match Devito
ZoeLeibowitz Apr 25, 2024
2a4886a
misc: Doc
ZoeLeibowitz Apr 26, 2024
9cc79df
misc: Add line back
ZoeLeibowitz May 1, 2024
bc082ae
compiler: Add Mock/placeholder expressions to create distinct iterati…
ZoeLeibowitz Apr 3, 2024
13e1f29
misc: Clean up
ZoeLeibowitz Apr 3, 2024
019d1c6
bench: Remove null profiled sections in Kernel for openmp
ZoeLeibowitz Apr 3, 2024
cbea467
compiler: Remove init=False from LinSolveMock
ZoeLeibowitz Apr 3, 2024
d9c6fcd
compiler: Simplify by just having a Mock RHS which drops correspondin…
ZoeLeibowitz Apr 3, 2024
0d1325c
misc: Clean up
ZoeLeibowitz Apr 3, 2024
b22cd37
misc: Clean
ZoeLeibowitz Apr 3, 2024
5a869b5
misc: Comments
ZoeLeibowitz Apr 3, 2024
cf8e9c1
misc: Typo
ZoeLeibowitz Apr 3, 2024
20416b7
compiler: Lift iteration space instead of using new Mock object
ZoeLeibowitz May 2, 2024
59f38b7
misc: Clean
ZoeLeibowitz May 2, 2024
0465168
misc: Clean
ZoeLeibowitz May 2, 2024
c6230dd
misc: Clean
ZoeLeibowitz May 2, 2024
536e139
compiler: Move petsc lift to petsc only file
ZoeLeibowitz May 2, 2024
3a5f0a2
types: Simplify petsc_lift
ZoeLeibowitz May 2, 2024
4824e40
types: Add else to petsc_lift
ZoeLeibowitz May 2, 2024
c49033d
misc: Move petsc_lift to passes/clusters file
ZoeLeibowitz May 2, 2024
1f245e7
compiler: Move petsc_lift to after clusterize inside lower_clusters
ZoeLeibowitz May 2, 2024
73d1083
misc: Fix functools
ZoeLeibowitz Jul 9, 2024
e2d7321
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
f4d9c6a
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
eb58f3c
dsl: Dispatch to sympy.Add not both Add and EvalDerivative
ZoeLeibowitz Jul 10, 2024
f229935
compiler: Create mixin for ThreadCallable and PETScCallable
ZoeLeibowitz Jul 23, 2024
0f9bb9b
compiler: Don't ever generate time loop for petsc callbacks
ZoeLeibowitz Oct 2, 2024
f5b0746
compiler: Move passes from utils into passes and create petsc_preprocess
ZoeLeibowitz Oct 4, 2024
07a27bf
misc: Remove workflow triggers
ZoeLeibowitz Oct 4, 2024
7ad60cc
rebase leftover
ZoeLeibowitz Oct 14, 2024
469e464
Merge branch 'devitocodes:master' into master
ZoeLeibowitz Oct 16, 2024
95bda78
dsl: Edit PETScSolve to support modified stencils
ZoeLeibowitz Oct 16, 2024
44d1ae3
dsl: Map time indices after forming eqn sets
ZoeLeibowitz Oct 17, 2024
97c0d52
dsl: Simplify index extraction
ZoeLeibowitz Oct 20, 2024
2ecf48a
Merge branch 'devitocodes:master' into master
ZoeLeibowitz Oct 25, 2024
49b41ee
Merge branch 'devitocodes:master' into master
ZoeLeibowitz Nov 11, 2024
1b239da
Merge pull request #31 from ZoeLeibowitz/modifed_stencil
ZoeLeibowitz Nov 12, 2024
6e9f6da
snes ex19 matfree jac
ZoeLeibowitz Dec 13, 2024
370d647
examples: Use vecgetsubvector
ZoeLeibowitz Dec 16, 2024
185d5ba
update matfree
ZoeLeibowitz Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/pytest-petsc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI-petsc

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
push:
branches:
- master
pull_request:
branches:
- master

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

env:
DOCKER_BUILDKIT: "1"
DEVITO_ARCH: "${{ matrix.arch }}"
DEVITO_LANGUAGE: ${{ matrix.language }}

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

matrix:
name: [
pytest-docker-py39-gcc-noomp
]
include:
- name: pytest-docker-py39-gcc-noomp
python-version: '3.9'
os: ubuntu-latest
arch: "gcc"
language: "C"
sympy: "1.12"

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

- name: Build docker image
run: |
docker build . --file docker/Dockerfile.devito --tag devito_img --build-arg base=zoeleibowitz/bases:cpu-${{ matrix.arch }} --build-arg petscinstall=petsc

- name: Set run prefix
run: |
echo "RUN_CMD=docker run --rm -t -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} --name testrun devito_img" >> $GITHUB_ENV
id: set-run

- name: Set tests
run : |
echo "TESTS=tests/test_petsc.py" >> $GITHUB_ENV
id: set-tests

- name: Check configuration
run: |
${{ env.RUN_CMD }} python3 -c "from devito import configuration; print(''.join(['%s: %s \n' % (k, v) for (k, v) in configuration.items()]))"

- name: Test with pytest
run: |
${{ env.RUN_CMD }} pytest --cov --cov-config=.coveragerc --cov-report=xml ${{ env.TESTS }}

- name: Upload coverage to Codecov
if: "!contains(matrix.name, 'docker')"
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: ${{ matrix.name }}
16 changes: 15 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from devito.ir.iet import (FindNodes, FindSymbols, Iteration, ParallelBlock,
retrieve_iteration_tree)
from devito.tools import as_tuple
from devito.petsc.utils import get_petsc_dir, get_petsc_arch

try:
from mpi4py import MPI # noqa
Expand All @@ -33,7 +34,7 @@ def skipif(items, whole_module=False):
accepted = set()
accepted.update({'device', 'device-C', 'device-openmp', 'device-openacc',
'device-aomp', 'cpu64-icc', 'cpu64-icx', 'cpu64-nvc', 'cpu64-arm',
'cpu64-icpx', 'chkpnt'})
'cpu64-icpx', 'chkpnt', 'petsc'})
accepted.update({'nodevice'})
unknown = sorted(set(items) - accepted)
if unknown:
Expand Down Expand Up @@ -87,6 +88,19 @@ def skipif(items, whole_module=False):
if i == 'chkpnt' and Revolver is NoopRevolver:
skipit = "pyrevolve not installed"
break
if i == 'petsc':
petsc_dir = get_petsc_dir()
petsc_arch = get_petsc_arch()
if petsc_dir is None or petsc_arch is None:
skipit = "PETSC_DIR or PETSC_ARCH are not set"
break
else:
petsc_installed = os.path.join(
petsc_dir, petsc_arch, 'include', 'petscconf.h'
)
if not os.path.isfile(petsc_installed):
skipit = "PETSc is not installed"
break

if skipit is False:
return pytest.mark.skipif(False, reason='')
Expand Down
10 changes: 7 additions & 3 deletions devito/ir/equations/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
Stencil, detect_io, detect_accesses)
from devito.symbolics import IntDiv, limits_mapper, uxreplace
from devito.tools import Pickable, Tag, frozendict
from devito.types import Eq, Inc, ReduceMax, ReduceMin, relational_min
from devito.types import (Eq, Inc, ReduceMax, ReduceMin,
relational_min)
from devito.types.equation import InjectSolveEq

__all__ = ['LoweredEq', 'ClusterizedEq', 'DummyEq', 'OpInc', 'OpMin', 'OpMax',
'identity_mapper']
'identity_mapper', 'OpInjectSolve']


class IREq(sympy.Eq, Pickable):
Expand Down Expand Up @@ -102,7 +104,8 @@ def detect(cls, expr):
reduction_mapper = {
Inc: OpInc,
ReduceMax: OpMax,
ReduceMin: OpMin
ReduceMin: OpMin,
InjectSolveEq: OpInjectSolve
}
try:
return reduction_mapper[type(expr)]
Expand All @@ -119,6 +122,7 @@ def detect(cls, expr):
OpInc = Operation('+')
OpMax = Operation('max')
OpMin = Operation('min')
OpInjectSolve = Operation('solve')


identity_mapper = {
Expand Down
4 changes: 4 additions & 0 deletions devito/ir/iet/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from devito.ir.iet import (Expression, Increment, Iteration, List, Conditional, SyncSpot,
Section, HaloSpot, ExpressionBundle)
from devito.tools import timed_pass
from devito.petsc.types import LinearSolveExpr
from devito.petsc.iet.utils import petsc_iet_mapper

__all__ = ['iet_build']

Expand All @@ -24,6 +26,8 @@ def iet_build(stree):
for e in i.exprs:
if e.is_Increment:
exprs.append(Increment(e))
elif isinstance(e.rhs, LinearSolveExpr):
exprs.append(petsc_iet_mapper[e.operation](e, operation=e.operation))
else:
exprs.append(Expression(e, operation=e.operation))
body = ExpressionBundle(i.ispace, i.ops, i.traffic, body=exprs)
Expand Down
4 changes: 2 additions & 2 deletions devito/ir/iet/efunc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import cached_property

from devito.ir.iet.nodes import Call, Callable
from devito.ir.iet.nodes import Call, Callable, FixedArgsCallable
from devito.ir.iet.utils import derive_parameters
from devito.symbolics import uxreplace
from devito.tools import as_tuple
Expand Down Expand Up @@ -131,7 +131,7 @@ class AsyncCall(Call):
pass


class ThreadCallable(Callable):
class ThreadCallable(FixedArgsCallable):

"""
A Callable executed asynchronously by a thread.
Expand Down
62 changes: 56 additions & 6 deletions devito/ir/iet/nodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The Iteration/Expression Tree (IET) hierarchy."""

import abc
import ctypes
import inspect
from functools import cached_property
from collections import OrderedDict, namedtuple
Expand Down Expand Up @@ -28,7 +29,7 @@
'Increment', 'Return', 'While', 'ListMajor', 'ParallelIteration',
'ParallelBlock', 'Dereference', 'Lambda', 'SyncSpot', 'Pragma',
'DummyExpr', 'BlankLine', 'ParallelTree', 'BusyWait', 'UsingNamespace',
'CallableBody', 'Transfer']
'CallableBody', 'Transfer', 'Callback', 'FixedArgsCallable']

# First-class IET nodes

Expand Down Expand Up @@ -750,6 +751,15 @@ def defines(self):
return self.all_parameters


class FixedArgsCallable(Callable):

"""
A Callable class that enforces a fixed function signature.
"""

pass


class CallableBody(MultiTraversable):

"""
Expand Down Expand Up @@ -1028,8 +1038,8 @@ class Dereference(ExprStmt, Node):
The following cases are supported:

* `pointer` is a PointerArray or TempFunction, and `pointee` is an Array.
* `pointer` is an ArrayObject representing a pointer to a C struct, and
`pointee` is a field in `pointer`.
* `pointer` is an ArrayObject or CCompositeObject representing a pointer
to a C struct, and `pointee` is a field in `pointer`.
"""

is_Dereference = True
Expand All @@ -1048,13 +1058,14 @@ def functions(self):

@property
def expr_symbols(self):
ret = [self.pointer.indexed]
ret = []
if self.pointer.is_PointerArray or self.pointer.is_TempFunction:
ret.append(self.pointee.indexed)
ret.extend([self.pointer.indexed, self.pointee.indexed])
ret.extend(flatten(i.free_symbols for i in self.pointee.symbolic_shape[1:]))
ret.extend(self.pointer.free_symbols)
else:
ret.append(self.pointee._C_symbol)
assert issubclass(self.pointer._C_ctype, ctypes._Pointer)
ret.extend([self.pointer._C_symbol, self.pointee._C_symbol])
return tuple(filter_ordered(ret))

@property
Expand Down Expand Up @@ -1120,6 +1131,45 @@ def defines(self):
return tuple(self.parameters)


class Callback(Call):
"""
Base class for special callback types.

Parameters
----------
name : str
The name of the callback.
retval : str
The return type of the callback.
param_types : str or list of str
The return type for each argument of the callback.

Notes
-----
- The reason Callback is an IET type rather than a SymPy type is
due to the fact that, when represented at the SymPy level, the IET
engine fails to bind the callback to a specific Call. Consequently,
errors occur during the creation of the call graph.
"""
# TODO: Create a common base class for Call and Callback to avoid
# having arguments=None here
def __init__(self, name, retval=None, param_types=None, arguments=None):
super().__init__(name=name)
self.retval = retval
self.param_types = as_tuple(param_types)

@property
def callback_form(self):
"""
A string representation of the callback form.

Notes
-----
To be overridden by subclasses.
"""
return


class Section(List):

"""
Expand Down
14 changes: 13 additions & 1 deletion devito/ir/iet/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def _gen_value(self, obj, mode=1, masked=()):
strtype = '%s%s' % (strtype, self._restrict_keyword)
strtype = ' '.join(qualifiers + [strtype])

if obj.is_LocalObject and obj._C_modifier is not None and mode == 2:
if obj.is_LocalType and obj._C_modifier is not None and mode == 2:
strtype += obj._C_modifier

strname = obj._C_name
Expand Down Expand Up @@ -613,6 +613,9 @@ def visit_Lambda(self, o):
(', '.join(captures), ', '.join(decls), ''.join(extra)))
return LambdaCollection([top, c.Block(body)])

def visit_Callback(self, o, nested_call=False):
return CallbackArg(o)

def visit_HaloSpot(self, o):
body = flatten(self._visit(i) for i in o.children)
return c.Collection(body)
Expand Down Expand Up @@ -1416,3 +1419,12 @@ def sorted_efuncs(efuncs):
CommCallable: 1
}
return sorted_priority(efuncs, priority)


class CallbackArg(c.Generable):

def __init__(self, callback):
self.callback = callback

def generate(self):
yield self.callback.callback_form
10 changes: 9 additions & 1 deletion devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
split, timed_pass, timed_region, contains_val)
from devito.types import (Buffer, Grid, Evaluable, host_layer, device_layer,
disk_layer)
from devito.petsc.iet.passes import lower_petsc
from devito.petsc.clusters import petsc_preprocess

__all__ = ['Operator']

Expand Down Expand Up @@ -374,6 +376,9 @@ def _lower_clusters(cls, expressions, profiler=None, **kwargs):
# Build a sequence of Clusters from a sequence of Eqs
clusters = clusterize(expressions, **kwargs)

# Preprocess clusters for PETSc lowering
clusters = petsc_preprocess(clusters)

# Operation count before specialization
init_ops = sum(estimate_cost(c.exprs) for c in clusters if c.is_dense)

Expand Down Expand Up @@ -471,6 +476,9 @@ def _lower_iet(cls, uiet, profiler=None, **kwargs):

# Lower IET to a target-specific IET
graph = Graph(iet, **kwargs)

lower_petsc(graph, **kwargs)

graph = cls._specialize_iet(graph, **kwargs)

# Instrument the IET for C-level profiling
Expand Down Expand Up @@ -502,7 +510,7 @@ def dimensions(self):

# During compilation other Dimensions may have been produced
dimensions = FindSymbols('dimensions').visit(self)
ret.update(d for d in dimensions if d.is_PerfKnob)
ret.update(dimensions)

ret = tuple(sorted(ret, key=attrgetter('name')))

Expand Down
Loading
Loading