-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Control Flow Block Constraints (#1476)
This PR implements pre- and post-conditions on control flow blocks, as well as invariants. This is a feature that was discussed in the last DaCe Workshop of 2023 but has not been implemented yet since then. These invariants serve as helpers in analysis of the SDFG and may in the future be used to add runtime checks / assertions (optionally). A pass can be used to attempt automatic derivation of such constraints, or they can be manually set as properties. This PR adds the scaffolding for this and for now implements a single auto-constraint-derivation criterium, which states that parameters used to determine data container sizes are always `>= 0` and optionally assumed to always be `<= MAX_N`, where `MAX_N` is a configurable analysis pass parameter.
- Loading branch information
1 parent
e2a00cb
commit 052e2c8
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. | ||
|
||
import dace | ||
from dace.transformation.passes.analysis import DeriveSDFGConstraints | ||
|
||
|
||
def test_infer_data_dim_constraints_nomax(): | ||
N = dace.symbol('N') | ||
|
||
@dace.program | ||
def matmul(A: dace.float64[N, N], B: dace.float64[N, N], C: dace.float64[N, N]): | ||
for i in range(N): | ||
for j in range(N): | ||
for k in range(N): | ||
C[i, j] += A[i, k] * B[k, j] | ||
|
||
sdfg = matmul.to_sdfg() | ||
|
||
derive_pass = DeriveSDFGConstraints() | ||
_, inv, _ = derive_pass.apply_pass(sdfg, {}) | ||
|
||
assert 'N' in inv | ||
assert 'N > 0' in inv['N'] | ||
|
||
|
||
def test_infer_data_dim_constraints_withmax(): | ||
N = dace.symbol('N') | ||
|
||
@dace.program | ||
def matmul(A: dace.float64[N, N], B: dace.float64[N, N], C: dace.float64[N, N]): | ||
for i in range(N): | ||
for j in range(N): | ||
for k in range(N): | ||
C[i, j] += A[i, k] * B[k, j] | ||
|
||
sdfg = matmul.to_sdfg() | ||
|
||
derive_pass = DeriveSDFGConstraints() | ||
derive_pass.assume_max_data_size = 128 | ||
_, inv, _ = derive_pass.apply_pass(sdfg, {}) | ||
|
||
assert 'N' in inv | ||
assert 'N > 0' in inv['N'] | ||
assert 'N <= 128' in inv['N'] | ||
|
||
|
||
if __name__ == "__main__": | ||
test_infer_data_dim_constraints_nomax() | ||
test_infer_data_dim_constraints_withmax() |