Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start PetscObject #1

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
2b2719a
Test.
ZoeLeibowitz Jun 20, 2023
d93d7e2
add is_PetscObject
ZoeLeibowitz Jun 22, 2023
bda2f71
add petscobj to __all__
ZoeLeibowitz Jun 22, 2023
0815722
replace abstractproperty with property and abstractmethod
ZoeLeibowitz Jun 22, 2023
f778c7b
start PetscObject class
ZoeLeibowitz Jun 22, 2023
1760332
attempt is_const functionality in PetscObject instead of AbstractObje…
ZoeLeibowitz Jun 22, 2023
eceb342
latest petscobj with is_const func
ZoeLeibowitz Jun 22, 2023
e83e971
start petscobj test
ZoeLeibowitz Jun 23, 2023
b649d61
test petscobject latest
ZoeLeibowitz Jun 23, 2023
0de3f60
change names to simplify
ZoeLeibowitz Jun 23, 2023
76ad632
latest test
ZoeLeibowitz Jun 23, 2023
34e1d89
trigger workflow
ZoeLeibowitz Jun 23, 2023
f620f7a
start integrating shape into abstractobj using abstractfunc functions
ZoeLeibowitz Jun 26, 2023
280074f
add _C_Ctype func
ZoeLeibowitz Jun 26, 2023
43a1605
simplify, remove indexify stuff for now
ZoeLeibowitz Jun 27, 2023
23e3970
improved indices_setup but still probs bad way to do it
ZoeLeibowitz Jun 27, 2023
bbfec76
create abstractobjwithshape
ZoeLeibowitz Jun 27, 2023
fe97015
add abstractobjwithshape true/false
ZoeLeibowitz Jun 27, 2023
b28ba82
switch to using grid functionality inside petscobj
ZoeLeibowitz Jun 27, 2023
f83ace4
edit setup shape and setup indices
ZoeLeibowitz Jun 27, 2023
131bf24
change petscobj test
ZoeLeibowitz Jun 28, 2023
b0878c3
edit petsc test
ZoeLeibowitz Jun 28, 2023
7b5cd04
edit c_ctype func
ZoeLeibowitz Jun 28, 2023
1362449
flake8
ZoeLeibowitz Jun 28, 2023
d2c0149
remove is_ petscobj lines
ZoeLeibowitz Jun 30, 2023
781d210
add passes/iet/petsc file and move petscobj to it
ZoeLeibowitz Jun 30, 2023
fee5ca0
remove local/global
ZoeLeibowitz Jun 30, 2023
5607c1e
altered so that one can generate diff types not just PetscInts
ZoeLeibowitz Jun 30, 2023
005acd1
latest.
ZoeLeibowitz Jul 3, 2023
140ee60
latest.
ZoeLeibowitz Jul 3, 2023
f15a8e2
start to indexify petscobj
ZoeLeibowitz Jul 3, 2023
bb9f9ac
fix indexify
ZoeLeibowitz Jul 3, 2023
247b6ed
simplify indexify
ZoeLeibowitz Jul 3, 2023
d8f34fc
latest.
ZoeLeibowitz Jul 3, 2023
987b0d8
change so that indexify works exactly the same as Function
ZoeLeibowitz Jul 4, 2023
a517f74
add properties back into AbstractObjwithShape (even if commented) sin…
ZoeLeibowitz Jul 4, 2023
064234b
add hashable content func back and dtype to AbstractObjWithShape
ZoeLeibowitz Jul 4, 2023
9d867c8
add __rkwargs__ but need to check this
ZoeLeibowitz Jul 5, 2023
109c405
add hashable content to petscobject
ZoeLeibowitz Jul 5, 2023
b5a4b0e
change hashable content function and start test in test_caching.py
ZoeLeibowitz Jul 5, 2023
375eb05
add some more assertions in petsc test for diff attributes
ZoeLeibowitz Jul 5, 2023
f82e8dd
start petsc expression test
ZoeLeibowitz Jul 5, 2023
5aa2d22
add more expressions to petsc test expressions
ZoeLeibowitz Jul 6, 2023
9a6dc7a
add assertion in petsc test_caching
ZoeLeibowitz Jul 6, 2023
cf4252d
add test for petsc objects inside iteration loops
ZoeLeibowitz Jul 6, 2023
88d5eb6
test_petsc_build_dummy
ZoeLeibowitz Jul 10, 2023
af945f0
add functionptr class and a test for it
ZoeLeibowitz Aug 3, 2023
4927f08
latest
ZoeLeibowitz Aug 3, 2023
7c4de5d
change FunctionPointer class and add tests
ZoeLeibowitz Aug 8, 2023
203e1ee
latest functionpointer
ZoeLeibowitz Aug 8, 2023
f051528
add handler for FunctionPointer to symbolics/printer.py
ZoeLeibowitz Aug 9, 2023
76ae866
latest
ZoeLeibowitz Aug 9, 2023
32a31e6
to do: fix the init finalize in petsc obj
ZoeLeibowitz Aug 10, 2023
a4f730e
change init to init_finalize in petscobj
ZoeLeibowitz Aug 14, 2023
37a6699
latest
ZoeLeibowitz Aug 14, 2023
c766364
latest
ZoeLeibowitz Jul 20, 2023
eca4440
move petsc pass into petsc.py
ZoeLeibowitz Jul 26, 2023
7fbc8fd
add libr directory and ldflags
ZoeLeibowitz Jul 27, 2023
5540860
dev petsc pass
ZoeLeibowitz Aug 2, 2023
a6bfd8f
latest
ZoeLeibowitz Aug 4, 2023
33029e2
latest
ZoeLeibowitz Aug 8, 2023
43cef9e
add CallBack class to nodes, add some functionalities for this class …
ZoeLeibowitz Aug 10, 2023
5697d1a
add test_callback_cgen
ZoeLeibowitz Aug 10, 2023
96b2359
latest
ZoeLeibowitz Aug 10, 2023
9e758b1
latest
ZoeLeibowitz Aug 14, 2023
f95f36c
petscstruct but hacky
ZoeLeibowitz Aug 16, 2023
bf9bff6
working typedef struct but very hacky
ZoeLeibowitz Aug 16, 2023
809c4f2
typedef working from args frozen params
ZoeLeibowitz Aug 16, 2023
41b0a2b
uxreplace the symbols for callback
ZoeLeibowitz Aug 17, 2023
42f52b5
fixed petsc struct class
ZoeLeibowitz Aug 17, 2023
0069b93
tidy struct petsc
ZoeLeibowitz Aug 17, 2023
55cf8c5
edit _operator_typedecls to find the ctx typedef in the callback root
ZoeLeibowitz Aug 18, 2023
d160b7f
edit struct fields
ZoeLeibowitz Aug 18, 2023
d6990bb
change pfields to check if i is Symbol
ZoeLeibowitz Aug 21, 2023
a3d0676
progress on callback petsc calls
ZoeLeibowitz Aug 21, 2023
18afcc4
latest petsc code
ZoeLeibowitz Aug 21, 2023
1097106
alter loop iterations of callback
ZoeLeibowitz Aug 21, 2023
2afc095
fix transformer i.e use List for body
ZoeLeibowitz Aug 22, 2023
687c476
build more petsc lines inside kernel
ZoeLeibowitz Aug 23, 2023
f63b58b
latest petsc pass
ZoeLeibowitz Aug 24, 2023
c8e4f95
with jit backdoor, it runs now
ZoeLeibowitz Aug 24, 2023
bd8d92e
remove second struct
ZoeLeibowitz Aug 24, 2023
34da299
figured how to adjust iteration space if needed
ZoeLeibowitz Aug 28, 2023
c73ea72
running apart from PetscFunctionBegin
ZoeLeibowitz Aug 28, 2023
a84bc0e
code acc runs
ZoeLeibowitz Aug 28, 2023
794e670
fix so that x_m etc are not args to kernel
ZoeLeibowitz Aug 29, 2023
b25e410
subdomain pass
ZoeLeibowitz Sep 7, 2023
a39a4ad
edits to subdomain iet pass version and python run
ZoeLeibowitz Sep 11, 2023
c9cd114
remove conditionals when building rhs vector
ZoeLeibowitz Sep 12, 2023
53e6d36
change callback to utilise an xextended
ZoeLeibowitz Sep 14, 2023
d049106
switch to more variables rather than numbers
ZoeLeibowitz Sep 16, 2023
feb0504
diff pass with more loops for bcs
ZoeLeibowitz Sep 25, 2023
f61f594
make petsc pass using DMDA
ZoeLeibowitz Oct 2, 2023
b027908
add ccode file produced with dmda pass
ZoeLeibowitz Oct 2, 2023
f594665
turn off shifting
ZoeLeibowitz Oct 2, 2023
01cfcbe
turn off shifting
ZoeLeibowitz Oct 2, 2023
656f769
latest
ZoeLeibowitz Oct 2, 2023
436e001
remove ipythons
ZoeLeibowitz Oct 2, 2023
fd8adc5
remove comment
ZoeLeibowitz Oct 2, 2023
57e81a3
latest
ZoeLeibowitz Oct 2, 2023
dc47d0d
remove ipython
ZoeLeibowitz Oct 2, 2023
71034fe
turn off petsc pass
ZoeLeibowitz Oct 31, 2023
71f9561
add functions to separate petsc pass
ZoeLeibowitz Nov 1, 2023
5025616
turn off negative access bounds checks for petsc
ZoeLeibowitz Nov 1, 2023
634e6cb
remove global y vec
ZoeLeibowitz Nov 1, 2023
e9e5bb2
resort back
ZoeLeibowitz Nov 1, 2023
d6f2182
git checkout origin/master misc file
ZoeLeibowitz Nov 1, 2023
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
2 changes: 0 additions & 2 deletions devito/core/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ def _specialize_iet(cls, graph, **kwargs):

# Misc optimizations
hoist_prodders(graph)

# Symbol definitions
cls._Target.DataManager(**kwargs).process(graph)

# Linearize n-dimensional Indexeds
linearize(graph, **kwargs)

Expand Down
7 changes: 7 additions & 0 deletions devito/finite_differences/finite_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# code generation
_PRECISION = 9

# could add:
# import numpy as np
# _PRECISION = _PRECISION = {np.float32: 9, np.float64: 16}


@check_input
@check_symbolic
Expand Down Expand Up @@ -222,6 +226,9 @@ def make_derivative(expr, dim, fd_order, deriv_order, side, matvec, x0, symbolic
# Enforce fixed precision FD coefficients to avoid variations in results
weights = [sympify(w).evalf(_PRECISION) for w in weights][::matvec.val]

#if using mapper for precision, could have:
# weights = [sympify(w).evalf(_PRECISION[expr.dtype]) for w in weights]

# Transpose the FD, if necessary
if matvec == transpose:
indices = indices.transpose()
Expand Down
21 changes: 11 additions & 10 deletions devito/ir/clusters/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,17 @@ def dspace(self):
d = i.dim.parent
else:
d = i.dim
try:
if i.lower < 0 or \
i.upper > f._size_nodomain[d].left + f._size_halo[d].right:
# It'd mean trying to access a point before the
# left halo (test0) or after the right halo (test1)
oobs.update(d._defines)
except (KeyError, TypeError):
# Unable to detect presence of OOB accesses (e.g., `d` not in
# `f._size_halo`, that is typical of indirect accesses `A[B[i]]`)
pass
# TMP turn off for PETSc
# try:
# if i.lower < 0 or \
# i.upper > f._size_nodomain[d].left + f._size_halo[d].right:
# # It'd mean trying to access a point before the
# # left halo (test0) or after the right halo (test1)
# oobs.update(d._defines)
# except (KeyError, TypeError):
# # Unable to detect presence of OOB accesses (e.g., `d` not in
# # `f._size_halo`, that is typical of indirect accesses `A[B[i]]`)
# pass

# Construct the `intervals` of the DataSpace, that is a global,
# Dimension-centric view of the data space
Expand Down
9 changes: 6 additions & 3 deletions devito/ir/equations/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ def lower_exprs(expressions, **kwargs):
for i in retrieve_indexed(expr):
f = i.function

# Introduce shifting to align with the computational domain
indices = [(lower_exprs(a) + o) for a, o in
zip(i.indices, f._size_nodomain.left)]
# # Introduce shifting to align with the computational domain
# indices = [(lower_exprs(a) + o) for a, o in
# zip(i.indices, f._size_nodomain.left)]

# tmp turn off this shifting in order to utilise DMDA in PETSc
indices = [lower_exprs(a) for a in i.indices]

# Substitute spacing (spacing only used in own dimension)
indices = [i.xreplace({d.spacing: 1, -d.spacing: -1})
Expand Down
15 changes: 14 additions & 1 deletion devito/ir/iet/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'AugmentedExpression', 'Increment', 'Return', 'While',
'ParallelIteration', 'ParallelBlock', 'Dereference', 'Lambda',
'SyncSpot', 'Pragma', 'DummyExpr', 'BlankLine', 'ParallelTree',
'BusyWait', 'CallableBody', 'Transfer']
'BusyWait', 'CallableBody', 'Transfer', 'CallBack']

# First-class IET nodes

Expand Down Expand Up @@ -729,6 +729,19 @@ def defines(self):
return self.all_parameters


class CallBack(Call):

"""
Implement a function pointer argument for a callback function.
"""
def __init__(self, name, return_type, parameter_type, **kwargs):

super().__init__(name=name)

self.return_type = return_type
self.parameter_type = parameter_type


class CallableBody(Node):

"""
Expand Down
1 change: 0 additions & 1 deletion devito/ir/iet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def derive_parameters(iet, drop_locals=False):
# Maybe filter out all other compiler-generated objects
if drop_locals:
parameters = [p for p in parameters if not (p.is_ArrayBasic or p.is_LocalObject)]

return parameters


Expand Down
26 changes: 22 additions & 4 deletions devito/ir/iet/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import ctypes

import cgen as c
from sympy import IndexedBase
from sympy import IndexedBase, sympify
from sympy.core.function import Application

from devito.exceptions import VisitorException
from devito.ir.iet.nodes import (Node, Iteration, Expression, ExpressionBundle,
Call, Lambda, BlankLine, Section)
Call, CallBack, Lambda, BlankLine, Section)
from devito.ir.support.space import Backward
from devito.symbolics import ListInitializer, ccode, uxreplace
from devito.tools import (GenericVisitor, as_tuple, ctypes_to_cstr, filter_ordered,
Expand Down Expand Up @@ -196,7 +196,6 @@ def _gen_struct_decl(self, obj, masked=()):

if not issubclass(ctype, ctypes.Structure):
return None

try:
return obj._C_typedecl
except AttributeError:
Expand Down Expand Up @@ -299,6 +298,7 @@ def _gen_signature(self, o):
tparams = ', '.join([i.inline() for i in self._args_decl(o.templates)])
signature = c.Template(tparams, signature)
return signature


def _blankline_logic(self, children):
"""
Expand Down Expand Up @@ -483,6 +483,12 @@ def visit_Call(self, o, nested_call=False):
rettype = self._gen_rettype(retobj)
return c.Initializer(c.Value(rettype, retobj._C_name), call)

def visit_CallBack(self, o, nested_call=False):
name = o.name
return_type = o.return_type
parameter_type = o.parameter_type
return FunctionPointerArg(name, return_type, parameter_type)

def visit_Conditional(self, o):
try:
then_body, else_body = self._blankline_logic(o.children)
Expand Down Expand Up @@ -646,7 +652,6 @@ def visit_Operator(self, o, mode='all'):
globs = self._operator_globals(o, mode)
if globs:
globs.append(blankline)

return c.Module(headers + includes + typedecls + globs +
esigns + [blankline, kernel] + efuncs)

Expand Down Expand Up @@ -1253,3 +1258,16 @@ def generate(self):
if self.cast:
tip = '(%s)%s' % (self.cast, tip)
yield tip


class FunctionPointerArg(c.Generable):

def __init__(self, name, return_type, parameter_type):
self.name = name
self.return_type = return_type
self.parameter_type = parameter_type

def generate(self):
yield "(%s (*)(%s))%s" % (self.return_type, self.parameter_type, self.name)


15 changes: 4 additions & 11 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from devito.mpi import MPI
from devito.parameters import configuration
from devito.passes import (Graph, lower_index_derivatives, generate_implicit,
generate_macros, minimize_symbols, unevaluate)
generate_macros, minimize_symbols, unevaluate, lower_petsc)
from devito.symbolics import estimate_cost
from devito.tools import (DAG, OrderedSet, Signer, ReducerMap, as_tuple, flatten,
filter_sorted, frozendict, is_integer, split, timed_pass,
Expand Down Expand Up @@ -175,7 +175,6 @@ def _check_kwargs(cls, **kwargs):
def _build(cls, expressions, **kwargs):
# Python- (i.e., compile-) and C-level (i.e., run-time) performance
profiler = create_profile('timers')

# Lower the input expressions into an IET
irs, byproduct = cls._lower(expressions, profiler=profiler, **kwargs)

Expand Down Expand Up @@ -247,10 +246,8 @@ def _lower(cls, expressions, **kwargs):
# This may be used by a compilation pass that constructs a new
# expression for which a partial or complete lowering is desired
kwargs['rcompile'] = cls._rcompile_wrapper(**kwargs)

# [Eq] -> [LoweredEq]
expressions = cls._lower_exprs(expressions, **kwargs)

# [LoweredEq] -> [Clusters]
clusters = cls._lower_clusters(expressions, **kwargs)

Expand Down Expand Up @@ -327,9 +324,7 @@ def _lower_exprs(cls, expressions, **kwargs):

# "True" lowering (indexification, shifting, ...)
expressions = lower_exprs(expressions, **kwargs)

processed = [LoweredEq(i) for i in expressions]

return processed

# Compilation -- Cluster level
Expand Down Expand Up @@ -448,7 +443,6 @@ def _lower_iet(cls, uiet, profiler=None, **kwargs):
"""
name = kwargs.get("name", "Kernel")
sregistry = kwargs['sregistry']

# Wrap the IET with an EntryFunction (a special Callable representing
# the entry point of the generated library)
parameters = derive_parameters(uiet, True)
Expand All @@ -461,14 +455,15 @@ def _lower_iet(cls, uiet, profiler=None, **kwargs):
# Instrument the IET for C-level profiling
# Note: this is postponed until after _specialize_iet because during
# specialization further Sections may be introduced
cls._Target.instrument(graph, profiler=profiler, **kwargs)

cls._Target.instrument(graph, profiler=profiler, **kwargs)
# Extract the necessary macros from the symbolic objects
generate_macros(graph)

# Target-independent optimizations
minimize_symbols(graph)

lower_petsc(graph, **kwargs)

return graph.root, graph

# Read-only properties exposed to the outside world
Expand Down Expand Up @@ -748,7 +743,6 @@ def cinterface(self, force=False):

cfile = name.with_suffix(".%s" % self._compiler.src_ext)
hfile = name.with_suffix('.h')

# Generate the .c and .h code
ccode, hcode = CInterface().visit(self)

Expand Down Expand Up @@ -832,7 +826,6 @@ def apply(self, **kwargs):
# Build the arguments list to invoke the kernel function
with self._profiler.timer_on('arguments'):
args = self.arguments(**kwargs)

# Invoke kernel function with args
arg_values = [args[p.name] for p in self.parameters]
try:
Expand Down
1 change: 1 addition & 0 deletions devito/passes/iet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .asynchrony import * # noqa
from .instrument import * # noqa
from .languages import * # noqa
from .petsc import * # noqa
5 changes: 5 additions & 0 deletions devito/passes/iet/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def place_definitions(self, iet, globs=None, **kwargs):
self._alloc_scalar_on_low_lat_mem((iet,) + v, k, storage)

iet, _ = self._inject_definitions(iet, storage)


# Process all other definitions, essentially all temporary objects
# created by the compiler up to this point (Array, LocalObject, etc.)
Expand Down Expand Up @@ -359,8 +360,12 @@ def place_definitions(self, iet, globs=None, **kwargs):
if v:
includes.add(v)

# it is at this point storage has been populated with the efunc foo and
# a <devito.passes.iet....> so after calling _inject_definitions again
# the ccode inclues cudaStreamCreate etc
iet, efuncs = self._inject_definitions(iet, storage)


return iet, {'efuncs': efuncs,
'globals': as_tuple(globs),
'includes': as_tuple(includes)}
Expand Down
2 changes: 0 additions & 2 deletions devito/passes/iet/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def reuse_efuncs(root, efuncs, sregistry=None):
root = efuncs.pop(root.name)
processed = [afunc if len(efuncs) > 1 else efuncs.pop()
for afunc, efuncs in mapper.values()]

return root, processed


Expand All @@ -245,7 +244,6 @@ def abstract_efunc(efunc):

efunc = Uxreplace(mapper).visit(efunc)
efunc = efunc._rebuild(name='foo')

return efunc


Expand Down
4 changes: 0 additions & 4 deletions devito/passes/iet/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def instrument(graph, **kwargs):
if profiler is None:
return
timer = Timer(profiler.name, list(profiler.all_sections))

instrument_sections(graph, timer=timer, **kwargs)
sync_sections(graph, **kwargs)

Expand Down Expand Up @@ -103,14 +102,11 @@ def instrument_sections(iet, **kwargs):
"""
profiler = kwargs['profiler']
timer = kwargs['timer']

piet = profiler.instrument(iet, timer)

if piet is iet:
return piet, {}

headers = [TimedList._start_timer_header(), TimedList._stop_timer_header()]

return piet, {'headers': headers}


Expand Down
2 changes: 0 additions & 2 deletions devito/passes/iet/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def make_mpi(iet, mpimode=None, **kwargs):
"""
# To produce unique object names
generators = {'msg': generator(), 'comm': generator(), 'comp': generator()}

sync_heb = HaloExchangeBuilder('basic', generators, **kwargs)
user_heb = HaloExchangeBuilder(mpimode, generators, **kwargs)
mapper = {}
Expand All @@ -307,7 +306,6 @@ def make_mpi(iet, mpimode=None, **kwargs):

efuncs = sync_heb.efuncs + user_heb.efuncs
iet = Transformer(mapper, nested=True).visit(iet)

# Must drop the PARALLEL tag from the Iterations within which halo
# exchanges are performed
mapper = {}
Expand Down
Loading
Loading