Skip to content

Commit 8fdd73c

Browse files
authored
Enable Cache in ICON4Py checks (#493)
1 parent 78e318e commit 8fdd73c

File tree

3 files changed

+71
-9
lines changed

3 files changed

+71
-9
lines changed

checks/apps/icon4py/icon4py_check.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55

6+
import os
7+
import re
68
import reframe as rfm
79
import reframe.utility.sanity as sn
810

@@ -28,16 +30,28 @@ class ICON4PyBenchmarks(rfm.RunOnlyRegressionTest):
2830
'HUGETLB_MORECORE': 'no',
2931
'GT4PY_UNSTRUCTURED_HORIZONTAL_HAS_UNIT_STRIDE': '1',
3032
'PYTHONOPTIMIZE': '2',
31-
# GT4Py cache does not work properly for dace backend yet
32-
# 'GT4PY_BUILD_CACHE_LIFETIME': 'persistent',
33-
# 'GT4PY_BUILD_CACHE_DIR': '...',
33+
'GT4PY_BUILD_CACHE_LIFETIME': 'persistent',
3434
}
3535
executable = './_run.sh'
3636
executable_opts = ['2>&1']
3737

3838
@run_before('run')
3939
def prepare_env(self):
4040
gpu_arch = self.current_partition.select_devices('gpu')[0].arch
41+
42+
cache_folder = (
43+
f"{os.environ.get('SCRATCH')}/"
44+
f".cache/reframe_bencher_icon4py/"
45+
)
46+
sub_folder = (
47+
f"{self.current_system.name}="
48+
f"{gpu_arch}="
49+
f"{self.current_environ}"
50+
)
51+
sub_folder = re.sub(r'[^a-zA-Z0-9=]', '', sub_folder)
52+
cache_folder = os.path.join(cache_folder, sub_folder)
53+
self.env_vars['GT4PY_BUILD_CACHE_DIR'] = cache_folder
54+
4155
if 'gfx' in gpu_arch: # AMD GPU
4256
self.env_vars['CUPY_INSTALL_USE_HIP'] = '1'
4357
self.env_vars['HCC_AMDGPU_TARGET'] = gpu_arch
@@ -54,12 +68,12 @@ def validate_test(self):
5468
(r'^\s*model/atmosphere/diffusion/tests/'
5569
r'diffusion/integration_tests/'
5670
r'test_benchmark_diffusion\.py'
57-
r'::test_diffusion_benchmark\s*PASSED'
71+
r'::test_diffusion_benchmark[\s\S]*?PASSED'
5872
), self.stdout)
5973
dycore_granule = sn.assert_found(
6074
(r'^\s*model/atmosphere/dycore/tests/'
6175
r'dycore/integration_tests/test_benchmark_solve_nonhydro\.py'
62-
r'::test_benchmark_solve_nonhydro\[True-False\]\s*PASSED'
76+
r'::test_benchmark_solve_nonhydro\[True-False\][\s\S]*?PASSED'
6377
), self.stdout)
6478

6579
return diffusion_granule and dycore_granule

checks/apps/icon4py/src/_install.sh

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ unset PYTHONPATH
77

88
git clone https://github.com/C2SM/icon4py.git
99
cd icon4py
10-
git checkout 5485bcacb1dbc7688b1e7d276d4e2e28362c5444 # Commit: Update to GT4Py v1.1.0 (#933)
10+
git checkout 15b7406d9385a189abaaa71b14851d1491b231f1 # Commit: Update to GT4Py v1.1.2 (#969)
1111

1212
# Install uv locally
1313
curl -LsSf https://astral.sh/uv/install.sh | UV_UNMANAGED_INSTALL="$PWD/bin" sh
@@ -25,6 +25,54 @@ mpi4py_ver=$(uv pip show mpi4py | awk '/Version:/ {print $2}')
2525
uv pip uninstall mpi4py && uv pip install --no-binary mpi4py "mpi4py==$mpi4py_ver"
2626
uv pip install git+https://github.com/cupy/cupy.git
2727

28+
# Patch Gt4Py to avoid cache issues
29+
uv pip uninstall gt4py
30+
git clone --branch v1.1.2 https://github.com/GridTools/gt4py.git
31+
python3 -c '
32+
import sys
33+
from pathlib import Path
34+
35+
file_path = Path("gt4py/src/gt4py/next/otf/stages.py")
36+
lines = file_path.read_text().splitlines()
37+
38+
new_lines = []
39+
iterator = iter(lines)
40+
41+
found = False
42+
for line in iterator:
43+
# 1. Detect the start of the block we want to change
44+
if "program_hash = utils.content_hash(" in line:
45+
found = True
46+
# Insert the NEW pre-calculation line
47+
# We steal the indentation from the current line to be safe
48+
indent = line[:line.find("program_hash")]
49+
new_lines.append(f"{indent}offset_provider_arrays = {{key: value.ndarray if hasattr(value, \"ndarray\") else value for key, value in offset_provider.items()}}")
50+
51+
# Add the modified content_hash call
52+
new_lines.append(f"{indent}program_hash = utils.content_hash(")
53+
new_lines.append(f"{indent} (")
54+
new_lines.append(f"{indent} program.fingerprint(),")
55+
new_lines.append(f"{indent} sorted(offset_provider_arrays.items(), key=lambda el: el[0]),")
56+
57+
# Skip the OLD lines from the iterator until we hit "column_axis"
58+
# We blindly consume lines until we find the one we keep
59+
while True:
60+
skipped_line = next(iterator)
61+
if "column_axis," in skipped_line:
62+
new_lines.append(skipped_line) # Add column_axis line back
63+
break
64+
else:
65+
new_lines.append(line)
66+
67+
if found:
68+
file_path.write_text("\n".join(new_lines) + "\n")
69+
print("Patch applied.")
70+
else:
71+
print("Target line not found.")
72+
sys.exit(1)
73+
'
74+
uv pip install -e ./gt4py
75+
2876
################################################################################
2977
# NVHPC runtime auto-discovery for serialbox (libnvhpcatm.so)
3078
################################################################################

checks/apps/icon4py/src/_run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ unset PYTHONPATH
77
cd icon4py
88
source .venv/bin/activate
99

10-
pytest -v \
10+
pytest -sv \
1111
-m continuous_benchmarking \
1212
--benchmark-only \
1313
--benchmark-warmup=on \
@@ -16,8 +16,8 @@ pytest -v \
1616
--backend=dace_gpu \
1717
--grid=icon_benchmark_regional \
1818
--benchmark-time-unit=ms \
19-
model/atmosphere/diffusion/tests/diffusion/integration_tests/test_benchmark_diffusion.py::test_diffusion_benchmark \
20-
model/atmosphere/dycore/tests/dycore/integration_tests/test_benchmark_solve_nonhydro.py::test_benchmark_solve_nonhydro[True-False]
19+
"model/atmosphere/diffusion/tests/diffusion/integration_tests/test_benchmark_diffusion.py::test_diffusion_benchmark" \
20+
"model/atmosphere/dycore/tests/dycore/integration_tests/test_benchmark_solve_nonhydro.py::test_benchmark_solve_nonhydro[True-False]"
2121
echo
2222

2323
# Cleanup

0 commit comments

Comments
 (0)