spcl / spcl/dace

Greedy fusion breaks loop with nested SDFG

Open
#1,280 7 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
593
Forks
163
Avg merge
2d 23h
Merged PRs (30d)
60

Description

**Describe the bug**

An application of `greedy_fuse` breaks one of the loops in CloudSC, as seen in the screenshot below. In this context, `ZSINKSUM` is both an input and output variable. The variable is correctly initialized but stored in the additional and unnecessary variable `__tmp2` that is never passed correctly to the actual function.

Generated code:

```cpp
DACE_DFI void loop_body_6_1_138_7(double* __restrict__ ZSOLQA, double* __restrict__ ZSINKSUM, int _for_it_73);

{
double ZSINKSUM_out_1;
// Tasklet code (T_l4181_c4181)
ZSINKSUM_out_1 = 0.0;
__tmp2[0] = ZSINKSUM_out_1;
}

dace::CopyND::template ConstDst<1>::Copy( __tmp2, ZSINKSUM + _for_it_69, 1);
loop_body_6_1_138_7(&ZSOLQA[0], &__tmp1[0], (_for_it_69 + 1));
dace::CopyND::template ConstDst<1>::Copy( __tmp1, ZSINKSUM + _for_it_69, 1);
```

![image](https://github.com/spcl/dace/assets/720619/dc289651-2a66-4c02-afe3-604c8a5a542f)

**To Reproduce**

1. Download the following SDFG: https://polybox.ethz.ch/index.php/s/YC0ugZL7vG73doz
2. Apply the `greedy_fuse` from autoopt.

```
sdfg = dace.SDFG.from_file('CLOUDSCOUTER_unrolled.sdfg')
greedy_fuse(sdfg, False)
sdfg.simplify(verbose=True)
```

4. Look for the state starting with `_state_l4191_c4191`.

**Desktop (please complete the following information):**
- Python 3.10

Contributor guide

Open the contributing guide

Research direction

Start with the autoopt entry point greedy_fuse and reproduce the issue by loading CLOUDSCOUTER_unrolled.sdfg, applying the transformation, and simplifying the SDFG. Inspect the state beginning with _state_l4191_c4191 and compare the generated loop arguments and ZSINKSUM handling. Done means the nested-SDFG loop remains intact and the initialized value is passed to the actual function rather than being stranded in __tmp2.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.