Skip to content

Commit

Permalink
Merge branch 'master' into fix1150
Browse files Browse the repository at this point in the history
  • Loading branch information
acalotoiu authored Sep 18, 2023
2 parents f33202d + 680a956 commit ffe0fc0
Show file tree
Hide file tree
Showing 216 changed files with 18,269 additions and 2,337 deletions.
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
14 changes: 8 additions & 6 deletions .github/workflows/general-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7,'3.10']
python-version: [3.7,'3.11']
simplify: [0,1,autoopt]

steps:
Expand All @@ -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,17 +70,17 @@ 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: |
export NOSTATUSBAR=1
export DACE_testing_serialization=1
export DACE_testing_serialization=0
export DACE_testing_deserialize_exception=1
export DACE_cache=single
export DACE_optimizer_automatic_simplification=${{ matrix.simplify }}
export PYTHON_BINARY="coverage run --source=dace --parallel-mode"
./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
4 changes: 4 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Neville Walo
Lukas Trümper
Cliff Hodel
Tiancheng Chen
Reid Wahl
Yihang Luo
Alexandru Calotoiu
Phillip Lane
Samuel Martin

and other contributors listed in https://github.com/spcl/dace/graphs/contributors
3 changes: 2 additions & 1 deletion dace/cli/daceprof.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def make_sequential(sdfg: dace.SDFG):
for n, _ in sdfg.all_nodes_recursive():
if isinstance(n, dace.nodes.EntryNode):
sched = getattr(n, 'schedule', False)
if sched == dace.ScheduleType.CPU_Multicore or sched == dace.ScheduleType.Default:
if sched in (dace.ScheduleType.CPU_Multicore, dace.ScheduleType.CPU_Persistent,
dace.ScheduleType.Default):
n.schedule = dace.ScheduleType.Sequential

registered.append(dace.hooks.register_sdfg_call_hook(before_hook=make_sequential))
Expand Down
62 changes: 62 additions & 0 deletions dace/cli/fcdc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2019-2023 ETH Zurich and the DaCe authors. All rights reserved.
""" Simple Fortran SDFG command-line compiler. """

import dace
import os
import sys
import argparse
import shutil
from dace.frontend.fortran import fortran_parser

def main():
# Command line options parser
parser = argparse.ArgumentParser(description='Fortran to SDFG command-line transpiler.')

# Required argument for Fortran file path
parser.add_argument('filepath', help='<PATH TO FORTRAN FILE>', type=str)

# Optional argument for output location
parser.add_argument('-o',
'--out',
type=str,
help='If provided, saves library as the given file or in the specified path, '
'together with a header file.')

parser.add_argument('-O',
'--optimize',
dest='optimize',
action='store_true',
help="If set, invokes the command-line optimization"
" interface",
default=False)

args = parser.parse_args()

filepath = args.filepath
if not os.path.isfile(filepath):
print('Fortran file', filepath, 'not found')
exit(1)

outpath = args.out

# Load SDFG
sdfg = fortran_parser.create_sdfg_from_fortran_file(filepath)

if args.optimize:
sdfg.optimize()

# Compile SDFG
sdfg.compile(outpath)

# Copying header file to optional path
if outpath is not None:
source = os.path.join(sdfg.build_folder, 'include', sdfg.name + '.h')
if os.path.isdir(outpath):
outpath = os.path.join(outpath, sdfg.name + '.h')
else:
outpath = os.path.join(os.path.dirname(outpath), sdfg.name + '.h')
shutil.copyfile(source, outpath)


if __name__ == '__main__':
main()
12 changes: 4 additions & 8 deletions dace/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def generate_headers(sdfg: SDFG, frame: framecode.DaCeCodeGenerator) -> str:
exit_params = (sdfg.name, sdfg.name)
proto += 'typedef void * %sHandle_t;\n' % sdfg.name
proto += 'extern "C" %sHandle_t __dace_init_%s(%s);\n' % init_params
proto += 'extern "C" void __dace_exit_%s(%sHandle_t handle);\n' % exit_params
proto += 'extern "C" int __dace_exit_%s(%sHandle_t handle);\n' % exit_params
proto += 'extern "C" void __program_%s(%sHandle_t handle%s);\n' % params
return proto

Expand Down Expand Up @@ -69,15 +69,16 @@ def generate_dummy(sdfg: SDFG, frame: framecode.DaCeCodeGenerator) -> str:
int main(int argc, char **argv) {{
{sdfg.name}Handle_t handle;
int err;
{allocations}
handle = __dace_init_{sdfg.name}({init_params});
__program_{sdfg.name}(handle{params});
__dace_exit_{sdfg.name}(handle);
err = __dace_exit_{sdfg.name}(handle);
{deallocations}
return 0;
return err;
}}
'''

Expand Down Expand Up @@ -177,11 +178,6 @@ def generate_code(sdfg, validate=True) -> List[CodeObject]:
shutil.move(f"{tmp_dir}/test2.sdfg", "test2.sdfg")
raise RuntimeError('SDFG serialization failed - files do not match')

# Run with the deserialized version
# NOTE: This means that all subsequent modifications to `sdfg`
# are not reflected outside of this function (e.g., library
# node expansion).
sdfg = sdfg2

# Before generating the code, run type inference on the SDFG connectors
infer_types.infer_connector_types(sdfg)
Expand Down
31 changes: 29 additions & 2 deletions dace/codegen/common.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Copyright 2019-2022 ETH Zurich and the DaCe authors. All rights reserved.
# Copyright 2019-2023 ETH Zurich and the DaCe authors. All rights reserved.
import ast
from copy import deepcopy
import ctypes.util
from dace import config, data, dtypes, sdfg as sd, symbolic
from dace.sdfg import SDFG
from dace.properties import CodeBlock
from dace.codegen import cppunparse
from dace.codegen.tools import gpu_runtime
from functools import lru_cache
from io import StringIO
import os
Expand Down Expand Up @@ -73,7 +74,7 @@ def update_persistent_desc(desc: data.Data, sdfg: SDFG):
Replaces the symbols used in a persistent data descriptor according to NestedSDFG's symbol mapping.
The replacement happens recursively up to the top-level SDFG.
"""
if (desc.lifetime == dtypes.AllocationLifetime.Persistent and sdfg.parent
if (desc.lifetime in (dtypes.AllocationLifetime.Persistent, dtypes.AllocationLifetime.External) and sdfg.parent
and any(str(s) in sdfg.parent_nsdfg_node.symbol_mapping for s in desc.free_symbols)):
newdesc = deepcopy(desc)
csdfg = sdfg
Expand Down Expand Up @@ -144,3 +145,29 @@ def _try_execute(cmd: str) -> bool:
'set the DaCe configuration entry ``compiler.cuda.backend`` '
'or the ``DACE_compiler_cuda_backend`` environment variable '
'to either "cuda" or "hip".')


@lru_cache()
def get_gpu_runtime() -> gpu_runtime.GPURuntime:
"""
Returns the GPU runtime library (CUDA / HIP) if exists. The result is cached for performance.
"""
backend = get_gpu_backend()
if backend == 'cuda':
libpath = ctypes.util.find_library('cudart')
if os.name == 'nt' and not libpath: # Windows-based search
for version in (12, 11, 10, 9):
libpath = ctypes.util.find_library(f'cudart64_{version}0')
if libpath:
break
elif backend == 'hip':
libpath = ctypes.util.find_library('amdhip64')
else:
raise RuntimeError(f'Cannot obtain GPU runtime library for backend {backend}')

if not libpath:
envname = 'PATH' if os.name == 'nt' else 'LD_LIBRARY_PATH'
raise RuntimeError(f'GPU runtime library for {backend} not found. Please set the {envname} '
'environment variable to point to the libraries.')

return gpu_runtime.GPURuntime(backend, libpath)
Loading

0 comments on commit ffe0fc0

Please sign in to comment.