spcl / spcl/dace

[Release 1.0] `FuseStates` collapse wrong edge + undefined behavior

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

Description

Hunting for a bad write in our model we discovered that DaCe had swapped two maps order with no data dependency. This was tracked down to `FuseStates` misbehaving. While reproducing, the error was fickle, disappearing easily - we rebuild a partial reproducer showing the bug _and_ showing a determinism issue with the pass.

## Fuse States issue

The original SDFG looks like this (file attached below)

![Image](https://github.com/user-attachments/assets/cf7db331-0e71-4f28-bf41-0b748a9cc789)

`Block_3` has `q` has an input
`Block_5` has `q` has an output
Block 3 and 5 are effectively not sharing data dependency (output of 3 is not used in 5) but the order of blocks matter since this is a write-after-read situation.

When `FuseStates` applied (see beloew) `FuseStates` produces a single Block:

![Image](https://github.com/user-attachments/assets/ec264861-772b-48a7-9807-e5cde129fc2b)

instead of two:

![Image](https://github.com/user-attachments/assets/a338f81e-be7f-42c3-8300-20d55c26bc1d)

## Lack of determinism

Using the attached [unsimplified.sdfg.txt](https://github.com/user-attachments/files/18972136/unsimplified.sdfg.txt) as the input

This simple script should reproduce the above
```python

import dace
from dace.transformation.passes.fusion_inline import FuseStates

def f():
sdfg = dace.SDFG.from_file("./unsimplified.sdfg")
ret = FuseStates().apply_pass(sdfg, {})
print(f"Fuzed state: {ret}")
return 0

if __name__ == "__main__":
f()
```

Will print 7 if the error shows *BUT* could be printing 6 if the error magically doesn't show.

Wrapping into a simple bash should show the issue

```bash
#!/bin/bash

for i in {1..10}
do
python code_dace.py
done
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.