Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
a9801e7
compiler: Add FuncPtrCall
ZoeLeibowitz Dec 13, 2023
3f73add
misc: Update docstring
ZoeLeibowitz Dec 13, 2023
ccd10b9
compiler: Edit names, move position of Callback and other small edits
ZoeLeibowitz Dec 19, 2023
f34ae6d
misc: Update docstring for Callback
ZoeLeibowitz Jan 5, 2024
ae28dac
misc: Clean up blank lines
ZoeLeibowitz Jan 6, 2024
20fd2d1
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
2a6b923
try petscfunc from abstractfunc
ZoeLeibowitz Nov 27, 2023
2c0d33e
latest.
ZoeLeibowitz Nov 30, 2023
12ab5bd
remove data allignment
ZoeLeibowitz Dec 4, 2023
2e940ad
new petsc types
ZoeLeibowitz Dec 4, 2023
0815c70
add const func in petscfunction
ZoeLeibowitz Dec 7, 2023
cc38a90
dsl: Simplify PETScFunction class and add diff dtypes inside test_pet…
ZoeLeibowitz Dec 19, 2023
1dc5695
dsl: Inherit from DiscreteFunction for PETScFunction instead?'
ZoeLeibowitz Dec 19, 2023
6152445
compiler: Switch PETScFunction to inherit from Array
ZoeLeibowitz Dec 20, 2023
cbedc60
compiler: Edit PETScFunction to inherit from ArrayBasic
ZoeLeibowitz Dec 20, 2023
469e308
misc: Fix pytest for test_petsc.py
ZoeLeibowitz Dec 20, 2023
9129223
compiler: Edit _C_ctype property of PETScFunction to utilise CustomDtype
ZoeLeibowitz Dec 20, 2023
acff687
compiler: Edit _C_ctype property of PETScFunction
ZoeLeibowitz Dec 20, 2023
3362ad8
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
5b15b4e
compiler: Change name to PETScArray from PETScFunction
ZoeLeibowitz Jan 2, 2024
7f3920a
compiler: Add intermediate class between PETScArray and ArrayBasic
ZoeLeibowitz Jan 4, 2024
15e7400
compiler: Remove PETSc specific checks in place_definitions
ZoeLeibowitz Jan 4, 2024
ea9be50
compiler: Remove PETSc specific check from place_definitions and edit…
ZoeLeibowitz Jan 4, 2024
905a7e2
compiler: Remove is_PETScArray
ZoeLeibowitz Jan 4, 2024
415ad20
compiler: Remove elif is_ObjectArray and use alloc_object_.. inside t…
ZoeLeibowitz Jan 4, 2024
adc5428
misc: Delete empty file
ZoeLeibowitz Jan 8, 2024
0a571c7
misc: Move dtype_to_petsctype to petsc.py and clean up blank lines
ZoeLeibowitz Jan 8, 2024
ce3cfb3
misc: Clean up blank line
ZoeLeibowitz Jan 8, 2024
245242a
Update nodes.py
ZoeLeibowitz Feb 23, 2024
b45b17c
Update nodes.py
ZoeLeibowitz Feb 23, 2024
40699ae
compiler: Add FuncPtrCall
ZoeLeibowitz Dec 13, 2023
0ad3625
compiler: Edit names, move position of Callback and other small edits
ZoeLeibowitz Dec 19, 2023
136921a
types: Update PETScArray to have liveness
ZoeLeibowitz Feb 28, 2024
c9e9836
compiler: Switch get to pop in PETScArray
ZoeLeibowitz Mar 1, 2024
31c8a27
types: Move liveness to ArrayBasic from PETScArray
ZoeLeibowitz Mar 11, 2024
3d5278e
misc: clean
ZoeLeibowitz Mar 11, 2024
ae01826
types: Make PETScArrays differentiable
ZoeLeibowitz Mar 11, 2024
222d804
types: Introduce PETScFunction class to enable differentiablity and t…
ZoeLeibowitz Mar 12, 2024
bbf64d2
types: Update PETScArray
ZoeLeibowitz Mar 14, 2024
9ce5462
types: Edit init file for petsc types
ZoeLeibowitz Mar 14, 2024
5e70798
revert file messed up rebase
ZoeLeibowitz Mar 15, 2024
649b282
types: Add coefficients arg to PETScArray
ZoeLeibowitz Mar 15, 2024
2b17216
types: Add basic PETScEq
ZoeLeibowitz Mar 15, 2024
2c01d4f
types: Add PETScSolve and simple iet pass
ZoeLeibowitz Mar 18, 2024
a49dfa5
tests: Add test for PETScSolve
ZoeLeibowitz Mar 18, 2024
4d9f98e
misc: Clean
ZoeLeibowitz Mar 18, 2024
944adb0
misc: Clean up
ZoeLeibowitz Mar 18, 2024
5924933
misc: Add a comment in types/petsc.py
ZoeLeibowitz Mar 18, 2024
01f099f
types: Update PETScEq default solver params
ZoeLeibowitz Mar 18, 2024
80e9b69
types: Remove hasattr from LoweredEq, create common node class for pe…
ZoeLeibowitz Mar 27, 2024
807e93c
compiler: Edit iteration bound check in cluster.py i.e change PETScAr…
ZoeLeibowitz Mar 27, 2024
8f8c3c0
compiler: Remove deep nesting in cluster.py isinstance check for Arra…
ZoeLeibowitz Mar 28, 2024
efc2289
compiler: Replace additions in LoweredEq with PETScRHS class which is…
ZoeLeibowitz Mar 28, 2024
7ecaf4a
misc: Clean
ZoeLeibowitz Mar 28, 2024
d99d672
compiler: Remove target and solver params from LinearSolverExpression
ZoeLeibowitz Mar 28, 2024
f62a12b
compiler: Reduce elif statements inside iet/algorithms by using a PET…
ZoeLeibowitz Mar 28, 2024
fb6c936
types: Change name from PETScRHS to LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
d232332
types: Edit LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
9fd5a8b
compiler: Small edit in LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
527269e
compiler: Small edit to hash in LinearSolveExpr
ZoeLeibowitz Mar 28, 2024
ce3ebba
compiler: Remove function from iet/algorithms and replace with just t…
ZoeLeibowitz Mar 28, 2024
d8a57bb
compiler: Remove unecessary __init__ from LinearSolverExpression
ZoeLeibowitz Apr 2, 2024
f2d05a1
compiler: Remove printer for LinearSolveExpr
ZoeLeibowitz Apr 2, 2024
0cbae6f
misc: Clean up
ZoeLeibowitz Apr 2, 2024
eafda55
compiler: Edit PETScArrays to support devito multi-dim indexing
ZoeLeibowitz Apr 17, 2024
bcb892f
misc: clean
ZoeLeibowitz Apr 17, 2024
1333432
tests: Add test for no automatic cast generation with PETScArrays
ZoeLeibowitz Apr 19, 2024
754eb0f
misc: Docstring edit in test petsc
ZoeLeibowitz Apr 19, 2024
4057c2c
compiler: Add PETScIndexedData
ZoeLeibowitz Apr 19, 2024
eb51bd0
misc: Clean
ZoeLeibowitz Apr 19, 2024
bdaba5e
compiler: Add indexedbases back and simplify PETScArray symbolic shape
ZoeLeibowitz Apr 19, 2024
a488156
types: Reverse dmda and therefore casting to match Devito
ZoeLeibowitz Apr 25, 2024
5914852
misc: Doc
ZoeLeibowitz Apr 26, 2024
41c7ff4
misc: Add line back
ZoeLeibowitz May 1, 2024
3e0288d
compiler: Add Mock/placeholder expressions to create distinct iterati…
ZoeLeibowitz Apr 3, 2024
17193ea
misc: Clean up
ZoeLeibowitz Apr 3, 2024
d55a2d0
bench: Remove null profiled sections in Kernel for openmp
ZoeLeibowitz Apr 3, 2024
76d05c7
compiler: Remove init=False from LinSolveMock
ZoeLeibowitz Apr 3, 2024
5555b67
compiler: Simplify by just having a Mock RHS which drops correspondin…
ZoeLeibowitz Apr 3, 2024
c4ec0b7
misc: Clean up
ZoeLeibowitz Apr 3, 2024
ff4cf07
misc: Clean
ZoeLeibowitz Apr 3, 2024
309a3f9
misc: Comments
ZoeLeibowitz Apr 3, 2024
452a213
misc: Typo
ZoeLeibowitz Apr 3, 2024
21d6af2
compiler: Lift iteration space instead of using new Mock object
ZoeLeibowitz May 2, 2024
5b4a79c
misc: Clean
ZoeLeibowitz May 2, 2024
a1dc4a4
misc: Clean
ZoeLeibowitz May 2, 2024
3e57412
misc: Clean
ZoeLeibowitz May 2, 2024
c561573
compiler: Move petsc lift to petsc only file
ZoeLeibowitz May 2, 2024
2721817
types: Simplify petsc_lift
ZoeLeibowitz May 2, 2024
06a9c4c
types: Add else to petsc_lift
ZoeLeibowitz May 2, 2024
1195470
misc: Move petsc_lift to passes/clusters file
ZoeLeibowitz May 2, 2024
1c20833
compiler: Move petsc_lift to after clusterize inside lower_clusters
ZoeLeibowitz May 2, 2024
fdd3d67
misc: Fix functools
ZoeLeibowitz Jul 9, 2024
1cce1af
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
7ad9bc9
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
dd75395
dsl: Dispatch to sympy.Add not both Add and EvalDerivative
ZoeLeibowitz Jul 10, 2024
1fe94ea
compiler: Create mixin for ThreadCallable and PETScCallable
ZoeLeibowitz Jul 23, 2024
feba0a9
compiler: Don't ever generate time loop for petsc callbacks
ZoeLeibowitz Oct 2, 2024
10602d0
compiler: Move passes from utils into passes and create petsc_preprocess
ZoeLeibowitz Oct 4, 2024
ad1fb03
misc: Remove workflow triggers
ZoeLeibowitz Oct 4, 2024
107d86d
rebase leftover
ZoeLeibowitz Oct 14, 2024
f3e1701
dsl: Edit PETScSolve to support modified stencils
ZoeLeibowitz Oct 16, 2024
e825ab8
dsl: Map time indices after forming eqn sets
ZoeLeibowitz Oct 17, 2024
ccb1901
dsl: Simplify index extraction
ZoeLeibowitz Oct 20, 2024
f0483f4
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
57b99e6
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
ca20534
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
15ed63e
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
bd4fc4b
dsl: Dispatch to sympy.Add not both Add and EvalDerivative
ZoeLeibowitz Jul 10, 2024
09f6fdf
compiler: Create mixin for ThreadCallable and PETScCallable
ZoeLeibowitz Jul 23, 2024
09d9180
types: Edit freesymbols in FieldFromPointer
ZoeLeibowitz Jan 3, 2025
8472b77
clean
ZoeLeibowitz Jan 8, 2025
579045f
trigger wfs for branches off this branch
ZoeLeibowitz Jan 8, 2025
79cf51a
rebase leftover
ZoeLeibowitz Feb 18, 2025
4272da2
rebase fix and remove concretize mapper
ZoeLeibowitz Feb 18, 2025
526449e
rebase leftover
ZoeLeibowitz Feb 18, 2025
4689508
flake8
ZoeLeibowitz Feb 18, 2025
434e424
flake8
ZoeLeibowitz Feb 18, 2025
cfa7218
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
fd8c53f
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
d09e654
misc: Split Dockerfile.cpu into .cpu and .intel
FabioLuporini Dec 19, 2023
62a4e1c
misc: Update file due to incorrect rebase
ZoeLeibowitz Dec 22, 2023
0f862ba
dsl: Dispatch to sympy.Add not both Add and EvalDerivative
ZoeLeibowitz Jul 10, 2024
b8de614
compiler: Create mixin for ThreadCallable and PETScCallable
ZoeLeibowitz Jul 23, 2024
82b434b
types: Edit freesymbols in FieldFromPointer
ZoeLeibowitz Jan 3, 2025
8cb18d3
compiler: Use classes
ZoeLeibowitz Jan 9, 2025
da2bbf3
compiler: Switch to using a separate struct and dm for each SNES solve
ZoeLeibowitz Jan 9, 2025
c445140
compiler: Rework petscarrays
ZoeLeibowitz Jan 9, 2025
670e1d2
misc: Clean up
ZoeLeibowitz Jan 9, 2025
ad5fb49
compiler: Timedep abstraction
ZoeLeibowitz Jan 10, 2025
89cc06e
More cleanup, add callbackdm etc
ZoeLeibowitz Jan 12, 2025
2c4a568
Address some comments
ZoeLeibowitz Jan 12, 2025
b83ec92
compiler: Move uxreplace_efuncs into Builder
ZoeLeibowitz Jan 23, 2025
4d75af8
misc: Clean up
ZoeLeibowitz Jan 23, 2025
5f25b0f
misc: Add timeloop abstraction docs
ZoeLeibowitz Jan 25, 2025
37b62b3
misc: Clean up and docs
ZoeLeibowitz Jan 26, 2025
10af16f
misc: Spellings
ZoeLeibowitz Jan 28, 2025
ef7ee34
flake8
ZoeLeibowitz Feb 18, 2025
3b80b8b
Merge pull request #38 from ZoeLeibowitz/cleanup2
ZoeLeibowitz Feb 18, 2025
b989d06
Clean up
ZoeLeibowitz Feb 18, 2025
be99236
Merge pull request #36 from ZoeLeibowitz/FieldFromPointer
ZoeLeibowitz Feb 19, 2025
15f78ea
compiler: Initialize and Finalize PETSc once and command line args
ZoeLeibowitz Mar 10, 2025
cdc75f0
Merge pull request #43 from ZoeLeibowitz/init_finalize
ZoeLeibowitz Mar 18, 2025
c68dd4f
Coupled (#41)
ZoeLeibowitz Mar 19, 2025
ccb68db
edit petsc utils
ZoeLeibowitz Mar 19, 2025
70e0b0f
compiler: petsc memory allocator
ZoeLeibowitz Mar 19, 2025
cddee0d
edit utils
ZoeLeibowitz Mar 19, 2025
8a273f4
update utils
ZoeLeibowitz Mar 19, 2025
c29ac83
petsc malloc
ZoeLeibowitz Mar 19, 2025
0841755
fix mem issue
ZoeLeibowitz Mar 19, 2025
cdee484
edit memory allocator
ZoeLeibowitz Mar 20, 2025
b512417
fix
ZoeLeibowitz Mar 20, 2025
8046b75
ferfrwe
ZoeLeibowitz Mar 20, 2025
a927ca6
circular import
ZoeLeibowitz Mar 20, 2025
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 }} mpiexec -n 1 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 }}
15 changes: 14 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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 +87,19 @@ def skipif(items, whole_module=False):
if i == 'chkpnt' and Revolver is NoopRevolver:
skipit = "pyrevolve not installed"
break
if i == 'petsc':
petsc_dir = os.environ.get('PETSC_DIR')
petsc_arch = os.environ.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
33 changes: 32 additions & 1 deletion devito/data/allocators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
import mmap
import os
import sys
from pathlib import Path

import numpy as np

from devito.logger import logger
from devito.parameters import configuration
from devito.tools import dtype_to_ctype, is_integer


__all__ = ['ALLOC_ALIGNED', 'ALLOC_NUMA_LOCAL', 'ALLOC_NUMA_ANY',
'ALLOC_KNL_MCDRAM', 'ALLOC_KNL_DRAM', 'ALLOC_GUARD',
'default_allocator']
'ALLOC_PETSC', 'default_allocator']


class AbstractMemoryAllocator:
Expand Down Expand Up @@ -337,6 +339,34 @@ def put_local(self):
return self._node == 'local'


class PetscMemoryAllocator(MemoryAllocator):
"""
"""
@classmethod
def initialize(cls):
# from IPython import embed; embed()
from devito.petsc.utils import core_metadata
metadata = core_metadata()
lib_dir = Path(metadata['lib_dirs'][-1])

try:
cls.lib = ctypes.CDLL(lib_dir/'libpetsc.so')
except OSError:
cls.lib = None

def _alloc_C_libcall(self, size, ctype):
c_pointer = ctypes.cast(ctypes.c_void_p(), ctypes.c_void_p)
ret = self.lib.PetscMalloc(size, ctypes.byref(c_pointer))

if ret == 0:
return c_pointer, (c_pointer, )
else:
return None, None

def free(self, c_pointer):
self.lib.PetscFree(c_pointer)


class DataReference(MemoryAllocator):

"""
Expand Down Expand Up @@ -396,6 +426,7 @@ def alloc(self, shape, dtype, padding=0):
ALLOC_KNL_MCDRAM = NumaAllocator(1)
ALLOC_NUMA_ANY = NumaAllocator('any')
ALLOC_NUMA_LOCAL = NumaAllocator('local')
ALLOC_PETSC = PetscMemoryAllocator()

custom_allocators = {
'fallback': ALLOC_ALIGNED,
Expand Down
3 changes: 2 additions & 1 deletion devito/ir/equations/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def concretize_subdims(exprs, **kwargs):
"""
sregistry = kwargs.get('sregistry')

mapper = {}
# Update based on changes in #2509
mapper = kwargs.get('concretize_mapper', {})
rebuilt = {} # Rebuilt implicit dims etc which are shared between dimensions

_concretize_subdims(exprs, mapper, rebuilt, sregistry)
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 PetscEq

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


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,
PetscEq: OpPetsc
}
try:
return reduction_mapper[type(expr)]
Expand All @@ -119,6 +122,7 @@ def detect(cls, expr):
OpInc = Operation('+')
OpMax = Operation('max')
OpMin = Operation('min')
OpPetsc = 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 MetaData
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, MetaData):
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
65 changes: 58 additions & 7 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 All @@ -19,7 +20,7 @@
ctypes_to_cstr)
from devito.types.basic import (AbstractFunction, AbstractSymbol, Basic, Indexed,
Symbol)
from devito.types.object import AbstractObject, LocalObject
from devito.types.object import AbstractObject, LocalObject, LocalCompositeObject

__all__ = ['Node', 'MultiTraversable', 'Block', 'Expression', 'Callable',
'Call', 'ExprStmt', 'Conditional', 'Iteration', 'List', 'Section',
Expand All @@ -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 @@ -763,6 +764,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 @@ -1041,8 +1051,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 LocalCompositeObject representing a pointer
to a C struct, and `pointee` is a field in `pointer`.
"""

is_Dereference = True
Expand All @@ -1061,13 +1071,15 @@ 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 (isinstance(self.pointer, LocalCompositeObject) or
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 @@ -1133,6 +1145,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
Loading
Loading