Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested access with nested symbol dependency #1239

Merged
merged 6 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/fpga-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ jobs:
rm -rf .dacecache tests/.dacecache
. /opt/setupenv
python -m pip install --upgrade pip
pip install pytest-xdist flake8 coverage codecov
pip install pytest-xdist flake8 coverage
pip uninstall -y dace
pip install -e ".[testing]"
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov

- name: Run FPGA Tests
run: |
Expand All @@ -35,7 +37,7 @@ jobs:
reachable=0
ping -W 2 -c 1 codecov.io || reachable=$?
if [ $reachable -eq 0 ]; then
codecov
./codecov
else
echo "Codecov.io is unreachable"
fi
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/general-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ jobs:
sudo apt-get install -y libpapi-dev papi-tools # Instrumentation dependencies
sudo apt-get install -y verilator # RTL simulation dependencies
python -m pip install --upgrade pip
pip install flake8 pytest-xdist coverage codecov
pip install flake8 pytest-xdist coverage
pip install -e ".[testing]"
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov

- name: Test dependencies
run: |
Expand All @@ -52,7 +54,7 @@ jobs:
export DACE_optimizer_automatic_simplification=${{ matrix.simplify }}
fi
pytest -n auto --cov-report=xml --cov=dace --tb=short -m "not gpu and not verilator and not tensorflow and not mkl and not sve and not papi and not mlir and not lapack and not fpga and not mpi and not rtl_hardware and not scalapack and not datainstrument"
codecov
./codecov

- name: Test OpenBLAS LAPACK
run: |
Expand All @@ -68,7 +70,7 @@ jobs:
export DACE_optimizer_automatic_simplification=${{ matrix.simplify }}
fi
pytest -n 1 --cov-report=xml --cov=dace --tb=short -m "lapack"
codecov
./codecov

- name: Run other tests
run: |
Expand All @@ -81,4 +83,4 @@ jobs:
./tests/polybench_test.sh
./tests/xform_test.sh
coverage combine .; coverage report; coverage xml
codecov
./codecov
6 changes: 4 additions & 2 deletions .github/workflows/gpu-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
rm -rf .dacecache tests/.dacecache
. /opt/setupenv
python -m pip install --upgrade pip
pip install flake8 pytest-xdist coverage codecov
pip install flake8 pytest-xdist coverage
pip install mpi4py
pip uninstall -y dace
pip install -e ".[testing]"
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov

- name: Test dependencies
run: |
Expand Down Expand Up @@ -52,7 +54,7 @@ jobs:
reachable=0
ping -W 2 -c 1 codecov.io || reachable=$?
if [ $reachable -eq 0 ]; then
codecov
./codecov
else
echo "Codecov.io is unreachable"
fi
6 changes: 4 additions & 2 deletions .github/workflows/heterogeneous-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
rm -rf .dacecache tests/.dacecache
. /opt/setupenv
python -m pip install --upgrade pip
pip install flake8 pytest-xdist coverage codecov
pip install flake8 pytest-xdist coverage
pip install mpi4py pytest-mpi
pip uninstall -y dace
pip install -e ".[testing]"
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov

- name: Test dependencies
run: |
Expand Down Expand Up @@ -73,7 +75,7 @@ jobs:
reachable=0
ping -W 2 -c 1 codecov.io || reachable=$?
if [ $reachable -eq 0 ]; then
codecov
./codecov
else
echo "Codecov.io is unreachable"
fi
58 changes: 35 additions & 23 deletions dace/frontend/python/newast.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,29 +728,38 @@ def _add_access(
for s, sr in self.symbols.items():
if s in symbolic.symlist(r).values():
ignore_indices.append(i)
sym_rng.append(sr)
# NOTE: Assume that the i-th index of the range is
# dependent on a local symbol s, i.e, rng[i] = f(s).
# Therefore, the i-th index will not be squeezed
# even if it has length equal to 1. However, it must
# still be offsetted by f(min(sr)), so that the indices
# for the squeezed connector start from 0.
# Example:
# Memlet range: [i+1, j, k+1]
# k: local symbol with range(1, 4)
# i,j: global symbols
# Squeezed range: [f(k)] = [k+1]
# Offset squeezed range: [f(k)-f(min(range(1, 4)))] =
# [f(k)-f(1)] = [k-1]
# NOTE: The code takes into account the case where an
# index is dependent on multiple symbols. See also
# tests/python_frontend/nested_name_accesses_test.py.
step = sr[0][2]
if (step < 0) == True:
repl_dict[s] = sr[0][1]
if any(t in self.sdfg.arrays or t in (str(sym) for sym in self.symbols)
for t in sr.free_symbols):
sym_rng.append(subsets.Range([(0, parent_array.shape[i] - 1, 1)]))
repl_dict = {}
break
else:
repl_dict[s] = sr[0][0]
offset.append(r[0].subs(repl_dict))
sym_rng.append(sr)
# NOTE: Assume that the i-th index of the range is
# dependent on a local symbol s, i.e, rng[i] = f(s).
# Therefore, the i-th index will not be squeezed
# even if it has length equal to 1. However, it must
# still be offsetted by f(min(sr)), so that the indices
# for the squeezed connector start from 0.
# Example:
# Memlet range: [i+1, j, k+1]
# k: local symbol with range(1, 4)
# i,j: global symbols
# Squeezed range: [f(k)] = [k+1]
# Offset squeezed range: [f(k)-f(min(range(1, 4)))] =
# [f(k)-f(1)] = [k-1]
# NOTE: The code takes into account the case where an
# index is dependent on multiple symbols. See also
# tests/python_frontend/nested_name_accesses_test.py.
step = sr[0][2]
if (step < 0) == True:
repl_dict[s] = sr[0][1]
else:
repl_dict[s] = sr[0][0]
if repl_dict:
offset.append(r[0].subs(repl_dict))
else:
offset.append(0)

if ignore_indices:
tmp_memlet = Memlet.simple(parent_name, rng)
Expand Down Expand Up @@ -2913,8 +2922,11 @@ def _add_access(
for s, sr in self.symbols.items():
if s in symbolic.symlist(r).values():
ignore_indices.append(i)
if any(t in self.sdfg.arrays for t in sr.free_symbols):
if any(t in self.sdfg.arrays or t in (str(sym) for sym in self.symbols)
for t in sr.free_symbols):
sym_rng.append(subsets.Range([(0, parent_array.shape[i] - 1, 1)]))
repl_dict = {}
break
else:
sym_rng.append(sr)
# NOTE: Assume that the i-th index of the range is
Expand Down
46 changes: 46 additions & 0 deletions tests/python_frontend/nested_name_accesses_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2019-2021 ETH Zurich and the DaCe authors. All rights reserved.
import dace as dc
import numpy as np
import os

N = dc.symbol('N')

Expand Down Expand Up @@ -138,6 +139,49 @@ def nested_offset_access(inp: dc.float64[6, 5, 5]):
assert (np.allclose(out, ref))


def test_nested_offset_access_nested_dependency():
@dc.program
def nested_offset_access_nested_dep(inp: dc.float64[6, 5, 5]):
out = np.zeros((5, 5, 5), np.float64)
for i, j in dc.map[0:5, 0:5]:
out[i, j, 0] = 0.25 * (inp[i + 1, j, 1] + inp[i, j, 1])
for k in range(1, 4):
for l in range(k, 5):
out[i, j, k] = 0.25 * (inp[i + 1, j, l - k + 1] + inp[i, j, l - k + 1])
return out

inp = np.reshape(np.arange(6 * 5 * 5, dtype=np.float64), (6, 5, 5)).copy()
last_value = os.environ.get('DACE_testing_serialization', '0')
os.environ['DACE_testing_serialization'] = '0'
with dc.config.set_temporary('testing', 'serialization', value=False):
out = nested_offset_access_nested_dep(inp)
os.environ['DACE_testing_serialization'] = last_value
ref = nested_offset_access_nested_dep.f(inp)
assert (np.allclose(out, ref))


def test_nested_offset_access_nested_dependency_dappy():
@dc.program
def nested_offset_access_nested_dep(inp: dc.float64[6, 5, 10]):
out = np.zeros((5, 5, 10), np.float64)
for i, j in dc.map[0:5, 0:5]:
out[i, j, 0] = 0.25 * (inp[i + 1, j, 1] + inp[i, j, 1])
for k in range(1, 5):
for l in range(k, 4):
with dc.tasklet():
in1 << inp[i + 1, j, k + l + 1]
in2 << inp[i, j, k + l + 1]
out1 >> out[i, j, k + l]
out1 = 0.25 * (in1 + in2)
return out

inp = np.reshape(np.arange(6 * 5 * 10, dtype=np.float64), (6, 5, 10)).copy()
out = nested_offset_access_nested_dep(inp)
ref = nested_offset_access_nested_dep.f(inp)
assert (np.allclose(out, ref))



if __name__ == "__main__":
test_nested_name_accesses()
test_nested_offset_access()
Expand All @@ -146,3 +190,5 @@ def nested_offset_access(inp: dc.float64[6, 5, 5]):
test_nested_multi_offset_access_dappy()
test_nested_dec_offset_access()
test_nested_dec_offset_access_dappy()
test_nested_offset_access_nested_dependency()
test_nested_offset_access_nested_dependency_dappy()