Post-Validation Modifications Produce Invalid SDFGs
- Dominant language
- Python
- Stars
- 593
- Forks
- 163
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 60
Description
**Description**
In `codegen.py`, the SDFG is validated before compilation. However, the SDFG can still be modified after this validation step, and those intermediate changes are not re-validated. This can lead to code being generated from an invalid SDFG, resulting in subtle and unexpected bugs.
For example, as shown in [PR #2117](https://github.com/spcl/dace/pull/2117), a bug in the GEMM `LibraryNode` expansion resulted in an invalid SDFG. The issue was only exposed when `sdfg.apply_transformations_once_everywhere(...)` was called during CUDA codegen preprocessing. This method triggers `sdfg.validate()`, which then raised an error unrelated to the new transformation itself, but caused by the earlier expansion step that had not been properly validated.
This PR addresses the bug in this specific instance, but similar issues may exist elsewhere. Invalid SDFG states
introduced after the initial validation can go unnoticed and only be caught much later, during code generation or
execution.
**Reproduce**
If [PR #2117](https://github.com/spcl/dace/pull/2117) is not yet merged, you can reproduce the issue by replacing this line in the code:
```python
# Recursively expand library nodes that have not yet been expanded
sdfg.expand_library_nodes()
```
by
```python
# Recursively expand library nodes that have not yet been expanded
sdfg.expand_library_nodes()
sdfg.validate()
```
and run:
```shell
pytest ./tests/library/gemm_test.py --cov-report=xml --cov=dace --tb=short -m "gpu"
```
Contributor guide
Assessment
This issue has not been assessed yet.