Skip to content

Commit

Permalink
Merge branch 'master' into users/lukas/propagation-with-offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad authored May 30, 2024
2 parents 9278b85 + 7214739 commit ed768e8
Show file tree
Hide file tree
Showing 17 changed files with 331 additions and 105 deletions.
75 changes: 0 additions & 75 deletions .github/workflows/pace-build-ci.yml

This file was deleted.

96 changes: 96 additions & 0 deletions .github/workflows/pyFV3-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: NASA/NOAA pyFV3 repository build test

on:
push:
branches: [ master, ci-fix ]
pull_request:
branches: [ master, ci-fix ]
merge_group:
branches: [ master, ci-fix ]

defaults:
run:
shell: bash

jobs:
build_and_validate_pyFV3:
if: "!contains(github.event.pull_request.labels.*.name, 'no-ci')"
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.11.7]

steps:
- uses: actions/checkout@v2
with:
repository: 'NOAA-GFDL/PyFV3'
ref: 'ci/DaCe'
submodules: 'recursive'
path: 'pyFV3'
- uses: actions/checkout@v2
with:
path: 'dace'
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install library dependencies
run: |
sudo apt-get update
sudo apt-get install -y libopenmpi-dev libboost-all-dev
gcc --version
# Because Github doesn't allow us to do a git checkout in code
# we use a trick to checkout DaCe first (not using the external submodule)
# install the full suite via requirements_dev, then re-install the correct DaCe
- name: Install Python packages
run: |
python -m pip install --upgrade pip wheel setuptools
pip install -e ./pyFV3[develop]
pip install -e ./dace
- name: Download data
run: |
cd pyFV3
mkdir -p test_data
cd test_data
wget https://portal.nccs.nasa.gov/datashare/astg/smt/pace-regression-data/8.1.3_c12_6ranks_standard.D_SW.tar.gz
tar -xzvf 8.1.3_c12_6ranks_standard.D_SW.tar.gz
wget https://portal.nccs.nasa.gov/datashare/astg/smt/pace-regression-data/8.1.3_c12_6ranks_standard.RiemSolver3.tar.gz
tar -xzvf 8.1.3_c12_6ranks_standard.RiemSolver3.tar.gz
wget https://portal.nccs.nasa.gov/datashare/astg/smt/pace-regression-data/8.1.3_c12_6ranks_standard.Remapping.tar.gz
tar -xzvf 8.1.3_c12_6ranks_standard.Remapping.tar.gz
cd ../..
# Clean up caches between run for stale un-expanded SDFG to trip the build system (NDSL side issue)
- name: "Regression test: Riemman Solver on D-grid (RiemSolver3)"
env:
FV3_DACEMODE: BuildAndRun
PACE_CONSTANTS: GFS
PACE_LOGLEVEL: Debug
run: |
pytest -v -s --data_path=./pyFV3/test_data/8.1.3/c12_6ranks_standard/dycore \
--backend=dace:cpu --which_modules=Riem_Solver3 \
--threshold_overrides_file=./pyFV3/tests/savepoint/translate/overrides/standard.yaml \
./pyFV3/tests/savepoint
rm -r ./.gt_cache_FV3_A
- name: "Regression test: Shallow water lagrangian dynamics on D-grid (D_SW) (on rank 0 only)"
env:
FV3_DACEMODE: BuildAndRun
PACE_CONSTANTS: GFS
PACE_LOGLEVEL: Debug
run: |
pytest -v -s --data_path=./pyFV3/test_data/8.1.3/c12_6ranks_standard/dycore \
--backend=dace:cpu --which_modules=D_SW --which_rank=0 \
--threshold_overrides_file=./pyFV3/tests/savepoint/translate/overrides/standard.yaml \
./pyFV3/tests/savepoint
rm -r ./.gt_cache_FV3_A
- name: "Regression test: Remapping (on rank 0 only)"
env:
FV3_DACEMODE: BuildAndRun
PACE_CONSTANTS: GFS
PACE_LOGLEVEL: Debug
run: |
pytest -v -s --data_path=./pyFV3/test_data/8.1.3/c12_6ranks_standard/dycore \
--backend=dace:cpu --which_modules=Remapping --which_rank=0 \
--threshold_overrides_file=./pyFV3/tests/savepoint/translate/overrides/standard.yaml \
./pyFV3/tests/savepoint
rm -r ./.gt_cache_FV3_A
9 changes: 6 additions & 3 deletions dace/cli/sdfv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NewCls(cls):
return NewCls


def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None, verbose: bool = True):
"""
View an sdfg in the system's HTML viewer
Expand All @@ -33,6 +33,7 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
the generated HTML and related sources will be
served using a basic web server on that port,
blocking the current thread.
:param verbose: Be verbose.
"""
# If vscode is open, try to open it inside vscode
if filename is None:
Expand Down Expand Up @@ -71,7 +72,8 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
with open(html_filename, "w") as f:
f.write(html)

print("File saved at %s" % html_filename)
if(verbose):
print("File saved at %s" % html_filename)

if fd is not None:
os.close(fd)
Expand All @@ -83,7 +85,8 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
# start the web server
handler = partialclass(http.server.SimpleHTTPRequestHandler, directory=dirname)
httpd = http.server.HTTPServer(('localhost', filename), handler)
print(f"Serving at localhost:{filename}, press enter to stop...")
if(verbose):
print(f"Serving at localhost:{filename}, press enter to stop...")

# start the server in a different thread
def serve():
Expand Down
4 changes: 2 additions & 2 deletions dace/config_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -945,10 +945,10 @@ required:
serialize_all_fields:
type: bool
default: true
default: false
title: Serialize all unmodified fields in SDFG files
description: >
If False, saving an SDFG keeps only the modified non-default properties. If True,
If False (default), saving an SDFG keeps only the modified non-default properties. If True,
saves all fields.
#############################################
Expand Down
1 change: 1 addition & 0 deletions dace/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ def isconstant(var):
int16 = typeclass(numpy.int16)
int32 = typeclass(numpy.int32)
int64 = typeclass(numpy.int64)
uintp = typeclass(numpy.uintp)
uint8 = typeclass(numpy.uint8)
uint16 = typeclass(numpy.uint16)
uint32 = typeclass(numpy.uint32)
Expand Down
7 changes: 6 additions & 1 deletion dace/frontend/python/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def program(f: F,
recreate_sdfg: bool = True,
regenerate_code: bool = True,
recompile: bool = True,
distributed_compilation: bool = False,
constant_functions=False,
**kwargs) -> Callable[..., parser.DaceProgram]:
"""
Expand All @@ -60,6 +61,9 @@ def program(f: F,
it.
:param recompile: Whether to recompile the code. If False, the library in the build folder will be used if it exists,
without recompiling it.
:param distributed_compilation: Whether to compile the code from rank 0, and broadcast it to all the other ranks.
If False, every rank performs the compilation. In this case, make sure to check the ``cache`` configuration entry
such that no caching or clashes can happen between different MPI processes.
:param constant_functions: If True, assumes all external functions that do
not depend on internal variables are constant.
This will hardcode their return values into the
Expand All @@ -78,7 +82,8 @@ def program(f: F,
constant_functions,
recreate_sdfg=recreate_sdfg,
regenerate_code=regenerate_code,
recompile=recompile)
recompile=recompile,
distributed_compilation=distributed_compilation)


function = program
Expand Down
4 changes: 2 additions & 2 deletions dace/frontend/python/newast.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def _add_access(
arr_type = type(parent_array)
if arr_type == data.Scalar:
self.sdfg.add_scalar(var_name, dtype)
elif arr_type in (data.Array, data.View):
elif issubclass(arr_type, data.Array):
self.sdfg.add_array(var_name, shape, dtype, strides=strides)
elif arr_type == data.Stream:
self.sdfg.add_stream(var_name, dtype)
Expand Down Expand Up @@ -3116,7 +3116,7 @@ def _add_access(
arr_type = data.Scalar
if arr_type == data.Scalar:
self.sdfg.add_scalar(var_name, dtype)
elif arr_type in (data.Array, data.View):
elif issubclass(arr_type, data.Array):
if non_squeezed:
strides = [parent_array.strides[d] for d in non_squeezed]
else:
Expand Down
8 changes: 5 additions & 3 deletions dace/frontend/python/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def __init__(self,
recreate_sdfg: bool = True,
regenerate_code: bool = True,
recompile: bool = True,
distributed_compilation: bool = False,
method: bool = False):
from dace.codegen import compiled_sdfg # Avoid import loops

Expand All @@ -171,6 +172,7 @@ def __init__(self,
self.recreate_sdfg = recreate_sdfg
self.regenerate_code = regenerate_code
self.recompile = recompile
self.distributed_compilation = distributed_compilation

self.global_vars = _get_locals_and_globals(f)
self.signature = inspect.signature(f)
Expand Down Expand Up @@ -449,12 +451,12 @@ def __call__(self, *args, **kwargs):
sdfg.simplify()

with hooks.invoke_sdfg_call_hooks(sdfg) as sdfg:
if not mpi4py:
if self.distributed_compilation and mpi4py:
binaryobj = distributed_compile(sdfg, mpi4py.MPI.COMM_WORLD, validate=self.validate)
else:
# Compile SDFG (note: this is done after symbol inference due to shape
# altering transformations such as Vectorization)
binaryobj = sdfg.compile(validate=self.validate)
else:
binaryobj = distributed_compile(sdfg, mpi4py.MPI.COMM_WORLD, validate=self.validate)

# Recreate key and add to cache
cachekey = self._cache.make_key(argtypes, specified, self.closure_array_keys, self.closure_constant_keys,
Expand Down
18 changes: 15 additions & 3 deletions dace/frontend/python/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,16 +752,28 @@ def visit_Subscript(self, node: ast.Subscript) -> Any:
return self.generic_visit(node)

# Then query for the right value
if isinstance(node.value, ast.Dict):
if isinstance(node.value, ast.Dict): # Dict
for k, v in zip(node.value.keys, node.value.values):
try:
gkey = astutils.evalnode(k, self.globals)
except SyntaxError:
continue
if gkey == gslice:
return self._visit_potential_constant(v, True)
else: # List or Tuple
return self._visit_potential_constant(node.value.elts[gslice], True)
elif isinstance(node.value, (ast.List, ast.Tuple)): # List & Tuple
# Loop over the list if slicing makes it a list
if isinstance(node.value.elts[gslice], List):
visited_list = astutils.copy_tree(node.value)
visited_list.elts.clear()
for v in node.value.elts[gslice]:
visited_cst = self._visit_potential_constant(v, True)
visited_list.elts.append(visited_cst)
node.value = visited_list
return node
else:
return self._visit_potential_constant(node.value.elts[gslice], True)
else: # Catch-all
return self._visit_potential_constant(node, True)

return self._visit_potential_constant(node, True)

Expand Down
11 changes: 7 additions & 4 deletions dace/sdfg/sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ def __init__(self,
:param name: Name for the SDFG (also used as the filename for
the compiled shared library).
:param symbols: Additional dictionary of symbol names -> types that the SDFG
defines, apart from symbolic data sizes.
:param constants: Additional dictionary of compile-time constants
{name (str): tuple(type (dace.data.Data), value (Any))}.
:param propagate: If False, disables automatic propagation of
memlet subsets from scopes outwards. Saves
processing time but disallows certain
Expand Down Expand Up @@ -1520,6 +1520,8 @@ def save(self, filename: str, use_pickle=False, hash=None, exception=None, compr
:param compress: If True, uses gzip to compress the file upon saving.
:return: The hash of the SDFG, or None if failed/not requested.
"""
filename = os.path.expanduser(filename)

if compress:
fileopen = lambda file, mode: gzip.open(file, mode + 't')
else:
Expand Down Expand Up @@ -1547,14 +1549,15 @@ def save(self, filename: str, use_pickle=False, hash=None, exception=None, compr

return None

def view(self, filename=None):
def view(self, filename=None, verbose=False):
"""
View this sdfg in the system's HTML viewer
:param filename: the filename to write the HTML to. If `None`, a temporary file will be created.
:param verbose: Be verbose, `False` by default.
"""
from dace.cli.sdfv import view
view(self, filename=filename)
view(self, filename=filename, verbose=verbose)

@staticmethod
def _from_file(fp: BinaryIO) -> 'SDFG':
Expand Down
Loading

0 comments on commit ed768e8

Please sign in to comment.