Skip to content

Commit c01281c

Browse files
authored
Merge pull request #2949 from devitocodes/faster-python-rebased-final
compiler: Faster compilation time
2 parents 87ce0ce + abd7893 commit c01281c

41 files changed

Lines changed: 1839 additions & 755 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

devito/arch/archinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ def parse_product_arch():
497497
def get_visible_devices():
498498
device_vars = (
499499
'CUDA_VISIBLE_DEVICES',
500+
'NVIDIA_VISIBLE_DEVICES',
500501
'ROCR_VISIBLE_DEVICES',
501502
'HIP_VISIBLE_DEVICES'
502503
)

devito/finite_differences/derivative.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
import sympy
88

9-
from devito.tools import Pickable, as_mapper, as_tuple, frozendict, is_integer
9+
from devito.tools import (
10+
Pickable, as_mapper, as_tuple, frozendict, is_integer, memoized_func
11+
)
1012
from devito.types.dimension import Dimension
1113
from devito.types.utils import DimensionTuple
1214
from devito.warnings import warn
@@ -557,6 +559,7 @@ def _evaluate(self, **kwargs):
557559
def _eval_deriv(self):
558560
return self._eval_fd(self.expr)
559561

562+
@memoized_func(scope='build')
560563
def _eval_fd(self, expr, **kwargs):
561564
"""
562565
Evaluate the finite-difference approximation of the Derivative.

devito/finite_differences/differentiable.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,10 @@ def compare(self, other):
10281028
def base(self):
10291029
return self.expr.func(*[a for a in self.expr.args if a is not self.weights])
10301030

1031+
@cached_property
1032+
def pivot(self):
1033+
return self.base.subs({d: 0 for d in self.dimensions})
1034+
10311035
@property
10321036
def weights(self):
10331037
return self._weights

devito/finite_differences/finite_difference.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,15 @@ def make_derivative(expr, dim, fd_order, deriv_order, side, matvec, x0, coeffici
170170
# `coefficients` method (`taylor` or `symbolic`)
171171
if weights is None:
172172
weights = fd_weights_registry[coefficients](expr, deriv_order, indices, x0)
173-
if isinstance(weights, Iterable) and len(weights) != len(indices):
173+
_, wdim, _ = process_weights(weights, expr, dim)
174+
elif isinstance(weights, Iterable) and len(weights) != len(indices):
174175
warning(f"Number of weights ({len(weights)}) does not match "
175176
f"number of indices ({len(indices)}), reverting to Taylor")
176177
scale = False
178+
wdim = None
177179
weights = fd_weights_registry['taylor'](expr, deriv_order, indices, x0)
178180

179181
# Did fd_weights_registry return a new Function/Expression instead of a values?
180-
_, wdim, _ = process_weights(weights, expr, dim)
181182
if wdim is not None:
182183
weights = [weights._subs(wdim, i) for i in range(len(indices))]
183184

devito/finite_differences/tools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,14 @@ def make_stencil_dimension(expr, _min, _max):
228228

229229

230230
@cacheit
231-
def numeric_weights(function, deriv_order, indices, x0):
231+
def _numeric_weights(deriv_order, indices, x0):
232232
return finite_diff_weights(deriv_order, indices, x0)[-1][-1]
233233

234234

235+
def numeric_weights(function, deriv_order, indices, x0):
236+
return _numeric_weights(deriv_order, indices, x0)
237+
238+
235239
fd_weights_registry = {'taylor': numeric_weights, 'standard': numeric_weights,
236240
'symbolic': numeric_weights} # Backward compat for 'symbolic'
237241
coeff_priority = {'taylor': 1, 'standard': 1}

devito/ir/cgen/printer.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
from devito.arch.compiler import AOMPCompiler
1919
from devito.symbolics.inspection import has_integer_args, sympy_dtype
2020
from devito.symbolics.queries import q_leaf
21-
from devito.tools import ctypes_to_cstr, ctypes_vector_mapper, dtype_to_ctype
21+
from devito.tools import (
22+
ctypes_to_cstr, ctypes_vector_mapper, dtype_to_ctype, memoized_func
23+
)
2224
from devito.types.basic import AbstractFunction
2325

24-
__all__ = ['BasePrinter', 'ccode']
26+
__all__ = ['BasePrinter', 'ccode', 'get_printer']
2527

2628

2729
class BasePrinter(CodePrinter):
@@ -449,15 +451,20 @@ def _print_Fallback(self, expr):
449451
sympy.printing.str.StrPrinter._print_Add = BasePrinter._print_Add
450452

451453

452-
def ccode(expr, printer=None, **settings):
454+
@memoized_func
455+
def get_printer(printer, dtype):
456+
return printer(settings={'dtype': dtype})
457+
458+
459+
def ccode(expr, printer=None, dtype=None):
453460
"""Generate C++ code from an expression.
454461
455462
Parameters
456463
----------
457464
expr : expr-like
458465
The expression to be printed.
459-
settings : dict
460-
Options for code printing.
466+
dtype : data-type, optional
467+
Data type used by the printer.
461468
462469
Returns
463470
-------
@@ -468,4 +475,5 @@ def ccode(expr, printer=None, **settings):
468475
if printer is None:
469476
from devito.passes.iet.languages.C import CPrinter
470477
printer = CPrinter
471-
return printer(settings=settings).doprint(expr, None)
478+
dtype = printer._default_settings['dtype'] if dtype is None else dtype
479+
return get_printer(printer, dtype).doprint(expr, None)

devito/ir/clusters/analysis.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _callback(self, clusters, dim, prefix):
101101
is_parallel_atomic = False
102102

103103
scope = Scope(flatten(c.exprs for c in clusters))
104-
for dep in scope.d_all_gen():
104+
for dep in scope.d_all_gen(writes=scope.writes_tensor):
105105
test00 = dep.is_indep(dim) and not dep.is_storage_related(dim)
106106
test01 = all(dep.is_reduce_atmost(i) for i in prev)
107107
if test00 and test01:
@@ -112,10 +112,6 @@ def _callback(self, clusters, dim, prefix):
112112
is_parallel_indep &= (dep.distance_mapper.get(dim.root) == 0)
113113
continue
114114

115-
if dep.function in scope.initialized:
116-
# False alarm, the dependence is over a locally-defined symbol
117-
continue
118-
119115
if dep.is_reduction:
120116
is_parallel_atomic = True
121117
continue

0 commit comments

Comments
 (0)