Skip to content

Commit

Permalink
api: cleanup based on first review
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Jul 24, 2023
1 parent 1c4ee94 commit 1bce3b5
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 20 deletions.
1 change: 0 additions & 1 deletion devito/ir/clusters/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ def dspace(self):

# Construct the `intervals` of the DataSpace, that is a global,
# Dimension-centric view of the data space

intervals = IntervalGroup.generate('union', *parts.values())
# E.g., `db0 -> time`, but `xi NOT-> x`
intervals = intervals.promote(lambda d: not d.is_Sub)
Expand Down
4 changes: 1 addition & 3 deletions devito/ir/equations/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def handle_indexed(indexed):
# such as A[3])
indexeds = retrieve_indexed(expr, deep=True)
for i in indexeds:
expl_dims = {d for (d, e) in zip(i.function.dimensions, i.indices)
if e.is_integer}
extra.update(expl_dims)
extra.update({d for d in i.function.dimensions if i.indices[d].is_integer})

# Enforce determinism
extra = filter_sorted(extra)
Expand Down
5 changes: 3 additions & 2 deletions devito/ir/support/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,9 @@ def is_const(self, dim):
"""
True if a constant dependence, that is no Dimensions involved, False otherwise.
"""
return (self.source.aindices.get(dim, None) is None and
self.sink.aindices.get(dim, None) is None and
print(self.source.aindices, dim)
return (self.source.aindices.get(dim) is None and
self.sink.aindices.get(dim) is None and
self.distance_mapper.get(dim, 0) == 0)

@memoized_meth
Expand Down
12 changes: 6 additions & 6 deletions devito/operations/interpolators.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _weights(self):
raise NotImplementedError

@property
def _gdim(self):
def _gdims(self):
return self.grid.dimensions

@property
Expand All @@ -153,9 +153,9 @@ def _rdim(self):
parent = self.sfunction.dimensions[-1]
dims = [CustomDimension("r%s%s" % (self.sfunction.name, d.name),
-self.r+1, self.r, 2*self.r, parent)
for d in self._gdim]
for d in self._gdims]

return DimensionTuple(*dims, getters=self._gdim)
return DimensionTuple(*dims, getters=self._gdims)

def _augment_implicit_dims(self, implicit_dims):
return as_tuple(implicit_dims) + self.sfunction.dimensions
Expand All @@ -178,7 +178,7 @@ def _interp_idx(self, variables, implicit_dims=None):

# Coefficient symbol expression
temps.extend(self._coeff_temps(implicit_dims))
for ((di, d), rd, p) in zip(enumerate(self._gdim), self._rdim, pos):
for ((di, d), rd, p) in zip(enumerate(self._gdims), self._rdim, pos):
# Add conditional to avoid OOB
lb = sympy.And(rd + p >= d.symbolic_min - self.r, evaluate=False)
ub = sympy.And(rd + p <= d.symbolic_max + self.r, evaluate=False)
Expand Down Expand Up @@ -330,7 +330,7 @@ class LinearInterpolator(WeightedInterpolator):
@property
def _weights(self):
c = [(1 - p) * (1 - r) + p * r
for (p, d, r) in zip(self._point_symbols, self._gdim, self._rdim)]
for (p, d, r) in zip(self._point_symbols, self._gdims, self._rdim)]
return Mul(*c)

@cached_property
Expand All @@ -345,7 +345,7 @@ def _coeff_temps(self, implicit_dims):
pmap = self.sfunction._position_map
poseq = [Eq(self._point_symbols[d], pos - floor(pos),
implicit_dims=implicit_dims)
for (d, pos) in zip(self._gdim, pmap.keys())]
for (d, pos) in zip(self._gdims, pmap.keys())]
return poseq


Expand Down
2 changes: 1 addition & 1 deletion devito/passes/clusters/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def lower_schedule(schedule, meta, sregistry, ftemps):
# This prevents cases such as `floor(a*b)` with `a` and `b` floats
# that would creat a temporary `int r = b` leading to erronous numerical results
# Such cases happen with the positions for sparse functions for example.
dtype = sympy_dtype(pivot, meta.dtype) or meta.dtype
dtype = sympy_dtype(pivot, meta.dtype)

if writeto:
# The Dimensions defining the shape of Array
Expand Down
4 changes: 3 additions & 1 deletion devito/passes/iet/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def _drop_halospots(iet):

# If a HaloSpot is outside any iteration it is not needed
for iters, halo_spots in MapNodes(Iteration, HaloSpot, 'groupby').visit(iet).items():
if iters:
continue
for hs in halo_spots:
for f, v in hs.fmapper.items():
if not iters and v.loc_indices:
if v.loc_indices:
mapper[hs].add(f)

# Transform the IET introducing the "reduced" HaloSpots
Expand Down
7 changes: 6 additions & 1 deletion devito/passes/iet/parpragma.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,12 @@ def _make_guard(self, parregion):

def _make_nested_partree(self, partree):
# Apply heuristic
if self.nhyperthreads <= self.nested or partree.root.is_ParallelAtomic:
if self.nhyperthreads <= self.nested:
return partree

# Loop nest with atomic reductions are more likely to have less latency
# keep outer loop parallel
if partree.root.is_ParallelAtomic:
return partree

# Note: there might be multiple sub-trees amenable to nested parallelism,
Expand Down
3 changes: 2 additions & 1 deletion devito/symbolics/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,5 @@ def sympy_dtype(expr, default):
return default
else:
# Infer expression dtype from its arguments
return infer_dtype([sympy_dtype(a, default) for a in expr.args])
dtype = infer_dtype([sympy_dtype(a, default) for a in expr.args])
return dtype or default
3 changes: 2 additions & 1 deletion devito/tools/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __getnewargs_ex__(self):
# objects with varying number of attributes
return (tuple(self), dict(self.__dict__))

def get(self, key, val):
def get(self, key, val=None):
return self._getters.get(key, val)


Expand Down Expand Up @@ -605,6 +605,7 @@ class UnboundTuple(object):
"""
A simple data structure that returns the last element forever once reached
"""

def __init__(self, items):
self.items = as_tuple(items)
self.last = len(self.items)
Expand Down
4 changes: 1 addition & 3 deletions devito/types/dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,9 +1460,7 @@ def parent(self):

@property
def origin(self):
"""
SubFunction have zero origin
"""
# SubFunction have zero origin
return DimensionTuple(*(0 for _ in range(self.ndim)), getters=self.dimensions)


Expand Down

0 comments on commit 1bce3b5

Please sign in to comment.