Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions devito/ir/clusters/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ def from_clusters(cls, *clusters):
if not all(root.guards == c.guards for c in clusters):
raise ValueError("Cannot build a Cluster from Clusters with "
"non-homogeneous guards")
if not all(root.dtype == c.dtype for c in clusters):
raise ValueError("Cannot build a Cluster from Clusters with "
"non-homogeneous data types")

writes = set().union(*[c.scope.writes for c in clusters])
reads = set().union(*[c.scope.reads for c in clusters])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2961,7 +2961,7 @@ def test_fullopt(self):
assert np.isclose(summary0[('section0', None)].oi, 3.136, atol=0.001)

assert summary1[('section0', None)].ops == 31
assert summary1[('section1', None)].ops == 16
assert summary1[('section1', None)].ops == 8
assert summary1[('section2', None)].ops == 4
assert np.isclose(summary1[('section0', None)].oi, 1.767, atol=0.001)

Expand Down
21 changes: 21 additions & 0 deletions tests/test_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from devito.ir.equations import LoweredEq
from devito.ir.equations.algorithms import dimension_sort
from devito.ir.iet import FindNodes, Iteration
from devito.ir.stree import stree_build
from devito.ir.support.basic import (
AFFINE, IRREGULAR, REGULAR, IterationInstance, Scope, TimedAccess, Vector, mocksym0,
mocksym1
Expand Down Expand Up @@ -1162,6 +1163,26 @@ def test_dimension_sort(self, expr, expected):
assert list(dimension_sort(expr)) == eval(expected)


class TestCluster:

def test_from_clusters_mixed_dtypes(self):
grid = Grid(shape=(4,))
x, = grid.dimensions

f = Function(name='f', grid=grid, dtype=np.float32)
g = Function(name='g', grid=grid, dtype=np.float64)

ispace = IterationSpace([Interval(x)])
clusters = (Cluster(Eq(f, 1), ispace=ispace),
Cluster(Eq(g, 1), ispace=ispace))

with pytest.raises(ValueError, match="non-homogeneous data types"):
Cluster.from_clusters(*clusters)

stree = stree_build(clusters)
assert len([i for i in stree.visit() if i.is_Iteration]) == 1


class TestClusterGroup:

def test_eq_hash_include_ispace(self):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,16 @@ def test_permutations_without_deps(self):
exprs = FindNodes(Expression).visit(tree[-1])
assert len(exprs) == 3

def test_fusion_mixed_dtypes(self):
grid = Grid(shape=(4, 4))

f = Function(name='f', grid=grid, dtype=np.uint16)
g = Function(name='g', grid=grid, dtype=np.float32)

op = Operator([Eq(f, 1), Eq(g, 1)])

assert_structure(op, ['x,y'], 'x,y')

@pytest.mark.parametrize('exprs,fissioned,shared', [
# 0) Trivial case
(('Eq(u, 1)', 'Eq(v, u.dxl)'), '(1,x)', [0]),
Expand Down
Loading