|
12 | 12 | Interval, IntervalGroup, IterationSpace, LabeledVector, Queue, Vector, extrema, |
13 | 13 | maximum, minimum, normalize_properties, relax_properties, unbounded, vmax, vmin |
14 | 14 | ) |
| 15 | +from devito.ir.support import null_ispace |
15 | 16 | from devito.passes.clusters.cse import _cse |
16 | 17 | from devito.symbolics import ( |
17 | 18 | Uxmapper, estimate_cost, retrieve_functions, reuse_if_untouched, search, sympy_dtype, |
@@ -131,7 +132,8 @@ def _aliases_from_clusters(self, cgroup, exclude, meta): |
131 | 132 | # AliasList -> Schedule |
132 | 133 | schedule = lower_aliases(aliases, meta, self.opt_maxpar) |
133 | 134 |
|
134 | | - variants.append(Variant(schedule, exprs)) |
| 135 | + if schedule: |
| 136 | + variants.append(Variant(schedule, exprs)) |
135 | 137 |
|
136 | 138 | if not variants: |
137 | 139 | return [] |
@@ -860,6 +862,7 @@ def lower_schedule(schedule, meta, sregistry, opt_ftemps, opt_min_dtype, |
860 | 862 | make = TempFunction if opt_ftemps else TempArray |
861 | 863 |
|
862 | 864 | clusters = [] |
| 865 | + inits = [] |
863 | 866 | subs = {} |
864 | 867 | for pivot, writeto, ispace, aliaseds, indicess in schedule: |
865 | 868 | name = sregistry.make_name() |
@@ -928,8 +931,11 @@ def lower_schedule(schedule, meta, sregistry, opt_ftemps, opt_min_dtype, |
928 | 931 | assert writeto.size == 0 |
929 | 932 |
|
930 | 933 | dtype = sympy_dtype(pivot, base=meta.dtype, smin=opt_min_dtype) |
931 | | - obj = Temp(name=name, dtype=dtype) |
| 934 | + const = not meta.guards |
| 935 | + obj = Temp(name=name, dtype=dtype, is_const=const) |
932 | 936 | expression = Eq(obj, uxreplace(pivot, subs)) |
| 937 | + if not const: |
| 938 | + inits.append(Eq(obj, 0)) |
933 | 939 |
|
934 | 940 | callback = lambda idx: obj # noqa: B023 |
935 | 941 |
|
@@ -959,6 +965,13 @@ def lower_schedule(schedule, meta, sregistry, opt_ftemps, opt_min_dtype, |
959 | 965 | # Finally, build the alias Cluster |
960 | 966 | clusters.append(Cluster(expression, ispace, meta.guards, properties)) |
961 | 967 |
|
| 968 | + if inits: |
| 969 | + # To avoid undefined variables when an constant (Temp) alias is used |
| 970 | + # within different guards/loop, we need to initialize it outside of the loops |
| 971 | + # so that it's globally defined. |
| 972 | + # See tests/test_dse.py::TestAliases::test_split_cond |
| 973 | + clusters.insert(0, Cluster(inits, null_ispace)) |
| 974 | + |
962 | 975 | return clusters, subs |
963 | 976 |
|
964 | 977 |
|
|
0 commit comments