MapFusionVertical refuses to fuse `map i { for j }` producer and consumer when the producer also reads the intermediate (row recurrence), even with permissive=True
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
Research direction
Start in dace/transformation/dataflow/map_fusion_vertical.py, especially MapFusionVertical.can_be_applied, and trace the checks for nested SDFG access patterns and producer self-dependencies. Use the provided rows reproducer to identify which check rejects fusion with permissive=True. Done means the two maps fuse for the row recurrence while retaining p if removing the intermediate is not valid; verify the transformed SDFG against the stated expected behavior.
Written by the indexing model from the issue text.
Description
Version: extended at 801cafd17 (dace 2.0.0a10); map_fusion_vertical.py unchanged up to 017f54b9d.
Summary. Two maps over rows i, each with a sequential loop over j inside (a nested SDFG). The first computes a recurrence along the row on a transient p; the second reads p along the same row. Iteration i of each map reads and writes only row i, so fusing them into map i { for j (p); for j (q) } is legal and keeps each row in cache. The pattern matcher finds the pair, but MapFusionVertical never applies, also with permissive=True.
import numpy as np
import dace
from dace.transformation.dataflow.map_fusion_vertical import MapFusionVertical
N = dace.symbol("N")
@dace.program
def rows(p0: dace.float64[N], q: dace.float64[N, N]):
p = np.empty((N, N), dtype=np.float64)
for i in dace.map[0:N]:
p[i, 0] = p0[i]
for j in range(1, N):
p[i, j] = 0.5 * p[i, j - 1] + 1.0
for i in dace.map[0:N]:
for j in range(1, N):
q[i, j] = q[i, j - 1] + p[i, j - 1]
sdfg = rows.to_sdfg(simplify=True)
print(sdfg.apply_transformations_repeated(MapFusionVertical)) # 0
print(sdfg.apply_transformations_repeated(MapFusionVertical, permissive=True)) # 0
What the transformation sees (one state, both map bodies are nested SDFGs):
| Edge | Subset of p |
|---|---|
p (read) -> first map |
0:N, 0:N - 1 (the recurrence reads p[i, j - 1]) |
first map -> p (write) |
0:N, 0:N |
p -> second map |
0:N, 0:N - 1 |
Reading p[i, j] instead of p[i, j - 1] in the second map (subset 0:N, 1:N) is refused the same way, so it is not the offset between write and read.
Expected. The two maps fuse: per iteration i the producer writes p[i, 0:N] and the consumer reads p[i, 0:N - 1] (or p[i, 1:N]), both within the row the same iteration produced. If removing the intermediate is not possible (it is read by the producer itself), keeping p in memory and only merging the two map scopes would still be valid.
Likely cause (not confirmed). The producer map reads the intermediate it writes (a read-after-write chain through p inside the first map), which the vertical-fusion checks treat as a dependency between the two maps; or the nested-SDFG bodies hide the per-iteration access, so the producer's write is seen as the whole array. permissive=True does not lift it, so the refusal is in a structural check.
Impact. On Polybench ADI's column sweep (GPU, N = 1600, 25 steps) the program with these maps fused by hand runs in 0.160 s, against 1.180 s for the best schedule without the fusion.
Where it matters. Any alternating-direction / line-sweep code after a loop interchange (Polybench ADI: the p, q, u column sweeps after MoveLoopIntoMap are exactly this shape). Found through NestForge, which applies DaCe MapFusionVertical as its map-fusion move.
Not yet checked. Which condition in MapFusionVertical.can_be_applied returns False (the cause above is a guess), and a hand-fused SDFG validated against NumPy for this exact reproducer. For the full ADI column sweep, a source written with the three row loops in one map gives the same results as the NumPy oracle (rtol 1e-8) on CPU and GPU.
🤖 Generated with Claude Code
- Dominant language
- Python
- Stars
- 602
- Forks
- 171
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spcl/dace
-
Difficulty 3/5 Half a day Newbie friendliness 55/100
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 2 days
-
Operational intensity raises TypeError on any library nodePossibly taken @abhinav-phi claimed this 4 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 2 days
-
ScalarToSymbolPromotion: replace the `0`-assignment fallback with guard-aware read/write analysisOpen
Difficulty 5/5 Over a week Newbie friendliness 42/100
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
software-mansion-labs/Diplomat#20 ·
Maintainers usually reply within 1 day
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaPossibly taken @lijy91 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
libnativeapi/nativeapi#53 · 1 reaction ·
Maintainers usually reply within 1 day
-
View Counts discarded due to field name mismatchPossibly taken @rsiva0400 claimed this today. Opensite-bug triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Model version publishes the new UK firm entity as a personPossibly taken @vahid-ahmadi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PolicyEngine/policyengine.py#764 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
spcl/HPCAgent-Bench#264 ·
Maintainers usually reply within 1 day