From 390721c0f194940b52b7ef58910d603b083f3bba Mon Sep 17 00:00:00 2001 From: samkellerhals Date: Thu, 14 Dec 2023 16:24:10 +0100 Subject: [PATCH] Add icon_grid benchmarks --- ci/cscs.yml | 142 +++++++++--------- ...test_apply_diffusion_to_theta_and_exner.py | 6 +- .../test_apply_diffusion_to_vn.py | 10 +- .../test_calculate_nabla2_for_z.py | 15 +- ...sed_velocity_advection_stencil_19_to_20.py | 6 +- ...fused_velocity_advection_stencil_1_to_7.py | 7 +- .../model/common/test_utils/helpers.py | 14 +- 7 files changed, 111 insertions(+), 89 deletions(-) diff --git a/ci/cscs.yml b/ci/cscs.yml index d345207ce6..5095556bed 100644 --- a/ci/cscs.yml +++ b/ci/cscs.yml @@ -48,78 +48,78 @@ variables: build_job: extends: .build_template -#test_model_job_roundtrip_simple_grid: -# extends: .test_template -# stage: test -# 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_roundtrip_simple_grid: + extends: .test_template + stage: test + 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 script: - - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=gtfn_cpu --grid=icon_grid - -#test_model_job_gtfn_gpu_simple_grid: -# extends: .test_template -# stage: test -# script: -# - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=gtfn_gpu -# -#test_tools_job: -# extends: .test_template -# stage: test -# 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 -# -#benchmark_model_gtfn_gpu_simple_grid: -# extends: .test_template -# stage: benchmark -# script: -# - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=gtfn_gpu --grid=simple_grid + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=gtfn_cpu + +test_model_job_gtfn_gpu_simple_grid: + extends: .test_template + stage: test + script: + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-skip -n auto --backend=gtfn_gpu + +test_tools_job: + extends: .test_template + stage: test + script: + - tox -r -c tools/ --verbose + +benchmark_model_dace_cpu_icon_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=icon_grid + only: + - main + when: manual + +benchmark_model_dace_gpu_icon_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=icon_grid + only: + - main + when: manual + +benchmark_model_gtfn_cpu_icon_grid: + extends: .test_template + stage: benchmark + script: + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=gtfn_cpu --grid=icon_grid + +benchmark_model_gtfn_gpu_icon_grid: + extends: .test_template + stage: benchmark + script: + - tox -r -e stencil_tests -c model/ --verbose -- --benchmark-only --backend=gtfn_gpu --grid=icon_grid diff --git a/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_theta_and_exner.py b/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_theta_and_exner.py index fa1e392aa0..a11faf0be6 100644 --- a/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_theta_and_exner.py +++ b/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_theta_and_exner.py @@ -26,6 +26,7 @@ random_mask, unflatten_first_two_dims, zero_field, + uses_icon_grid_with_otf ) from .test_calculate_nabla2_for_z import calculate_nabla2_for_z_numpy @@ -81,7 +82,10 @@ def reference( return dict(theta_v=theta_v, exner=exner) @pytest.fixture - def input_data(self, grid): + def input_data(self, grid, uses_icon_grid_with_otf): + if uses_icon_grid_with_otf: + pytest.skip("Execution domain needs to be restricted or boundary taken into account in stencil.") + kh_smag_e = random_field(grid, EdgeDim, KDim) inv_dual_edge_length = random_field(grid, EdgeDim) theta_v_in = random_field(grid, CellDim, KDim) diff --git a/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_vn.py b/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_vn.py index e121b428c8..0793ff4462 100644 --- a/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_vn.py +++ b/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_apply_diffusion_to_vn.py @@ -13,13 +13,12 @@ import numpy as np import pytest -from gt4py.next.ffront.fbuiltins import int32 +from gt4py.next.ffront.fbuiltins import int32 from icon4py.model.atmosphere.diffusion.stencils.apply_diffusion_to_vn import apply_diffusion_to_vn from icon4py.model.atmosphere.dycore.state_utils.utils import indices_field from icon4py.model.common.dimension import E2C2VDim, ECVDim, EdgeDim, KDim, VertexDim -from icon4py.model.common.test_utils.helpers import StencilTest, as_1D_sparse_field, random_field - +from icon4py.model.common.test_utils.helpers import StencilTest, as_1D_sparse_field, random_field, uses_icon_grid_with_otf from .test_apply_nabla2_and_nabla4_global_to_vn import apply_nabla2_and_nabla4_global_to_vn_numpy from .test_apply_nabla2_and_nabla4_to_vn import apply_nabla2_and_nabla4_to_vn_numpy from .test_apply_nabla2_to_vn_in_lateral_boundary import ( @@ -98,7 +97,10 @@ def reference( return dict(vn=vn) @pytest.fixture - def input_data(self, grid): + def input_data(self, grid, uses_icon_grid_with_otf): + if uses_icon_grid_with_otf: + pytest.skip("Execution domain needs to be restricted or boundary taken into account in stencil.") + edge = indices_field(EdgeDim, grid, is_halfdim=False, dtype=int32) u_vert = random_field(grid, VertexDim, KDim) diff --git a/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_calculate_nabla2_for_z.py b/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_calculate_nabla2_for_z.py index 6f30ff385a..be13010923 100644 --- a/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_calculate_nabla2_for_z.py +++ b/model/atmosphere/diffusion/tests/diffusion_stencil_tests/test_calculate_nabla2_for_z.py @@ -13,14 +13,13 @@ import numpy as np import pytest -from gt4py.next.ffront.fbuiltins import int32 -from gt4py.next.program_processors.otf_compile_executor import OTFCompileExecutor +from gt4py.next.ffront.fbuiltins import int32 from icon4py.model.atmosphere.diffusion.stencils.calculate_nabla2_for_z import ( calculate_nabla2_for_z, ) from icon4py.model.common.dimension import CellDim, E2CDim, EdgeDim, KDim -from icon4py.model.common.test_utils.helpers import StencilTest, random_field +from icon4py.model.common.test_utils.helpers import StencilTest, random_field, uses_icon_grid_with_otf from icon4py.model.common.type_alias import vpfloat, wpfloat @@ -55,12 +54,10 @@ def reference( return dict(z_nabla2_e=z_nabla2_e) @pytest.fixture - def input_data(self, grid, backend): - if hasattr(backend, 'executor'): - if isinstance(backend.executor, OTFCompileExecutor): - pytest.skip( - "Execution domain needs to be restricted or boundary taken into account in stencil." - ) + def input_data(self, grid, uses_icon_grid_with_otf): + if uses_icon_grid_with_otf: + pytest.skip("Execution domain needs to be restricted or boundary taken into account in stencil.") + kh_smag_e = random_field(grid, EdgeDim, KDim, dtype=vpfloat) inv_dual_edge_length = random_field(grid, EdgeDim, dtype=wpfloat) theta_v = random_field(grid, CellDim, KDim, dtype=wpfloat) diff --git a/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_19_to_20.py b/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_19_to_20.py index eaf3571d2a..726741996b 100644 --- a/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_19_to_20.py +++ b/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_19_to_20.py @@ -34,6 +34,7 @@ random_field, random_mask, zero_field, + uses_icon_grid_with_otf ) from .test_mo_math_divrot_rot_vertex_ri_dsl import mo_math_divrot_rot_vertex_ri_dsl_numpy @@ -116,7 +117,10 @@ def reference( return dict(ddt_vn_apc=ddt_vn_apc) @pytest.fixture - def input_data(self, grid): + def input_data(self, grid, uses_icon_grid_with_otf): + if uses_icon_grid_with_otf: + pytest.skip("Execution domain needs to be restricted or boundary taken into account in stencil.") + z_kin_hor_e = random_field(grid, EdgeDim, KDim) coeff_gradekin = random_field(grid, EdgeDim, E2CDim) coeff_gradekin_new = as_1D_sparse_field(coeff_gradekin, ECDim) diff --git a/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_1_to_7.py b/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_1_to_7.py index 0b4f40aab7..7b19ecb791 100644 --- a/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_1_to_7.py +++ b/model/atmosphere/dycore/tests/dycore_stencil_tests/test_fused_velocity_advection_stencil_1_to_7.py @@ -20,7 +20,7 @@ ) from icon4py.model.atmosphere.dycore.state_utils.utils import indices_field from icon4py.model.common.dimension import CellDim, E2C2EDim, EdgeDim, KDim, V2CDim, VertexDim -from icon4py.model.common.test_utils.helpers import StencilTest, random_field, zero_field +from icon4py.model.common.test_utils.helpers import StencilTest, random_field, zero_field, uses_icon_grid_with_otf from .test_mo_icon_interpolation_scalar_cells2verts_scalar_ri_dsl import ( mo_icon_interpolation_scalar_cells2verts_scalar_ri_dsl_numpy, @@ -192,7 +192,10 @@ def reference( ) @pytest.fixture - def input_data(self, grid): + def input_data(self, grid, uses_icon_grid_with_otf): + if uses_icon_grid_with_otf: + pytest.skip("Execution domain needs to be restricted or boundary taken into account in stencil.") + c_intp = random_field(grid, VertexDim, V2CDim) vn = random_field(grid, EdgeDim, KDim) rbf_vec_coeff_e = random_field(grid, EdgeDim, E2C2EDim) diff --git a/model/common/src/icon4py/model/common/test_utils/helpers.py b/model/common/src/icon4py/model/common/test_utils/helpers.py index 883a0aa75e..3beecd6038 100644 --- a/model/common/src/icon4py/model/common/test_utils/helpers.py +++ b/model/common/src/icon4py/model/common/test_utils/helpers.py @@ -21,9 +21,10 @@ from gt4py.next import common as gt_common from gt4py.next import constructors from gt4py.next.ffront.decorator import Program +from gt4py.next.program_processors.otf_compile_executor import OTFCompileExecutor from ..grid.base import BaseGrid - +from ..grid.icon import IconGrid try: import pytest_benchmark @@ -219,3 +220,14 @@ def __init_subclass__(cls, **kwargs): super().__init_subclass__(**kwargs) setattr(cls, f"test_{cls.__name__}", _test_validation) setattr(cls, f"test_{cls.__name__}_benchmark", _test_execution_benchmark) + + +@pytest.fixture +def uses_icon_grid_with_otf(backend, grid): + """Checks whether we are using a compiled backend with the icon_grid. + Is needed to skip certain stencils where the execution domain needs to be restricted or boundary taken into account. + """ + if hasattr(backend, 'executor') and isinstance(grid, IconGrid): + if isinstance(backend.executor, OTFCompileExecutor): + return True + return False