From af72744b4c4041c7307f204b9f94383e353d5479 Mon Sep 17 00:00:00 2001 From: Edoardo Paone Date: Thu, 14 Sep 2023 11:13:53 +0200 Subject: [PATCH 1/4] Add support for optional dace backend * Add CLI option to run dace backend, if dace module is installed in the python environment. * Add CI job configuration to run tests and bechmark on dace backend, but it must be manually triggered. --- ci/cscs.yml | 34 +++++++++++++- .../model/common/test_utils/pytest_config.py | 47 ++++++++++--------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/ci/cscs.yml b/ci/cscs.yml index 660817e5ed..61d8fe2c68 100644 --- a/ci/cscs.yml +++ b/ci/cscs.yml @@ -50,6 +50,22 @@ 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 + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_cpu + when: manual + +test_model_job_dace_gpu_simple_grid: + extends: .test_template + stage: test + script: + - pip install dace + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_gpu + when: manual + test_model_job_gtfn_cpu_simple_grid: extends: .test_template stage: test @@ -68,11 +84,27 @@ test_tools_job: script: - tox -r -c tools/ --verbose +benchmark_model_dace_cpu_simple_grid: + extends: .test_template + stage: benchmark + script: + - pip install dace + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=dace_cpu --grid=simple_grid + when: manual + +benchmark_model_dace_gpu_simple_grid: + extends: .test_template + stage: benchmark + script: + - pip install dace + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=dace_gpu --grid=simple_grid + 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 diff --git a/model/common/src/icon4py/model/common/test_utils/pytest_config.py b/model/common/src/icon4py/model/common/test_utils/pytest_config.py index 1ea7c0ccdc..2050b9e7be 100644 --- a/model/common/src/icon4py/model/common/test_utils/pytest_config.py +++ b/model/common/src/icon4py/model/common/test_utils/pytest_config.py @@ -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", @@ -80,33 +81,33 @@ 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") - - elif backend_option == "gtfn_gpu": - params.append(run_gtfn_gpu) - ids.append("backend=gtfn_gpu") - - if len(params) < 1: + try: + from gt4py.next.program_processors.runners.dace_iterator import run_dace_cpu, run_dace_gpu + + backends.update({ + "dace_cpu": run_dace_cpu, + "dace_gpu": run_dace_gpu, + }) + except ImportError: + # dace module not installed, ignore dace backends + pass + + 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: From 6a231dc66a494fad4c5e50171a01769327d76a7a Mon Sep 17 00:00:00 2001 From: Edoardo Paone Date: Wed, 13 Dec 2023 11:33:00 +0100 Subject: [PATCH 2/4] Auto-format code --- .../model/common/test_utils/pytest_config.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/model/common/src/icon4py/model/common/test_utils/pytest_config.py b/model/common/src/icon4py/model/common/test_utils/pytest_config.py index 2050b9e7be..0a23ce0ac6 100644 --- a/model/common/src/icon4py/model/common/test_utils/pytest_config.py +++ b/model/common/src/icon4py/model/common/test_utils/pytest_config.py @@ -89,12 +89,17 @@ def pytest_generate_tests(metafunc): } try: - from gt4py.next.program_processors.runners.dace_iterator import run_dace_cpu, run_dace_gpu + from gt4py.next.program_processors.runners.dace_iterator import ( + run_dace_cpu, + run_dace_gpu, + ) - backends.update({ - "dace_cpu": run_dace_cpu, - "dace_gpu": run_dace_gpu, - }) + backends.update( + { + "dace_cpu": run_dace_cpu, + "dace_gpu": run_dace_gpu, + } + ) except ImportError: # dace module not installed, ignore dace backends pass @@ -107,7 +112,9 @@ def pytest_generate_tests(metafunc): + "] and pass it as an argument to --backend when invoking pytest." ) - metafunc.parametrize("backend", [backends[backend_option]], ids=[f"backend={backend_option}"]) + metafunc.parametrize( + "backend", [backends[backend_option]], ids=[f"backend={backend_option}"] + ) # parametrise grid if "grid" in metafunc.fixturenames: From 64ccf295862d9dc04e2680013af20b766d4e015c Mon Sep 17 00:00:00 2001 From: Edoardo Paone Date: Wed, 13 Dec 2023 11:45:42 +0100 Subject: [PATCH 3/4] Enable dace CI job post-merge on main Still ignore test failures --- ci/cscs.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ci/cscs.yml b/ci/cscs.yml index 61d8fe2c68..0109da6dcc 100644 --- a/ci/cscs.yml +++ b/ci/cscs.yml @@ -56,7 +56,9 @@ test_model_job_dace_cpu_simple_grid: script: - pip install dace - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_cpu - when: manual + only: + - main + allow_failure: true test_model_job_dace_gpu_simple_grid: extends: .test_template @@ -64,7 +66,9 @@ test_model_job_dace_gpu_simple_grid: script: - pip install dace - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_gpu - when: manual + only: + - main + allow_failure: true test_model_job_gtfn_cpu_simple_grid: extends: .test_template From bb06189593e9258a52162a984dadbb9d6a190280 Mon Sep 17 00:00:00 2001 From: Edoardo Paone Date: Wed, 13 Dec 2023 13:31:00 +0100 Subject: [PATCH 4/4] Fix dace version to 0.15.1 --- ci/cscs.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ci/cscs.yml b/ci/cscs.yml index 0109da6dcc..bab0af8700 100644 --- a/ci/cscs.yml +++ b/ci/cscs.yml @@ -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" @@ -54,7 +55,7 @@ test_model_job_dace_cpu_simple_grid: extends: .test_template stage: test script: - - pip install dace + - pip install dace==$DACE_VERSION - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_cpu only: - main @@ -64,7 +65,7 @@ test_model_job_dace_gpu_simple_grid: extends: .test_template stage: test script: - - pip install dace + - pip install dace==$DACE_VERSION - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=dace_gpu only: - main @@ -92,16 +93,20 @@ benchmark_model_dace_cpu_simple_grid: extends: .test_template stage: benchmark script: - - pip install dace + - 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 + - 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: