Skip to content

Commit

Permalink
Add support for optional dace backend (#335)
Browse files Browse the repository at this point in the history
 * Add CLI option to run dace backend, if dace module is installed in the python environment.
 * Add CI job configuration to run tests on dace backend, after each PR is merged on main, but ignore test failures.
 * Use manual trigger to run benchmarks on dace backend.
  • Loading branch information
edopao authored Dec 13, 2023
1 parent 9c0b0c6 commit 8b5017e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 22 deletions.
43 changes: 42 additions & 1 deletion ci/cscs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ stages:
PYVERSION: 3.10.9

variables:
DACE_VERSION: "0.15.1"
PERSIST_IMAGE_NAME: $CSCS_REGISTRY_PATH/icon4py:$CI_COMMIT_SHORT_SHA
PYTHON_VERSION: "3.10"

Expand Down Expand Up @@ -50,6 +51,26 @@ test_model_job_roundtrip_simple_grid:
script:
- tox -r -c model/ --verbose -- --benchmark-skip -n auto

test_model_job_dace_cpu_simple_grid:
extends: .test_template
stage: test
script:
- pip install dace==$DACE_VERSION
- tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_cpu
only:
- main
allow_failure: true

test_model_job_dace_gpu_simple_grid:
extends: .test_template
stage: test
script:
- pip install dace==$DACE_VERSION
- tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_gpu
only:
- main
allow_failure: true

test_model_job_gtfn_cpu_simple_grid:
extends: .test_template
stage: test
Expand All @@ -68,11 +89,31 @@ test_tools_job:
script:
- tox -r -c tools/ --verbose

benchmark_model_dace_cpu_simple_grid:
extends: .test_template
stage: benchmark
script:
- pip install dace==$DACE_VERSION
- tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=dace_cpu --grid=simple_grid
only:
- main
when: manual

benchmark_model_dace_gpu_simple_grid:
extends: .test_template
stage: benchmark
script:
- pip install dace==$DACE_VERSION
- tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=dace_gpu --grid=simple_grid
only:
- main
when: manual

benchmark_model_gtfn_cpu_simple_grid:
extends: .test_template
stage: benchmark
script:
- tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=gtfn_cpu --grid=simple_grid
- tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=gtfn_cpu --grid=simple_grid

benchmark_model_gtfn_gpu_simple_grid:
extends: .test_template
Expand Down
50 changes: 29 additions & 21 deletions model/common/src/icon4py/model/common/test_utils/pytest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def pytest_addoption(parser):
pass

try:
# TODO (samkellerhals): set embedded to default as soon as all tests run in embedded mode
parser.addoption(
"--backend",
action="store",
Expand Down Expand Up @@ -80,33 +81,40 @@ def pytest_generate_tests(metafunc):
if "backend" in metafunc.fixturenames:
backend_option = metafunc.config.getoption("backend")

params = []
ids = []
backends = {
"embedded": None,
"roundtrip": run_roundtrip,
"gtfn_cpu": run_gtfn,
"gtfn_gpu": run_gtfn_gpu,
}

if (
backend_option == "None"
): # TODO (samkellerhals): set None to default as soon as all tests run in embedded mode
params.append(None)
ids.append("embedded")

elif backend_option == "gtfn_cpu":
params.append(run_gtfn)
ids.append("backend=gtfn_cpu")

elif backend_option == "roundtrip":
params.append(run_roundtrip)
ids.append("backend=roundtrip")
try:
from gt4py.next.program_processors.runners.dace_iterator import (
run_dace_cpu,
run_dace_gpu,
)

elif backend_option == "gtfn_gpu":
params.append(run_gtfn_gpu)
ids.append("backend=gtfn_gpu")
backends.update(
{
"dace_cpu": run_dace_cpu,
"dace_gpu": run_dace_gpu,
}
)
except ImportError:
# dace module not installed, ignore dace backends
pass

if len(params) < 1:
if backend_option not in backends:
available_backends = ", ".join([f"'{k}'" for k in backends.keys()])
raise Exception(
f"Selected backend: '{backend_option}' is not supported. Select from: 'embedded', 'gtfn_cpu', 'gtfn_gpu'."
"Need to select a backend. Select from: ["
+ available_backends
+ "] and pass it as an argument to --backend when invoking pytest."
)

metafunc.parametrize("backend", params, ids=ids)
metafunc.parametrize(
"backend", [backends[backend_option]], ids=[f"backend={backend_option}"]
)

# parametrise grid
if "grid" in metafunc.fixturenames:
Expand Down

0 comments on commit 8b5017e

Please sign in to comment.